Skip to content

Commit 0226681

Browse files
authored
Add failing test case for drop_column (#96)
* 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
1 parent 4e9fb9c commit 0226681

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1649
-160
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
volumes:
2323
- ./sqldumps:/docker-entrypoint-initdb.d
2424
cockroach:
25-
image: cockroachdb/cockroach:v2.1.0
25+
image: cockroachdb/cockroach:v19.2.10
2626
ports:
2727
- "26257:26257"
2828
- "8080:8080"

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
229229
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
230230
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA=
231231
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
232+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
232233
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
233234
golang.org/x/net v0.0.0-20200219183655-46282727080f h1:dB42wwhNuwPvh8f+5zZWNcU+F2Xs/B9wXXwvUCOH7r8=
234235
golang.org/x/net v0.0.0-20200219183655-46282727080f/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

internal/e2e/fixtures/cockroach/down/1.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ CREATE TABLE e2e_users (
22
id UUID NOT NULL,
33
created_at TIMESTAMP NOT NULL,
44
updated_at TIMESTAMP NOT NULL,
5+
username VARCHAR(255) NULL,
56
CONSTRAINT "primary" PRIMARY KEY (id ASC),
6-
FAMILY "primary" (id, created_at, updated_at)
7+
FAMILY "primary" (id, created_at, updated_at, username)
78
);
89

910
CREATE TABLE schema_migration (
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CREATE TABLE e2e_users (
2+
id UUID NOT NULL,
3+
created_at TIMESTAMP NOT NULL,
4+
updated_at TIMESTAMP NOT NULL,
5+
CONSTRAINT "primary" PRIMARY KEY (id ASC),
6+
FAMILY "primary" (id, created_at, updated_at)
7+
);
8+
9+
CREATE TABLE e2e_user_posts (
10+
id UUID NOT NULL,
11+
user_id UUID NOT NULL,
12+
content VARCHAR(255) NOT NULL DEFAULT '':::STRING,
13+
slug VARCHAR(64) NOT NULL,
14+
CONSTRAINT "primary" PRIMARY KEY (id ASC),
15+
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
16+
INDEX e2e_user_notes_user_id_idx (user_id ASC),
17+
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
18+
FAMILY "primary" (id, user_id, content, slug)
19+
);
20+
21+
CREATE TABLE schema_migration (
22+
version VARCHAR(14) NOT NULL,
23+
UNIQUE INDEX schema_migration_version_idx (version ASC),
24+
FAMILY "primary" (version, rowid)
25+
);
26+
27+
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;
28+
29+
-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
30+
ALTER TABLE e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;

internal/e2e/fixtures/cockroach/down/2.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
22
id UUID NOT NULL,
33
created_at TIMESTAMP NOT NULL,
44
updated_at TIMESTAMP NOT NULL,
5+
username VARCHAR(255) NULL,
56
CONSTRAINT "primary" PRIMARY KEY (id ASC),
6-
FAMILY "primary" (id, created_at, updated_at)
7+
FAMILY "primary" (id, created_at, updated_at, username)
78
);
89

910
CREATE TABLE e2e_user_notes (
1011
id UUID NOT NULL,
11-
notes VARCHAR(255) NULL,
1212
user_id UUID NOT NULL,
13+
notes VARCHAR(255) NULL,
1314
title VARCHAR(64) NOT NULL DEFAULT '':::STRING,
1415
CONSTRAINT "primary" PRIMARY KEY (id ASC),
1516
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
1617
INDEX e2e_user_notes_user_id_idx (user_id ASC),
1718
INDEX e2e_user_notes_title_idx (title ASC),
18-
FAMILY "primary" (id, notes, user_id, title)
19+
FAMILY "primary" (id, user_id, notes, title)
1920
);
2021

2122
CREATE TABLE schema_migration (
@@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
2425
FAMILY "primary" (version, rowid)
2526
);
2627

27-
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;
28+
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;
2829

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

internal/e2e/fixtures/cockroach/down/3.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ CREATE TABLE e2e_users (
22
id UUID NOT NULL,
33
created_at TIMESTAMP NOT NULL,
44
updated_at TIMESTAMP NOT NULL,
5+
username VARCHAR(255) NULL,
56
CONSTRAINT "primary" PRIMARY KEY (id ASC),
6-
FAMILY "primary" (id, created_at, updated_at)
7+
FAMILY "primary" (id, created_at, updated_at, username)
78
);
89

910
CREATE TABLE e2e_user_notes (
1011
id UUID NOT NULL,
11-
notes VARCHAR(255) NULL,
1212
user_id UUID NOT NULL,
13+
notes VARCHAR(255) NULL,
1314
CONSTRAINT "primary" PRIMARY KEY (id ASC),
1415
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
1516
INDEX e2e_user_notes_user_id_idx (user_id ASC),
16-
FAMILY "primary" (id, notes, user_id)
17+
FAMILY "primary" (id, user_id, notes)
1718
);
1819

1920
CREATE TABLE schema_migration (
@@ -22,7 +23,7 @@ CREATE TABLE schema_migration (
2223
FAMILY "primary" (version, rowid)
2324
);
2425

25-
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;
26+
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;
2627

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

internal/e2e/fixtures/cockroach/down/4.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
22
id UUID NOT NULL,
33
created_at TIMESTAMP NOT NULL,
44
updated_at TIMESTAMP NOT NULL,
5+
username VARCHAR(255) NULL,
56
CONSTRAINT "primary" PRIMARY KEY (id ASC),
6-
FAMILY "primary" (id, created_at, updated_at)
7+
FAMILY "primary" (id, created_at, updated_at, username)
78
);
89

910
CREATE TABLE e2e_user_notes (
1011
id UUID NOT NULL,
11-
notes VARCHAR(255) NULL,
1212
user_id UUID NOT NULL,
1313
slug VARCHAR(64) NOT NULL,
14+
notes VARCHAR(255) NULL,
1415
CONSTRAINT "primary" PRIMARY KEY (id ASC),
1516
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
1617
INDEX e2e_user_notes_user_id_idx (user_id ASC),
1718
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
18-
FAMILY "primary" (id, notes, user_id, slug)
19+
FAMILY "primary" (id, user_id, slug, notes)
1920
);
2021

2122
CREATE TABLE schema_migration (
@@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
2425
FAMILY "primary" (version, rowid)
2526
);
2627

27-
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;
28+
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;
2829

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

internal/e2e/fixtures/cockroach/down/5.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
22
id UUID NOT NULL,
33
created_at TIMESTAMP NOT NULL,
44
updated_at TIMESTAMP NOT NULL,
5+
username VARCHAR(255) NULL,
56
CONSTRAINT "primary" PRIMARY KEY (id ASC),
6-
FAMILY "primary" (id, created_at, updated_at)
7+
FAMILY "primary" (id, created_at, updated_at, username)
78
);
89

910
CREATE TABLE e2e_user_notes (
1011
id UUID NOT NULL,
11-
notes VARCHAR(255) NULL,
1212
user_id UUID NOT NULL,
1313
slug VARCHAR(64) NOT NULL,
14+
notes VARCHAR(255) NULL,
1415
CONSTRAINT "primary" PRIMARY KEY (id ASC),
1516
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
1617
INDEX e2e_user_notes_user_id_idx (user_id ASC),
1718
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
18-
FAMILY "primary" (id, notes, user_id, slug)
19+
FAMILY "primary" (id, user_id, slug, notes)
1920
);
2021

2122
CREATE TABLE schema_migration (
@@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
2425
FAMILY "primary" (version, rowid)
2526
);
2627

27-
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;
28+
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;
2829

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

internal/e2e/fixtures/cockroach/down/6.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ CREATE TABLE e2e_users (
22
id UUID NOT NULL,
33
created_at TIMESTAMP NOT NULL,
44
updated_at TIMESTAMP NOT NULL,
5+
username VARCHAR(255) NULL,
56
CONSTRAINT "primary" PRIMARY KEY (id ASC),
6-
FAMILY "primary" (id, created_at, updated_at)
7+
FAMILY "primary" (id, created_at, updated_at, username)
78
);
89

910
CREATE TABLE e2e_user_notes (
1011
id UUID NOT NULL,
11-
notes VARCHAR(255) NULL,
1212
user_id UUID NOT NULL,
1313
slug VARCHAR(64) NOT NULL,
14+
notes VARCHAR(255) NULL,
1415
CONSTRAINT "primary" PRIMARY KEY (id ASC),
1516
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
1617
INDEX e2e_user_notes_user_id_idx (user_id ASC),
1718
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
18-
FAMILY "primary" (id, notes, user_id, slug)
19+
FAMILY "primary" (id, user_id, slug, notes)
1920
);
2021

2122
CREATE TABLE schema_migration (
@@ -24,7 +25,7 @@ CREATE TABLE schema_migration (
2425
FAMILY "primary" (version, rowid)
2526
);
2627

27-
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;
28+
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;
2829

2930
-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
3031
ALTER TABLE e2e_user_notes VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CREATE TABLE e2e_users (
2+
id UUID NOT NULL,
3+
created_at TIMESTAMP NOT NULL,
4+
updated_at TIMESTAMP NOT NULL,
5+
username VARCHAR(255) NULL,
6+
CONSTRAINT "primary" PRIMARY KEY (id ASC),
7+
FAMILY "primary" (id, created_at, updated_at, username)
8+
);
9+
10+
CREATE TABLE e2e_user_posts (
11+
id UUID NOT NULL,
12+
user_id UUID NOT NULL,
13+
slug VARCHAR(64) NOT NULL,
14+
notes VARCHAR(255) NULL,
15+
CONSTRAINT "primary" PRIMARY KEY (id ASC),
16+
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (user_id ASC),
17+
INDEX e2e_user_notes_user_id_idx (user_id ASC),
18+
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC),
19+
FAMILY "primary" (id, user_id, slug, notes)
20+
);
21+
22+
CREATE TABLE schema_migration (
23+
version VARCHAR(14) NOT NULL,
24+
UNIQUE INDEX schema_migration_version_idx (version ASC),
25+
FAMILY "primary" (version, rowid)
26+
);
27+
28+
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;
29+
30+
-- Validate foreign key constraints. These can fail if there was unvalidated data during the dump.
31+
ALTER TABLE e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk;

0 commit comments

Comments
 (0)