-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20140e8
commit e123b11
Showing
10 changed files
with
595 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package migration_acceptance_tests | ||
|
||
import "github.com/stripe/pg-schema-diff/pkg/diff" | ||
|
||
var enumAcceptanceTestCases = []acceptanceTestCase{ | ||
{ | ||
name: "no-op", | ||
oldSchemaDDL: []string{ | ||
` | ||
CREATE TYPE color AS ENUM ('red', 'green', 'blue'); | ||
CREATE TABLE foo( | ||
color color DEFAULT 'green' | ||
); | ||
`, | ||
}, | ||
newSchemaDDL: []string{ | ||
` | ||
CREATE TYPE color AS ENUM ('red', 'green', 'blue'); | ||
CREATE TABLE foo( | ||
color color DEFAULT 'green' | ||
); | ||
`, | ||
}, | ||
|
||
vanillaExpectations: expectations{ | ||
empty: true, | ||
}, | ||
dataPackingExpectations: expectations{ | ||
empty: true, | ||
}, | ||
}, | ||
{ | ||
name: "create enum", | ||
oldSchemaDDL: []string{ | ||
` | ||
CREATE TABLE foo(); | ||
`, | ||
}, | ||
newSchemaDDL: []string{ | ||
` | ||
CREATE SCHEMA schema_1; | ||
CREATE TYPE schema_1.color AS ENUM ('red', 'green', 'blue'); | ||
CREATE TABLE foo( | ||
color schema_1.color DEFAULT 'green' | ||
); | ||
`, | ||
}, | ||
}, | ||
{ | ||
name: "drop enum", | ||
oldSchemaDDL: []string{ | ||
` | ||
CREATE SCHEMA schema_1; | ||
CREATE TYPE schema_1.color AS ENUM ('red', 'green', 'blue'); | ||
CREATE TABLE foo( | ||
color schema_1.color DEFAULT 'green' | ||
); | ||
`, | ||
}, | ||
newSchemaDDL: []string{ | ||
` | ||
CREATE SCHEMA schema_1; | ||
CREATE TABLE foo( | ||
color VARCHAR(255) DEFAULT 'green' | ||
); | ||
`, | ||
}, | ||
expectedHazardTypes: []diff.MigrationHazardType{ | ||
diff.MigrationHazardTypeAcquiresAccessExclusiveLock, | ||
diff.MigrationHazardTypeImpactsDatabasePerformance, | ||
}, | ||
}, | ||
{ | ||
name: "add values", | ||
oldSchemaDDL: []string{ | ||
` | ||
CREATE TYPE some_enum_1 AS ENUM ('1', '2', '3'); | ||
CREATE TABLE foo( | ||
val some_enum_1 | ||
); | ||
`}, | ||
newSchemaDDL: []string{ | ||
` | ||
CREATE TYPE some_enum_1 AS ENUM ('0', '1', '1.5', '2', '2.5', '3', '4'); | ||
CREATE TABLE foo( | ||
val some_enum_1 DEFAULT '1.5' | ||
); | ||
`}, | ||
}, | ||
{ | ||
name: "delete value and add value (enum not used)", | ||
oldSchemaDDL: []string{ | ||
` | ||
CREATE TYPE some_enum_1 AS ENUM ('1', '2', '3'); | ||
`}, | ||
newSchemaDDL: []string{ | ||
` | ||
CREATE TYPE some_enum_1 AS ENUM ('0', '1', '3'); | ||
`}, | ||
}, | ||
{ | ||
name: "delete value and add value (enum used)", | ||
oldSchemaDDL: []string{ | ||
` | ||
CREATE TYPE some_enum_1 AS ENUM ('1', '2', '3'); | ||
CREATE TABLE foo( | ||
val some_enum_1 | ||
); | ||
`}, | ||
newSchemaDDL: []string{ | ||
` | ||
CREATE TYPE some_enum_1 AS ENUM ('0', '1', '3'); | ||
CREATE TABLE foo( | ||
val some_enum_1 | ||
); | ||
`}, | ||
|
||
// Removing a value from an enum in-use is impossible in Postgres. pg-schema-diff will currently identify this | ||
// as a validation error. In the future, we can identify this in the actual plan generation stage. | ||
vanillaExpectations: expectations{ | ||
planErrorContains: errValidatingPlan.Error(), | ||
}, | ||
dataPackingExpectations: expectations{ | ||
planErrorContains: errValidatingPlan.Error(), | ||
}, | ||
}, | ||
} | ||
|
||
func (s *acceptanceTestSuite) TestEnumTestCases() { | ||
s.runTestCases(enumAcceptanceTestCases) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.