Skip to content

Commit

Permalink
Add failing test case for drop_column (#96)
Browse files Browse the repository at this point in the history
* Add failing test case for rename_column

* Improve rename_column SQLite behavior

`ALTER TABLE .. RENAME COLUMN .. TO ..` is officially supported and does not need the temporary table workaround.

* Add failing test case for drop_column

* Preserve foreign keys in SQLite on drop_column

Closes gobuffalo/pop#574

* Bump CockroachDB to non-EOL version

CockroachDB v2.1 has reached EOL on 7/1/20. The next version v19.1 already reached maintenance support and will reach EOL in 11/1/20 which is why this was bumped to v19.2 right away.

* Resolve missing keys and broken NULL constraints

Resolves an issue where CockroachDB would be missing e.g. UNIQUE indices when using `change_column`. Also fixes a bug when using `change_column` with `NOT NUL` but without `DEFAULT`.

* Add missing PostgreSQL E2E fixtures

* Add missing MySQL E2E fixtures
  • Loading branch information
aeneasr committed Aug 30, 2020
1 parent 4e9fb9c commit 0226681
Show file tree
Hide file tree
Showing 82 changed files with 1,649 additions and 160 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
volumes:
- ./sqldumps:/docker-entrypoint-initdb.d
cockroach:
image: cockroachdb/cockroach:v2.1.0
image: cockroachdb/cockroach:v19.2.10
ports:
- "26257:26257"
- "8080:8080"
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200219183655-46282727080f h1:dB42wwhNuwPvh8f+5zZWNcU+F2Xs/B9wXXwvUCOH7r8=
golang.org/x/net v0.0.0-20200219183655-46282727080f/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
3 changes: 2 additions & 1 deletion internal/e2e/fixtures/cockroach/down/1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE schema_migration (
Expand Down
30 changes: 30 additions & 0 deletions internal/e2e/fixtures/cockroach/down/10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
);

CREATE TABLE e2e_user_posts (
id UUID NOT NULL,
user_id UUID NOT NULL,
content VARCHAR(255) NOT NULL DEFAULT '':::STRING,
slug VARCHAR(64) NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, user_id, content, slug)
);

CREATE TABLE schema_migration (
version VARCHAR(14) NOT NULL,
UNIQUE INDEX schema_migration_version_idx (version ASC),
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
9 changes: 5 additions & 4 deletions internal/e2e/fixtures/cockroach/down/2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE e2e_user_notes (
id UUID NOT NULL,
notes VARCHAR(255) NULL,
user_id UUID NOT NULL,
notes VARCHAR(255) NULL,
title VARCHAR(64) NOT NULL DEFAULT '':::STRING,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
INDEX e2e_user_notes_title_idx (title ASC),
FAMILY "primary" (id, notes, user_id, title)
FAMILY "primary" (id, user_id, notes, title)
);

CREATE TABLE schema_migration (
Expand All @@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users (id) ON DELETE CASCADE;
ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_notes VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
9 changes: 5 additions & 4 deletions internal/e2e/fixtures/cockroach/down/3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE e2e_user_notes (
id UUID NOT NULL,
notes VARCHAR(255) NULL,
user_id UUID NOT NULL,
notes VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
FAMILY "primary" (id, notes, user_id)
FAMILY "primary" (id, user_id, notes)
);

CREATE TABLE schema_migration (
Expand All @@ -22,7 +23,7 @@ CREATE TABLE schema_migration (
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users (id) ON DELETE CASCADE;
ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_notes VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
9 changes: 5 additions & 4 deletions internal/e2e/fixtures/cockroach/down/4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE e2e_user_notes (
id UUID NOT NULL,
notes VARCHAR(255) NULL,
user_id UUID NOT NULL,
slug VARCHAR(64) NOT NULL,
notes VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, notes, user_id, slug)
FAMILY "primary" (id, user_id, slug, notes)
);

CREATE TABLE schema_migration (
Expand All @@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users (id) ON DELETE CASCADE;
ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_notes VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
9 changes: 5 additions & 4 deletions internal/e2e/fixtures/cockroach/down/5.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE e2e_user_notes (
id UUID NOT NULL,
notes VARCHAR(255) NULL,
user_id UUID NOT NULL,
slug VARCHAR(64) NOT NULL,
notes VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, notes, user_id, slug)
FAMILY "primary" (id, user_id, slug, notes)
);

CREATE TABLE schema_migration (
Expand All @@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users (id) ON DELETE CASCADE;
ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_notes VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
9 changes: 5 additions & 4 deletions internal/e2e/fixtures/cockroach/down/6.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE e2e_user_notes (
id UUID NOT NULL,
notes VARCHAR(255) NULL,
user_id UUID NOT NULL,
slug VARCHAR(64) NOT NULL,
notes VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, notes, user_id, slug)
FAMILY "primary" (id, user_id, slug, notes)
);

CREATE TABLE schema_migration (
Expand All @@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users (id) ON DELETE CASCADE;
ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_notes VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
31 changes: 31 additions & 0 deletions internal/e2e/fixtures/cockroach/down/7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE e2e_user_posts (
id UUID NOT NULL,
user_id UUID NOT NULL,
slug VARCHAR(64) NOT NULL,
notes VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, user_id, slug, notes)
);

CREATE TABLE schema_migration (
version VARCHAR(14) NOT NULL,
UNIQUE INDEX schema_migration_version_idx (version ASC),
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
31 changes: 31 additions & 0 deletions internal/e2e/fixtures/cockroach/down/8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
username VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at, username)
);

CREATE TABLE e2e_user_posts (
id UUID NOT NULL,
user_id UUID NOT NULL,
content VARCHAR(255) NOT NULL DEFAULT '':::STRING,
slug VARCHAR(64) NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, user_id, content, slug)
);

CREATE TABLE schema_migration (
version VARCHAR(14) NOT NULL,
UNIQUE INDEX schema_migration_version_idx (version ASC),
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
31 changes: 31 additions & 0 deletions internal/e2e/fixtures/cockroach/down/9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
name VARCHAR(255) NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at, name)
);

CREATE TABLE e2e_user_posts (
id UUID NOT NULL,
user_id UUID NOT NULL,
content VARCHAR(255) NOT NULL DEFAULT '':::STRING,
slug VARCHAR(64) NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, user_id, content, slug)
);

CREATE TABLE schema_migration (
version VARCHAR(14) NOT NULL,
UNIQUE INDEX schema_migration_version_idx (version ASC),
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
3 changes: 2 additions & 1 deletion internal/e2e/fixtures/cockroach/up/0.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
CREATE TABLE e2e_users (
id UUID NOT NULL,
username VARCHAR(255) NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, username, created_at, updated_at)
);

CREATE TABLE schema_migration (
Expand Down
5 changes: 3 additions & 2 deletions internal/e2e/fixtures/cockroach/up/1.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
CREATE TABLE e2e_users (
id UUID NOT NULL,
username VARCHAR(255) NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
FAMILY "primary" (id, username, created_at, updated_at)
);

CREATE TABLE e2e_user_notes (
Expand All @@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users (id) ON DELETE CASCADE;
ALTER TABLE e2e_user_notes ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_notes VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
30 changes: 30 additions & 0 deletions internal/e2e/fixtures/cockroach/up/10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE e2e_users (
id UUID NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, created_at, updated_at)
);

CREATE TABLE e2e_user_posts (
id UUID NOT NULL,
user_id UUID NOT NULL,
content VARCHAR(255) NOT NULL DEFAULT '':::STRING,
slug VARCHAR(32) NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
INDEX e2e_user_notes_user_id_idx (user_id ASC),
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
FAMILY "primary" (id, user_id, content, slug)
);

CREATE TABLE schema_migration (
version VARCHAR(14) NOT NULL,
UNIQUE INDEX schema_migration_version_idx (version ASC),
FAMILY "primary" (version, rowid)
);

ALTER TABLE e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES e2e_users(id) ON DELETE CASCADE;

-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
ALTER TABLE e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;

0 comments on commit 0226681

Please sign in to comment.