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

Allow some named inline column constraints in CREATE TABLE statements #559

Merged

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Dec 19, 2024

Allow some named inline column constraints in CREATE TABLE statements.

SQL like this can be converted to a pgroll OpCreateTable:

CREATE TABLE foo(a int CONSTRAINT my_check CHECK (a > 0))
CREATE TABLE foo(a int CONSTRAINT my_fk REFERENCES bar(b))

The previous behaviour was to allow only the unnamed forms of these constraints:

CREATE TABLE foo(a int CHECK (a > 0))
CREATE TABLE foo(a int REFERENCES bar(b))

Named inline column constraints remain unsupported for DEFAULT, NULL, NOT NULL, UNIQUE and PRIMARY KEY constraints and will fall back to a raw SQL operation.

@andrew-farries andrew-farries added the sql2pgroll Issues relating to the sql2pgroll package label Dec 19, 2024
@andrew-farries andrew-farries marked this pull request as ready for review December 19, 2024 16:18
@andrew-farries andrew-farries changed the base branch from main to fix-alter-table-add-column-expectations December 20, 2024 11:33
@andrew-farries andrew-farries force-pushed the allow-named-inline-constraints-in-create-table branch from 0e8a35a to 904fbce Compare December 20, 2024 11:33
Base automatically changed from fix-alter-table-add-column-expectations to main January 2, 2025 09:06
@andrew-farries andrew-farries force-pushed the allow-named-inline-constraints-in-create-table branch from 904fbce to 3b0170c Compare January 2, 2025 09:09
Allow some named inline column constraints in `CREATE TABLE` statements.

SQL like this can be converted to a pgroll `Column`:

```sql
CREATE TABLE foo(a int CONSTRAINT my_check CHECK (a > 0))
CREATE TABLE foo(a int CONSTRAINT my_fk REFERENCES bar(b))
```

The previous behaviour was to allow only the unamed forms of these:

```sql
CREATE TABLE foo(a int CHECK (a > 0))
CREATE TABLE foo(a int REFERENCES bar(b))
```

Named inline column constraints remain unsupported for `DEFAULT`, `NULL`,
`NOT NULL`, `UNIQUE` and `PRIMARY KEY` constraints.
@andrew-farries andrew-farries force-pushed the allow-named-inline-constraints-in-create-table branch from 3b0170c to d976256 Compare January 2, 2025 09:15
@andrew-farries andrew-farries merged commit ca094f5 into main Jan 2, 2025
28 checks passed
@andrew-farries andrew-farries deleted the allow-named-inline-constraints-in-create-table branch January 2, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql2pgroll Issues relating to the sql2pgroll package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants