pgschema
pgschema copied to clipboard
Dropping an enum together with the column that uses it plans DROP TYPE before DROP COLUMN (SQLSTATE 2BP01)
Version: observed on v1.11.0; from reading internal/diff/diff.go, the ordering is the same in v1.14.1 and on main.
Current state
CREATE TYPE annotated_by_type AS ENUM ('human', 'model');
CREATE TABLE evidence (id BIGSERIAL PRIMARY KEY, annotated_by annotated_by_type);
Desired state
CREATE TABLE evidence (id BIGSERIAL PRIMARY KEY);
Plan produced
DROP TYPE IF EXISTS annotated_by_type RESTRICT;
ALTER TABLE evidence DROP COLUMN annotated_by;
Result: the first statement fails because the column evidence.annotated_by still depends on the type.
Expected: ALTER TABLE ... DROP COLUMN before DROP TYPE.
Cause: collectMigrationSQL runs generateDropSQL (which emits type drops) before generateModifySQL (which emits column drops on modified tables). Type drops need to run after the column drops of modified tables, as they already do after DROP TABLE.