Skip to content

Improve validation of create_table and add_column operations #666

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

Merged
merged 6 commits into from
Feb 11, 2025

Conversation

andrew-farries
Copy link
Collaborator

Improve validation of create_table and add_column operations.

Previously, these operations would fail at migration Start if one of the column definitions was invalid due to having a missing name or type field.

This PR adds extra validation checks to both operations to ensure that such migrations fail at the validation stage instead.

Ensure that a `Column` has all required fields needed to create it.
All columns in create table statements need to be valid themselves (ie
have no missing required fields).
@andrew-farries andrew-farries marked this pull request as ready for review February 7, 2025 16:48
@andrew-farries andrew-farries requested a review from kvch February 7, 2025 16:48
Copy link
Contributor

@kvch kvch left a comment

Choose a reason for hiding this comment

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

These errors are caught by the JSON validator when the user writes their config files, no?

@andrew-farries
Copy link
Collaborator Author

These errors are caught by the JSON validator when the user writes their config files, no?

Yes, the JSON schema will reject these errors.

We should use JSON schema validation in pgroll itself - currently it's not used. It was added to support third party tools like the migration editor in Xata, but pgroll itself doesn't use the JSON schema to validate migration files.

I created #673 to start doing JSON validation in pgroll itself.

@andrew-farries andrew-farries merged commit d697304 into main Feb 11, 2025
28 checks passed
@andrew-farries andrew-farries deleted the validate-column-definitions branch February 11, 2025 07:25
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