You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When performing a migration in LibSQL using Atlas, certain changes require temporarily deleting a table and recreating it with modifications. This process should disable foreign key constraints with the PRAGMA foreign_keys = OFF command to prevent unintended cascade deletions. However, it appears that the PRAGMA foreign_keys = OFF command is not being applied or is ineffective, leading to the following issue:
When a table is deleted, related records in other tables with ON DELETE CASCADE foreign key constraints are also deleted, resulting in data loss.
Steps to Reproduce:
Start a TursoDB database with the following schema:
INSERT INTO parent_table (id, name, description) VALUES (1, 'Parent 1', 'Parent number 1');
INSERT INTO child_table (id, parent_id, name, description) VALUES (1, 1, 'Child name', 'Child of Parent 1');
Change the "description" column type on the "parent_table" to have "null" be true:
column"description" {
type=text
null = true
}
Run the migration and check if the child_table still has the row we inserted earlier.
Expected Behavior:
The migration applies without cascade deletions due to the foreign key constraints being disabled by PRAGMA foreign_keys = OFF. And the child_table still has a row.
Actual Behavior:
The child_table has been emptied because a parent table that it has a foreign key towards was (temporarily) deleted.
Impact:
This issue can lead to significant data loss when modifying tables in a database with foreign key constraints, making it unsafe to perform migrations in SQLite with Atlas in certain scenarios.
Issue Summary:
When performing a migration in LibSQL using Atlas, certain changes require temporarily deleting a table and recreating it with modifications. This process should disable foreign key constraints with the PRAGMA foreign_keys = OFF command to prevent unintended cascade deletions. However, it appears that the PRAGMA foreign_keys = OFF command is not being applied or is ineffective, leading to the following issue:
Steps to Reproduce:
Expected Behavior:
The migration applies without cascade deletions due to the foreign key constraints being disabled by PRAGMA foreign_keys = OFF. And the child_table still has a row.
Actual Behavior:
The child_table has been emptied because a parent table that it has a foreign key towards was (temporarily) deleted.
Impact:
This issue can lead to significant data loss when modifying tables in a database with foreign key constraints, making it unsafe to perform migrations in SQLite with Atlas in certain scenarios.
Environment:
The text was updated successfully, but these errors were encountered: