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

Support multiple 'alter column' sub operations #338

Merged
merged 7 commits into from
Apr 22, 2024

Conversation

andrew-farries
Copy link
Collaborator

Allow 'alter column' operations to include multiple sub-operations. This means migrations like this one are now possible:

{
  "name": "35_alter_column_multiple",
  "operations": [
    {
      "alter_column": {
        "table": "events",
        "column": "name",
        "name": "event_name",
        "type": "text",
        "nullable": false,
        "unique": {
          "name": "events_event_name_unique"
        },
        "check": {
          "name": "event_name_length",
          "constraint": "length(name) > 3"
        },
        "up": "(SELECT CASE WHEN name IS NULL THEN 'placeholder' ELSE name END)",
        "down": "name"
      }
    }
  ]
}

This 'alter column' operation:

  • Renames a column
  • Changes its type
  • Sets it NOT NULL
  • Adds a unique constraint
  • Adds a check constraint

Previously, this would have required 5 different operations.

Builds on #337. Fixes #336

@andrew-farries andrew-farries force-pushed the support-multiple-alter-column-sub-ops branch 2 times, most recently from ab784c9 to fd2751f Compare April 12, 2024 02:11
Create a new table and then make multiple changes to one of its columns
in a subsequent migration.
This is now inlined into the parent alter column operation.
Now that multiple sub-operations are supported.
To specify that multiple sub-operations are possible in an alter column
operation.
@andrew-farries andrew-farries force-pushed the support-multiple-alter-column-sub-ops branch from fd2751f to 0c2e02c Compare April 22, 2024 08:05
@andrew-farries andrew-farries merged commit a4222d8 into main Apr 22, 2024
44 checks passed
@andrew-farries andrew-farries deleted the support-multiple-alter-column-sub-ops branch April 22, 2024 11:11
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.

Support multiple sub-operations in one 'alter column' migration
2 participants