-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert
ALTER TABLE foo ADD CONSTRAINT bar UNIQUE (a)
SQL to `pgrol…
…l` operation (#507) Convert SQL DDL of the form: ```sql "ALTER TABLE foo ADD CONSTRAINT bar UNIQUE (a)" ``` To the equivalent `pgroll` operation: ```json [ { "create_constraint": { "type": "unique", "table": "foo", "name": "bar", "columns": ["a"], "up": { "a": "...", }, "down": { "a": "..." } } } ] ``` We need to be conservative when converting SQL statements to `pgroll` operations to ensure that information present in the SQL is not lost during the conversion. There are several options possible as part of `ADD CONSTRAINT ... UNIQUE` statements that aren't currently representable by the `OpCreateConstraint` operation, for example: ```sql ALTER TABLE foo ADD CONSTRAINT bar UNIQUE NULLS NOT DISTINCT (a) ALTER TABLE foo ADD CONSTRAINT bar UNIQUE (a) INCLUDE (b) ``` In these cases we must resort to converting to an `OpRawSQL`. Tests are added to cover these unrepresentable cases. Part of #504
- Loading branch information
1 parent
fd94011
commit 06bfebd
Showing
5 changed files
with
166 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package expect | ||
|
||
import "github.com/xataio/pgroll/pkg/migrations" | ||
|
||
func RawSQLOp(sql string) *migrations.OpRawSQL { | ||
return &migrations.OpRawSQL{Up: sql} | ||
} |