-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support adding foreign key constraints in
add_column
This patch reverts some of the logic previously introduced for SQLite. It adds new functionality to `add_column`, allowing to define a foreign key when creating a column. This works for all databases and adds support for introducing foreign keys to SQLite schemas after a table has been created (not possible previously). This patch also upgrade PostgreSQL and CockroachDB and MySQL to supported versions as the versions used previously were no longer maintained.
- Loading branch information
Showing
145 changed files
with
2,325 additions
and
1,078 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
CREATE TABLE schema_migration ( | ||
-- # 1 column | ||
-- # row 1 | ||
-- ## 269 | ||
CREATE TABLE public.schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), | ||
CONSTRAINT "primary" PRIMARY KEY (rowid ASC), | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); | ||
-- # 1 row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
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 schema_migration ( | ||
-- # 1 column | ||
-- # row 1 | ||
-- ## 269 | ||
CREATE TABLE public.schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), | ||
CONSTRAINT "primary" PRIMARY KEY (rowid ASC), | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); | ||
-- # 1 row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
CREATE TABLE e2e_users ( | ||
-- # 1 column | ||
-- # row 1 | ||
-- ## 269 | ||
CREATE TABLE public.schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), | ||
CONSTRAINT "primary" PRIMARY KEY (rowid ASC), | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); | ||
-- # row 2 | ||
-- ## 208 | ||
CREATE TABLE public.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 ( | ||
-- # row 3 | ||
-- ## 352 | ||
CREATE TABLE public.e2e_user_posts ( | ||
id UUID NOT NULL, | ||
content VARCHAR(255) NOT NULL DEFAULT '':::STRING, | ||
user_id UUID NOT NULL, | ||
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, content, user_id, 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; | ||
-- # row 4 | ||
-- ## 152 | ||
ALTER TABLE public.e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES public.e2e_users(id) ON DELETE CASCADE; | ||
-- # row 5 | ||
-- ## 115 | ||
-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES | ||
-- # row 6 | ||
-- ## 85 | ||
ALTER TABLE public.e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk; | ||
-- # 6 rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
CREATE TABLE e2e_users ( | ||
-- # 1 column | ||
-- # row 1 | ||
-- ## 269 | ||
CREATE TABLE public.schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), | ||
CONSTRAINT "primary" PRIMARY KEY (rowid ASC), | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); | ||
-- # row 2 | ||
-- ## 208 | ||
CREATE TABLE public.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 ( | ||
-- # row 3 | ||
-- ## 352 | ||
CREATE TABLE public.e2e_user_posts ( | ||
id UUID NOT NULL, | ||
content VARCHAR(255) NOT NULL DEFAULT '':::STRING, | ||
slug VARCHAR(32) NOT NULL, | ||
user_id UUID NOT NULL, | ||
CONSTRAINT "primary" PRIMARY KEY (id ASC), | ||
UNIQUE INDEX e2e_user_notes_slug_idx (slug 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, content, slug, user_id) | ||
); | ||
|
||
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; | ||
-- # row 4 | ||
-- ## 152 | ||
ALTER TABLE public.e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES public.e2e_users(id) ON DELETE CASCADE; | ||
-- # row 5 | ||
-- ## 115 | ||
-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES | ||
-- # row 6 | ||
-- ## 85 | ||
ALTER TABLE public.e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk; | ||
-- # 6 rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
CREATE TABLE e2e_authors ( | ||
-- # 1 column | ||
-- # row 1 | ||
-- ## 269 | ||
CREATE TABLE public.schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), | ||
CONSTRAINT "primary" PRIMARY KEY (rowid ASC), | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); | ||
-- # row 2 | ||
-- ## 210 | ||
CREATE TABLE public.e2e_authors ( | ||
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 ( | ||
-- # row 3 | ||
-- ## 352 | ||
CREATE TABLE public.e2e_user_posts ( | ||
id UUID NOT NULL, | ||
content VARCHAR(255) NOT NULL DEFAULT '':::STRING, | ||
slug VARCHAR(32) NOT NULL, | ||
user_id UUID NOT NULL, | ||
CONSTRAINT "primary" PRIMARY KEY (id ASC), | ||
UNIQUE INDEX e2e_user_notes_slug_idx (slug 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, content, slug, user_id) | ||
); | ||
|
||
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_authors(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; | ||
-- # row 4 | ||
-- ## 154 | ||
ALTER TABLE public.e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (user_id) REFERENCES public.e2e_authors(id) ON DELETE CASCADE; | ||
-- # row 5 | ||
-- ## 115 | ||
-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES | ||
-- # row 6 | ||
-- ## 85 | ||
ALTER TABLE public.e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk; | ||
-- # 6 rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
CREATE TABLE e2e_authors ( | ||
-- # 1 column | ||
-- # row 1 | ||
-- ## 269 | ||
CREATE TABLE public.schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), | ||
CONSTRAINT "primary" PRIMARY KEY (rowid ASC), | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); | ||
-- # row 2 | ||
-- ## 210 | ||
CREATE TABLE public.e2e_authors ( | ||
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 ( | ||
-- # row 3 | ||
-- ## 358 | ||
CREATE TABLE public.e2e_user_posts ( | ||
id UUID NOT NULL, | ||
content VARCHAR(255) NOT NULL DEFAULT '':::STRING, | ||
slug VARCHAR(32) NOT NULL, | ||
author_id UUID NOT NULL, | ||
CONSTRAINT "primary" PRIMARY KEY (id ASC), | ||
UNIQUE INDEX e2e_user_notes_slug_idx (slug ASC), | ||
INDEX e2e_user_notes_auto_index_e2e_user_notes_e2e_users_id_fk (author_id ASC), | ||
INDEX e2e_user_notes_user_id_idx (author_id ASC), | ||
FAMILY "primary" (id, content, slug, author_id) | ||
); | ||
|
||
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 (author_id) REFERENCES e2e_authors(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; | ||
-- # row 4 | ||
-- ## 156 | ||
ALTER TABLE public.e2e_user_posts ADD CONSTRAINT e2e_user_notes_e2e_users_id_fk FOREIGN KEY (author_id) REFERENCES public.e2e_authors(id) ON DELETE CASCADE; | ||
-- # row 5 | ||
-- ## 115 | ||
-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES | ||
-- # row 6 | ||
-- ## 85 | ||
ALTER TABLE public.e2e_user_posts VALIDATE CONSTRAINT e2e_user_notes_e2e_users_id_fk; | ||
-- # 6 rows |
Oops, something went wrong.