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 a 'set default' sub-operation to 'alter column' #346

Merged
merged 7 commits into from
Apr 25, 2024

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Apr 24, 2024

Allow 'alter column' operations to set the default value on a column:

{
  "name": "02_change_default",
  "operations": [
    {
      "alter_column": {
        "table": "events",
        "column": "name",
        "default": "'new default value'"
      }
    }
  ]
}

This is a versioned migration so the column to which the default is applied is duplicated and backfilled according to the up and down SQL supplied with the 'alter column' operation. up and down default to a simple copy of the field between new and old columns.

Fixes #327

Set a default and alter it in a subsequent migration.
This change allows the insert function to insert NULL values in the
database. This is useful for testing the alter column default value
suboperation.
Ensure that it's possible to alter a column to set it to not null and
add a default value in a single operation.
@andrew-farries andrew-farries merged commit afad3d8 into main Apr 25, 2024
44 checks passed
@andrew-farries andrew-farries deleted the add-alter-column-default-sub-op branch April 25, 2024 10:47
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 changing a column DEFAULT value
2 participants