8000 Add support for `alter_table` set `NOT NULL` operations with `create_table` operations by andrew-farries · Pull Request #608 · xataio/pgroll · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for alter_table set NOT NULL operations with create_table operations #608

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 2 commits into from
Jan 20, 2025

Conversation

andrew-farries
Copy link
Collaborator
@andrew-farries andrew-farries commented Jan 20, 2025

Ensure that multi-operation migrations combining alter_column SET NOT NULL and create_table operations work as expected.

{
  "name": "06_multi_operation",
  "operations": [
    {
      "create_table": {
        "name": "items",
        "columns": [
          {
            "name": "id",
            "type": "serial",
            "pk": true
          },
          {
            "name": "name",
            "type": "text",
            "nullable": true
          }
        ]
      }
    },
    {
      "alter_column": {
        "table": "items",
        "column": "name",
        "nullable": false,
        "up": "SELECT CASE WHEN name IS NULL THEN 'anonymous' ELSE name END",
        "down": "name || '_from_down_trigger'"
      }
    }
  ]
}

This migration creates a table and then sets a column's nullability.

Previously the migration would fail as the alter_column operation was unaware of the changes made by the preceding operation.

Part of #239

@andrew-farries andrew-farries force-pushed the support-rename-column-set-not-null branch from 508a839 to 60e201c Compare January 20, 2025 11:04
@andrew-farries andrew-farries force-pushed the support-create-table-set-not-null branch from 03f78a6 to 632f47c Compare January 20, 2025 11:04
Base automatically changed from support-rename-column-set-not-null to main January 20, 2025 11:10
Record the type of the columns in the new table in the in-memory
schema representation built by `OpCreateTable`.

This ensures that a columns can be duplicated correctly if a following
operation in the same migration needs to duplicate the column.
@andrew-farries andrew-farries force-pushed the support-create-table-set-not-null branch from 632f47c to ce2b4dd Compare January 20, 2025 11:12
@andrew-farries andrew-farries merged commit cec0d80 into main Jan 20, 2025
28 checks passed
@andrew-farries andrew-farries deleted the support-create-table-set-not-null branch January 20, 2025 11:15
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
0