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

Refactor alter column suboperations #337

Merged
merged 7 commits into from
Apr 10, 2024

Conversation

andrew-farries
Copy link
Collaborator

Remove duplication between 'alter column' sub-operations. Pull:

  • column duplication and trigger creation on migration start
  • column rename and trigger removal on complete
  • trigger and column drop on rollback

up to the parent 'alter column' operation. This removes a lot of duplicated code from the sub-operations and will make it easier to support multiple sub-operations in one 'alter column' operation.

Part of #336

@andrew-farries andrew-farries merged commit d4445bb into main Apr 10, 2024
44 checks passed
@andrew-farries andrew-farries deleted the refactor-alter-column-subops branch April 10, 2024 14:17
andrew-farries added a commit that referenced this pull request Apr 22, 2024
Allow 'alter column' operations to include multiple sub-operations. This
means migrations like this one are now possible:

```json
{
  "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
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