Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add foreign key support #53

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ Postgres v13 and below are not supported. Use at your own risk.
Note, the library only currently supports diffing the *public* schema. Support for diffing other schemas is on the roadmap

*Unsupported*:
- (On roadmap) Foreign key constraints
- (On roadmap) Diffing schemas other than "public"
- (On roadmap) Unique constraints (unique indexes are supported but not unique constraints)
- (On roadmap) Adding and remove partitions from an existing partitioned table
Expand Down
4 changes: 4 additions & 0 deletions internal/migration_acceptance_tests/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/stripe/pg-schema-diff/pkg/tempdb"
)

var (
errValidatingPlan = fmt.Errorf("validating migration plan")
)

type (
expectations struct {
planErrorIs error
Expand Down
31 changes: 29 additions & 2 deletions internal/migration_acceptance_tests/check_constraint_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ var checkConstraintCases = []acceptanceTestCase{
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Add check constraint with UDF dependency should error",
Expand Down Expand Up @@ -106,6 +109,9 @@ var checkConstraintCases = []acceptanceTestCase{
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Add multiple check constraints",
Expand All @@ -128,6 +134,9 @@ var checkConstraintCases = []acceptanceTestCase{
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Add check constraints to new column",
Expand All @@ -148,6 +157,9 @@ var checkConstraintCases = []acceptanceTestCase{
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Add check constraint with quoted identifiers",
Expand All @@ -170,6 +182,9 @@ var checkConstraintCases = []acceptanceTestCase{
ALTER TABLE foobar ADD CONSTRAINT "BAR_CHECK" CHECK ( "Bar" < "ID" );
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Add no inherit check constraint",
Expand All @@ -192,6 +207,9 @@ var checkConstraintCases = []acceptanceTestCase{
ALTER TABLE foobar ADD CONSTRAINT bar_check CHECK ( bar > id ) NO INHERIT;
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Add No-Inherit, Not-Valid check constraint",
Expand Down Expand Up @@ -381,7 +399,7 @@ var checkConstraintCases = []acceptanceTestCase{
},
},
{
name: "Alter a No-Inherit check constraint to be Inheritable",
name: "Alter a no-Inherit check constraint to be Inheritable",
oldSchemaDDL: []string{
`
CREATE TABLE foobar(
Expand All @@ -402,9 +420,12 @@ var checkConstraintCases = []acceptanceTestCase{
ALTER TABLE foobar ADD CONSTRAINT bar_check CHECK ( bar > id );
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Alter an Inheritable check constraint to be No-Inherit",
name: "Alter an Inheritable check constraint to be no-inherit",
oldSchemaDDL: []string{
`
CREATE TABLE foobar(
Expand All @@ -425,6 +446,9 @@ var checkConstraintCases = []acceptanceTestCase{
ALTER TABLE foobar ADD CONSTRAINT bar_check CHECK ( bar > id ) NO INHERIT;
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Alter a check constraint expression",
Expand All @@ -446,6 +470,9 @@ var checkConstraintCases = []acceptanceTestCase{
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
},
},
{
name: "Alter check constraint with UDF dependency should error",
Expand Down
8 changes: 6 additions & 2 deletions internal/migration_acceptance_tests/column_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,12 @@ var columnAcceptanceTestCases = []acceptanceTestCase{
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
diff.MigrationHazardTypeImpactsDatabasePerformance,
},
vanillaExpectations: expectations{planErrorContains: "validating migration plan"},
dataPackingExpectations: expectations{planErrorContains: "validating migration plan"},
vanillaExpectations: expectations{
planErrorContains: errValidatingPlan.Error(),
},
dataPackingExpectations: expectations{
planErrorContains: errValidatingPlan.Error(),
},
},
{
name: "Change to not null",
Expand Down
Loading