fix: alter notifications constraint with ON DELETE CASCADE
#211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds SQL migration file with changing the
fk_notifications_client_id
constraint to includeON DELETE CASCADE
to fix thedelete on table "clients" violates foreign key constraint "fk_notifications_client_id"
error.With this change removing records from the
clients
table will automatically remove related to theclients.id
records in thenotifications
table.Resolves #212
Test plan
Pre-requirements:
To test the sqlx migrations we should use the sqlx-cli tool:
Step 1:
To test the migration properly we should populate the table with different records including duplicated
device_token
records in theclients
andnotifications
tables.To mimic the real database behavior we will use the test migration SQL script with the data to be inserted into the database BEFORE the new migration SQL script.
Please download the script to the
/migrations
folder:Step 2:
Also, we should download the migration SQL script from #202 with removing duplicates and adding the unique constraint to the
device_token
to mimic removing records from theclients
table and test the follow-up migration as well AFTER this PR migration script.After that, we should have the following migrations scripts in our
/migrations
folder:Step 3:
Start the Postgres docker container:
Step 4:
Now we can start the sqlx migration to test its correctness and results using the sqlx-cli:
The expected result is that all migration steps should be passed successfully:
As an optional step, we can log in to Postgres and check for the duplicates:
The expected result is that there are no duplicates in the
clients
table at the end of the migration (but they were populated by the test database population migration script before).Due Diligence