Robert Munro
06/26/2023, 9:58 PM1.5.5
)
i have a table media
and i want to alter it to add a column (broadcast_date
) so i have 1.sqm
ALTER TABLE media ADD COLUMN broadcast_date TEXT DEFAULT NULL;
i have turned on deriveSchemaFromMigrations = true
in build.gradle.kts
but when building, it tries to run the alter table command before the schema in the .sq files? (error output in thread)
just wondering if thats the best way to do migrations?
source is here: https://github.com/sentinelweb/cuer/tree/feature/196-upcoming-videos/database/src/commonMain/sqldelight/uk/co/sentinelweb/cuer/databaseRobert Munro
06/26/2023, 10:02 PM> Task :database:generateCommonMainDatabaseInterface FAILED
/Users/robmunro/repos/cuer/database/src/commonMain/sqldelight/uk/co/sentinelweb/cuer/database/migrations/1.sqm line 1:12 - Attempting to alter something that is not a table.
1 ALTER TABLE media ADD COLUMN broadcast_date TEXT DEFAULT NULL
^^^^^
/Users/robmunro/repos/cuer/database/src/commonMain/sqldelight/uk/co/sentinelweb/cuer/database/migrations/1.sqm line 1:12 - No table found with name media
1 ALTER TABLE media ADD COLUMN broadcast_date TEXT DEFAULT NULL
^^^^^
/Users/robmunro/repos/cuer/database/src/commonMain/sqldelight/uk/co/sentinelweb/cuer/database/entity/MediaEntity.sq line 3:13 - Table already defined with name media
03 CREATE TABLE media (
^^^^^
04 id TEXT NOT NULL PRIMARY KEY,
05 flags INTEGER NOT NULL DEFAULT 0,
06 type TEXT AS uk.co.sentinelweb.cuer.domain.MediaDomain.MediaTypeDomain NOT NULL,
07 url TEXT NOT NULL,
08 title TEXT,
09 duration INTEGER,
10 position INTEGER,
11 date_last_played TEXT AS kotlinx.datetime.Instant,
12 description TEXT,
13 platform TEXT AS uk.co.sentinelweb.cuer.domain.PlatformDomain NOT NULL,
14 platform_id TEXT NOT NULL ,
15 published TEXT AS kotlinx.datetime.LocalDateTime,
16 channel_id TEXT,
17 thumb_id TEXT,
18 image_id TEXT,
19 -- broadcast_date TEXT AS kotlinx.datetime.LocalDateTime,
20 FOREIGN KEY (channel_id) REFERENCES channel(id)
21 )
Robert Munro
06/27/2023, 11:55 AMderiveSchemaFromMigrations = false
then the above error is gone - but when I try to generate the verification db (using database:generateCommonMainDatabaseSchema
) - then the migrations arent included in the generated db file. (in this case broadcast_date
is not in the media
table) - hence verifySqlelightMigration
fails.leandro
06/27/2023, 7:47 PMRobert Munro
06/27/2023, 7:55 PMDatabase.Schema.migrate(
driver = driver,
oldVersion = prefs.dbVersion,
newVersion = Database.Schema.version,
).also {
prefs.dbVersion = Database.Schema.version
}
But it seems that the migration is run automatically when the db is created? the Database.Schema.version
is already 2
Do i NOT need to call Database.Schema.migrate()
manually at all?leandro
06/28/2023, 8:24 AMRobert Munro
06/28/2023, 8:25 AM