ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
6.02k stars 269 forks source link

Support sqlite alter table drop column when applying new schema #3231

Open alarbada opened 4 days ago

alarbada commented 4 days ago

Sqlite supports dropping columns for a while now.

I was surprised to see that atlas still migrates the old way, removing and creating the table again.

a8m commented 4 days ago

Thanks for bringing this up, @alarbada. DROP COLUMN is allowed only with a few limitations:

The DROP COLUMN command only works if the column is not referenced by any other parts of the schema and is not a PRIMARY KEY and does not have a UNIQUE constraint. Possible reasons why the DROP COLUMN command can fail include:

The column is a PRIMARY KEY or part of one. The column has a UNIQUE constraint. The column is indexed. The column is named in the WHERE clause of a partial index. The column is named in a table or column CHECK constraint not associated with the column being dropped. The column is used in a foreign key constraint. The column is used in the expression of a generated column. The column appears in a trigger or view.

However, this can still be improved. I've assigned it to myself, and we will add it to the upcoming milestones.