-
Notifications
You must be signed in to change notification settings - Fork 82
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 support for foreign key constraints in create_table
operation
#597
Conversation
internal/jsonschema/testdata/create-table-14-invalid-fk-missing-referenced-table.txtar
Outdated
Show resolved
Hide resolved
internal/jsonschema/testdata/create-table-15-invalid-fk-missing-columns.txtar
Outdated
Show resolved
Hide resolved
pkg/migrations/op_common_test.go
Outdated
@@ -40,6 +44,14 @@ func ExecuteTests(t *testing.T, tests TestCases, opts ...roll.Option) { | |||
testSchema := testutils.TestSchema() | |||
|
|||
for _, tt := range tests { | |||
if tt.minPgMajorVersion != 0 && os.Getenv("POSTGRES_VERSION") != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this because setting a column list for ON DELETE
actions was released in pg15.
pkg/migrations/op_common_test.go
Outdated
@@ -40,6 +44,14 @@ func ExecuteTests(t *testing.T, tests TestCases, opts ...roll.Option) { | |||
testSchema := testutils.TestSchema() | |||
|
|||
for _, tt := range tests { | |||
if tt.minPgMajorVersion != 0 && os.Getenv("POSTGRES_VERSION") != "" { | |||
pgMajorVersion := strings.Split(os.Getenv("POSTGRES_VERSION"), ".")[0] | |||
version, _ := strconv.Atoi(pgMajorVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POSTGRES_VERSION
is set to latest
as part of the CI test matrix, ie not necessarily a Major.Minor string.
It's really a Postgres docker image tag, not strictly a postgres version number.
Maybe put this logic in a function and handle the case where it isn't Major.Minor release number.
This PR adds support for
foreign_key
constraints in table constraint definitions increate_table
.It includes all settings that are currently available in PostgreSQL 17. At the moment, this option is superior to other foreign key definitions in pgroll because it supports
ON UPDATE
andMATCH
type settings. As I mentioned in earlier PRs, once this work is finished, I am unifying the constraint options in all operations.Example constraint configuration: