sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

False positive in SchemaNeedsMigrationInspection

Open vanniktech opened this issue 3 years ago • 1 comments

SQLDelight Version

2.0.0-alpha02

IDE Version

AS B

Dialect

SQLite

Describe the Bug

I have the following table:

CREATE TABLE jamesTemplateDatabaseElement (
  id TEXT NOT NULL PRIMARY KEY,
  value TEXT NOT NULL,
  FOREIGN KEY (id) REFERENCES jamesTemplateDatabaseMetaData(id) ON DELETE CASCADE
);

This was added later in my application, therefore I also have this migration:

CREATE TABLE jamesTemplateDatabaseElement (
  id TEXT NOT NULL PRIMARY KEY,
  value TEXT NOT NULL,
  FOREIGN KEY (id) REFERENCES jamesTemplateDatabaseMetaData(id) ON DELETE CASCADE
);

All of which was done before: https://github.com/cashapp/sqldelight/issues/2732

In the table schema itself it's also value:

Screen Shot 2022-04-22 at 15 58 11

When I open that file though, the plugin hints me this:

Screen Shot 2022-04-22 at 15 58 38

and when alt+entering this is the generated code:

CREATE TABLE tmp_jamesTemplateDatabaseElement (id TEXT NOT NULL PRIMARY KEY, value TEXT NOT NULL);
INSERT INTO tmp_jamesTemplateDatabaseElement (id, value) SELECT id, value_ FROM jamesTemplateDatabaseElement;
DROP TABLE jamesTemplateDatabaseElement;
ALTER TABLE tmp_jamesTemplateDatabaseElement RENAME TO jamesTemplateDatabaseElement;

This kind of migration would never work though as there's no value_ column on jamesTemplateDatabaseElement. Somewhere the name from KotlinPoet is taken instead of the schema name.

Stacktrace

No response

vanniktech avatar Apr 22 '22 14:04 vanniktech

I expect it will be this code and the implementation of asParameter using the internal utilities which allocate names via kotlinpoet instead of the raw sql

AlecKazakova avatar Apr 22 '22 16:04 AlecKazakova

or this https://github.com/cashapp/sqldelight/blob/65449b46a89d261a4c9cd4f31b6cbfe013b4e144/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/SchemaNeedsMigrationInspection.kt#L72

aperfilyev avatar Apr 25 '23 18:04 aperfilyev