You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convert ALTER TABLE foo ADD CONSTRAINT bar UNIQUE (a) SQL to pgroll 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
0 commit comments