INSERT INTO not working in migration when database is created from scratch
See original GitHub issueRuntime Environment SQLDelight version: 1.4.4 Application OS: iOS (so with SQLite)
Describe the bug
INSERT INTO
sql statements are not executed when placed in a migration file (sqm).
In the beginning of creating the app we placed the CREATE TABLE
statement in the sq
file but moved that to the sqm
file for clarity. This bug is also happening when the CREATE TABLE
is in the sq file.
Details Now I have the following two sqm files. 0.sqm
CREATE TABLE User (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
);
1.sqm
CREATE TABLE UserType (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
);
INSERT INTO UserType (name) VALUES ("standard");
INSERT INTO UserType (name) VALUES ("admin");
INSERT INTO UserType (name) VALUES ("member");
When the user previously installed the app where 0.sqm is already executed and now is migrated to 1.sqm the INSERT INTO
have been executed in the database. So there is a UserType table with 3 entries.
Now when I removed the app from the device (to simulate a new user) and reinstall it the 2 tables have been created but there are no entries in UserType while that is expected.
In the build.gradle.kts file I have set deriveSchemaFromMigrations true
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top GitHub Comments
yes, it already exists. If you set
deriveSchemaFromMigrations = true
in your sqldelight gradle config then it will treat migration files as the source of truth and you dont need any SQL in your .sq files except runtime statements@AlecStrong thanks for the quick reply, I must have missed / over read this in the docs 🤔 I applied the changes and it is working as expected.
As a side note, are there any plans to try and eliminate this duplication?