cashapp / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://cashapp.github.io/sqldelight/
Apache License 2.0
6.12k stars 512 forks source link

Intellij plugin doesn't recognize that indexes of a dropped table are dropped #4574

Open sergejsha opened 1 year ago

sergejsha commented 1 year ago

SQLDelight Version

2.0.0

IDE Version

Android Studio Giraffe | 2022.3.1 Patch 1

Dialect

SQLite

Describe the Bug

Given a table with two fields and two indexes for each field.

  1. Create a database migration for renaming one of the fields.
  2. Auto-generated migration will:
    • create a temp-table
    • copy data from original table into that table
    • drops original table
    • alter temp-table name into original one.
  3. Because indexes for a dropped table are also dropped, they need to be re-added manually.
  4. Add missing indexes for the table
  5. Intellij plugin shows "Duplicate index name" error.
  6. If indexes are not added manually, verifySqlDelightMigration tasks shows that they were dropped and they are missing in the database after migration.

Expected behavior:

  1. When a table is dropped, Intellij plugin must consider indexes to be dropped as well.
  2. Auto-generated migration must re-create all dropped indexes.

Temporal workaround: before dropping a table, drop all indexes of that table in migration script. This allows index re-creation.

Stacktrace

No response

Knoxvillekm commented 4 months ago

Any fixes planned?

Additional sample

1.sqm
-- Create table with index
CREATE TABLE Table1(
    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    paretnId INTEGER NOT NULL
);
CREATE INDEX Table1_paretnId ON Table1 (paretnId);
2.sqm
-- Drop table (automatically drop index)
DROP TABLE Table1;

-- Create table with index
CREATE TABLE Table1(
    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    paretnId INTEGER NOT NULL,
    name TEXT
);
CREATE INDEX Table1_paretnId ON Table1 (paretnId); -- Warning "Duplicate index name Table1_paretnId"