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

Update TableNameMixin #644

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Aug 21, 2024

Support sqldelight/sqldelight#5407 CREATE OR REPLACE VIEW

Adding to SQL-PSI as best supported here to update the annotation check for EXISTS and REPLACE nodes, so that views can be replaced multiple times in migration files as scheme elements can only use a single CREATE statement and will fail with Table already defined with name $name.

A dialect (PostgreSql) will define CREATE OR REPLACE in the dialect grammar and has no effect in SQL-PSI or dialects that don't support CREATE OR REPLACE

Note:
The PostgreSql dialect will have to handle the possible addition of columns so CREATE OR REPLACE will have to behave like a cross-between IF NOT EXISTS and ALTER TABLE

Intentionally added remove to CreateViewMixin as it allows the columns to be replaced

override fun modifySchema(schema: Schema) {
    schema.forType<TableElement>().remove(name())
    schema.forType<SqlCreateViewStmt>().remove(name())
    schema.put<TableElement>(this)
    schema.put<SqlCreateViewStmt>(this)
  }

Testing with PostgreSql dialect using sql-psi snapshot version

Support CREATE OR REPLACE VIEW

Update the annotation check for EXISTS and REPLACE nodes, so that views can be replaced multiple times in migration files as scheme elements can only use a single CREATE statement

The sub dialect will define CREATE OR REPLACE in the  dialect grammar and has no effect in SQL-PSI
This appears to be the simple way to allow a CREATE OR REPLACE clause to be implemented in dialects
Without the need to implement something like ALTER TABLE mixin, it enables new columns to be generated in table interfaces from schema migrations files
@AlecKazakova
Copy link
Collaborator

yep good change. thanks

@AlecKazakova AlecKazakova merged commit b0c8897 into sqldelight:master Sep 5, 2024
1 check passed
@griffio griffio deleted the add-create-or-replace-view branch September 6, 2024 06:12
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.

2 participants