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

Fixes 5018 PostgreSql add Primary Key not nullable types #5020

Merged

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Feb 13, 2024

Fixes #5018

πŸ§‘β€πŸ³ πŸ§‡ Adds a mixin to the grammar to handle nullable types when adding a PRIMARY KEY with ALTER TABLE.
PostgreSql Primary Key columns are NOT NULL

AlterTableAddConstraintMixin
This takes a lazyQuery as input, checks if the table constraint is a primary key, updates matching columns to not nullable, and returns a new lazyQuery with the transformed columns. This has the effect of propagating primary key nullability constraints to the columns when altering the table.

New MigrationQueryTest added

tested locally with https://github.com/griffio/sqldelight-postgres-01

@griffio griffio changed the title Fixex 5018 PostgreSql add Primary Key not nullable types Fixes 5018 PostgreSql add Primary Key not nullable types Feb 13, 2024
to process rules in AlterTableAddConstraintMixin
This takes a lazyQuery as input, checks if the table constraint is a primary key, updates any matching columns to not nullable, and returns a new lazyQuery with the transformed columns. This has the effect of propagating primary key nullability constraints to the columns when altering the table.
New test for MigrationQueryTest for Postgresql - not relevant for Sqlite as can't alter table to add primary keys

Add tests for compiler generation for single and compound primary keys
@griffio griffio force-pushed the fix_5018_postgres_add_primary_key branch from 7ced7f6 to f9c237d Compare February 15, 2024 07:52
@AlecKazakova AlecKazakova merged commit 76a73f3 into cashapp:master Feb 15, 2024
11 checks passed
@griffio griffio deleted the fix_5018_postgres_add_primary_key branch February 15, 2024 19:01
hfhbd pushed a commit that referenced this pull request Apr 2, 2024
* Add mixin to grammar

to process rules in AlterTableAddConstraintMixin

* Add AlterTableAddConstraintMixin

This takes a lazyQuery as input, checks if the table constraint is a primary key, updates any matching columns to not nullable, and returns a new lazyQuery with the transformed columns. This has the effect of propagating primary key nullability constraints to the columns when altering the table.

* Add migration test fixtures

New test for MigrationQueryTest for Postgresql - not relevant for Sqlite as can't alter table to add primary keys

Add tests for compiler generation for single and compound primary keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PostgreSql - ALTER TABLE .. ADD PRIMARY KEY doesn't generate not nullable data class property
2 participants