forked from gobuffalo/fizz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle foreign keys and indices properly in SQLite and add e2e tests
This patch resolves issues with `change_column` and `drop_column` which previously caused duplicate or missing indices and foreign keys. To prevent future regressions and help debugging, a new e2e-test pipeline has been added to the project and the CI. Documentation for running the tests has been added to the README. End-to-end tests currently support MySQL, PostgreSQL, and SQLite and do not yet cover other SQL dialects. During review, please help ensure that the SQL fixtures are not missing something :) Closes gobuffalo#92
- Loading branch information
Showing
88 changed files
with
3,652 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,6 @@ sqlserver: | |
sqlite: | ||
dialect: "sqlite3" | ||
database: "./sql_scripts/sqlite/test.sqlite" | ||
options: | ||
mode: rwc | ||
|
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package e2e_test | ||
|
||
import ( | ||
"github.com/gobuffalo/pop/v5" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type CockroachSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (s *CockroachSuite) Test_Cockroach_MigrationSteps() { | ||
r := s.Require() | ||
|
||
c, err := pop.Connect("cockroach") | ||
r.NoError(err) | ||
r.NoError(retryOpen(c)) | ||
|
||
run(&s.Suite, c, runTestData(&s.Suite, c, true)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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 schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); |
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 |
---|---|---|
@@ -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_notes ( | ||
id UUID NOT NULL, | ||
notes VARCHAR(255) NULL, | ||
user_id UUID NOT 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) | ||
); | ||
|
||
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_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; |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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_notes ( | ||
id UUID NOT NULL, | ||
notes VARCHAR(255) NULL, | ||
user_id UUID 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), | ||
FAMILY "primary" (id, notes, 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_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; |
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 |
---|---|---|
@@ -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_notes ( | ||
id UUID NOT NULL, | ||
notes VARCHAR(255) NULL, | ||
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, notes, 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_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; |
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 |
---|---|---|
@@ -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_notes ( | ||
id UUID NOT NULL, | ||
notes VARCHAR(255) NULL, | ||
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, notes, 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_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; |
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 |
---|---|---|
@@ -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_notes ( | ||
id UUID NOT NULL, | ||
notes VARCHAR(255) NULL, | ||
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, notes, 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_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; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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 schema_migration ( | ||
version VARCHAR(14) NOT NULL, | ||
UNIQUE INDEX schema_migration_version_idx (version ASC), | ||
FAMILY "primary" (version, rowid) | ||
); |
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 |
---|---|---|
@@ -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_notes ( | ||
id UUID NOT NULL, | ||
notes VARCHAR(255) NULL, | ||
title VARCHAR(64) NOT NULL DEFAULT '':::STRING, | ||
user_id UUID 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), | ||
INDEX e2e_user_notes_title_idx (title ASC), | ||
FAMILY "primary" (id, notes, title, 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_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; |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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_notes ( | ||
id UUID NOT NULL, | ||
notes VARCHAR(255) NULL, | ||
user_id UUID 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), | ||
FAMILY "primary" (id, notes, 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_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; |
Oops, something went wrong.