Skip to content

Ordering of dropped column and constraint #3541

@brokentari

Description

@brokentari

Workflow consist of using atlas to generate goose migrations.

Expected Behavior

Generating goose migrations, the down migration of adding a column with predefined constraints would try to drop the constraint and then the column, or simply drop the table.

Actual Behavior

The drop migration drops the column, and then attempts to drop the constraint, causing a SQL error due to the constraint not existing anymore.

Steps to Reproduce

  1. Create a starting schema:
create table sample_table ( id numeric, c1 numeric);
  1. Generate the initial migration with atlas migrate diff --dir-format "goose" ...
  2. Add a column with a constraint to the schema:
create table sample_table ( id numeric, c1 numeric, c2 numeric check ( c2 <= 10) );
  1. Generate new migration, should have an invalid drop sequence (drops column before constraint, causing error):
-- +goose Up
-- modify "sample_table" table
ALTER TABLE "public"."sample_table" ADD CONSTRAINT "sample_table_c2_check" CHECK (c2 <= (10)::numeric), ADD COLUMN "c2" numeric NULL;

-- +goose Down
-- reverse: modify "sample_table" table
ALTER TABLE "public"."sample_table" DROP COLUMN "c2", DROP CONSTRAINT "sample_table_c2_check";

Notes

The ordering seems to be fine when the difference between a schema is removing a column/constraints, so that the simultaneous dropping is part of the up migration.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions