Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite 3.25 ALTER TABLE ... RENAME COLUMN ... TO ... statement compilation error in migrations #4897

Closed
griffio opened this issue Dec 8, 2023 · 1 comment · Fixed by #4899
Labels

Comments

@griffio
Copy link
Contributor

griffio commented Dec 8, 2023

SQLDelight Version

2.0.0, 2.0.1

SQLDelight Dialect

sqlite-3-25-dialect or higher

Describe the Bug

Sqlite support for rename table column (sqlite_3_25 and higher) in migrations generates compiler error

This is the same issues that Postgresql has - so fixes will be similar to work done for Postgresql

There is only a test for Postgresql in the migrations compiler test for alter column (not for sqlite)

Steps to generate compile error

sqldelight {
    databases {
        create("Database") {
            packageName.set("com.example")
            deriveSchemaFromMigrations = true
            dialect("app.cash.sqldelight:sqlite-3-25-dialect:2.0.1")
        }
    }
}

1.sqm

CREATE TABLE test (
    id INTEGER PRIMARY KEY NOT NULL
);

2.sqm

ALTER TABLE test RENAME COLUMN id TO new_id;

test.sq

deleteTest:
    DELETE FROM test;

selectTest:
    SELECT *
    FROM test;

insertTest:
    INSERT INTO test (new_id)
    VALUES(?);

Stacktrace

There are at least two issues:

SqlColumnAlias doesn't implement SqlColumn in the generated grammar and an alias type in the grammar is incorrect for a renamed column

class com.alecstrong.sql.psi.core.psi.impl.SqlColumnAliasImpl cannot be cast to class com.alecstrong.sql.psi.core.psi.SqlColumnName 

SqlColumnAlias is the incorrect type for a renamed column as alias columns are only expected in Result statements and CTE statements hence the illegal state

java.lang.IllegalStateException unexpected column alias parent SqliteAlterTableRenameColumnImpl(ALTER_TABLE_RENAME_COLUMN): ..	at com.alecstrong.sql.psi.core.psi.mixins.ColumnAliasMixin.source(ColumnAliasMixin.kt:29)
@griffio griffio added the bug label Dec 8, 2023
@griffio
Copy link
Contributor Author

griffio commented Dec 8, 2023

I have a branch that has the fixes in 3-25
For some reason the sqlite dialect has changed in 3-35 that is causing some further problem with a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant