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

Add rename_constraint operation #293

Merged
merged 5 commits into from
Mar 1, 2024
Merged

Add rename_constraint operation #293

merged 5 commits into from
Mar 1, 2024

Conversation

SferaDev
Copy link
Member

@SferaDev SferaDev commented Mar 1, 2024

In the frontend when renaming a column we were adding OpRawSQL operations that ALTER TABLE "${tableName}" RENAME CONSTRAINT "${oldName}" TO "${newName}"; to keep the constraints up to date for the data api to like them. Proposing to expose a new operation for that use case.

Before merging, an example should be added for the new operation.

Signed-off-by: Alexis Rico <sferadev@gmail.com>
pkg/schema/schema.go Outdated Show resolved Hide resolved
@SferaDev SferaDev marked this pull request as ready for review March 1, 2024 05:16
Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 Thanks for doing it 🙏

We also need:

  • An example migration in /examples . Either add a migration to create a table with a constraint then another migration to rename it, or just add a migration to rename one of the constraints created in an existing example.
  • Update the docs/README.md file operations reference section.

pkg/schema/schema.go Outdated Show resolved Hide resolved
pkg/migrations/op_rename_constraint.go Outdated Show resolved Hide resolved
Signed-off-by: Alexis Rico <sferadev@gmail.com>
Signed-off-by: Alexis Rico <sferadev@gmail.com>
Signed-off-by: Alexis Rico <sferadev@gmail.com>
Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the example can be:

{
  "name": "33_rename_check_constraint",
  "operations": [
    {
      "rename_constraint": {
        "table": "people",
        "from": "name_length",
        "to": "name_length_check"
      }
    }
  ]
}

to rename one of the constraints created by an earlier migration.

@SferaDev SferaDev enabled auto-merge (squash) March 1, 2024 11:27
@SferaDev SferaDev merged commit 577870c into main Mar 1, 2024
42 checks passed
@SferaDev SferaDev deleted the rename-constraint branch March 1, 2024 11:30
andrew-farries added a commit that referenced this pull request Mar 1, 2024
…finition (#300)

Otherwise migrations that include this operation are not valid according
to the JSON schema.

Fixup to #293.
andrew-farries added a commit that referenced this pull request Mar 4, 2024
Add a CI step to validate that the example migrations are valid
according to the JSON schema.

This would have caught the problem where the JSON schema was not fully
updated in #293 and had to be
updated in a follow-up PR #300
despite #293 including an example migration.

Use [ajv-cli](https://ajv.js.org/packages/ajv-cli.html) to perform
schema validation.

Here is an [example
run](https://github.com/xataio/pgroll/actions/runs/8113707179/job/22177613982)
where the check fails.
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.

None yet

2 participants