Search code examples
kotlinsqldelight

ALTER TABLE migrations does not update the generated code


I'm writing a migration file which alters a table, adding a new column, but the generated code isn't updated, so I can't insert new records into the table with value to the new column.

Example:


// BankAccount.sq file
    
CREATE TABLE bank_account (
    id INTEGER PRIMARY KEY,
    bank_code TEXT NOT NULL,
    account_number INTEGER NOT NULL,
    account_digit INTEGER NOT NULL
);

selectALL:
SELECT * FROM bank_account;
    
insert:
INSERT INTO bank_account VALUES (?,?,?,?);

// 1.sqm file
ALTER TABLE bank_account ADD COLUMN bank_name TEXT;

It seems the generated code is not updated after that column is added. For instance, the insert function isn't updated to receive the new added column to the table, and the internal generated Kotlin code isn't updated with the new column.

Is there any way to bypass this issue?


Solution

  • the CREATE TABLE is always the fresh version of your schema, so you need to add the column in the CREATE TABLE as well. If you want to have migration files be the source of truth you need to enable deriveSchemaFromMigrations as outlined here: https://cashapp.github.io/sqldelight/jvm_mysql/#migration-schema