hello all, my kmp app uses com.sqaureup.sqldelight...
# multiplatform
p
hello all, my kmp app uses com.sqaureup.sqldelight, it has some tables which now needs alteration i am stuck in adding migration plans to this, can someone help, details in thread 🧵
build.gradle.kts (shared)
Copy code
sqldelight {
    database("MyDb") {
        packageName = "com.example.some.db"
        sourceFolders = listOf("sqldelight")
        verifyMigrations = true
        deriveSchemaFromMigrations = true
    }
}
there is a file at /commonMain/sqldelight/com/example/some/db/MusicGenre.sq
Copy code
createTableIfNotExists:
CREATE TABLE IF NOT EXISTS MusicGenres (
    id TEXT NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    thumbnail_url TEXT NOT NULL,
    selected INTEGER NOT NULL
);

setAllMusicGenres:
INSERT OR REPLACE INTO MusicGenres(id, title, thumbnail_url, selected)
VALUES(?, ?, ?, ?);
now we need to add a new column to this table for this i created a file 1.sqm at /commonMain/sqldelight/com/example/some/db/migrations
Copy code
ALTER TABLE MusicGenres ADD COLUMN type TEXT NOT NULL DEFAULT '';
Error i get in 1.sqm file is Attempting to alter something that is not a table No table found with name MusicGenres
m
Make sure to add column creation statement in 1.sqm as well with the new column;
CREATE TABLE IF NOT EXISTS MusicGenres (
id TEXT NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
type TEXT NOT NULL DEFAULT ''
thumbnail_url TEXT NOT NULL,
selected INTEGER NOT NULL
);
p
tried this 1.sqm
Copy code
CREATE TABLE IF NOT EXISTS MusicGenres (
    id TEXT NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    type TEXT NOT NULL DEFAULT '',
    thumbnail_url TEXT NOT NULL,
    selected INTEGER NOT NULL
);

ALTER TABLE MusicGenres ADD COLUMN type TEXT NOT NULL DEFAULT '';
file generated
Copy code
public data class MusicGenres(
  public val id: String,
  public val title: String,
  public val type: String,
  public val thumbnail_url: String,
  public val selected: Long,
  public val type: String
) {
  public override fun toString(): String = """
  |MusicGenres [
  |  id: $id
  |  title: $title
  |  type: $type
  |  thumbnail_url: $thumbnail_url
  |  selected: $selected
  |  type: $type
  |]
  """.trimMargin()
}
type is added 2 times, hence an error ?
m
I have added and tested migrations on the Android side for SqlDelight. In my opinion, it should be similar in multiplatform. You can check it here; https://github.com/muazdev26/Notsi/tree/master/app/src/main/sqldelight/com/muazdev/notsi
c
better to ask in #squarelibraries
p
thanks