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 table and column rename operations preceding drop_multicolumn_constraint operations #684

Merged
merged 7 commits into from
Feb 14, 2025

Conversation

andrew-farries
Copy link
Collaborator

Ensure that drop_multicolumn_constraint operations can be preceded by rename table and rename column operations as in the following example:

{
  "name": "24_drop_constraint",
  "operations": [
    {
      "rename_table": {
        "from": "items",
        "to": "products"
      }
    },
    {
      "rename_column": {
        "table": "products",
        "from": "name",
        "to": "item_name"
      }
    },
    {
      "drop_multicolumn_constraint": {
        "table": "products",
        "name": "name_length",
        "up": {
          "item_name": "item_name"
        },
        "down": {
          "item_name": "SELECT CASE WHEN length(item_name) <= 3 THEN LPAD(item_name, 4, '-') ELSE item_name END"
        }
      }
    }
  ]
}

Part of #239.

Use the physical table name when creating triggers. This ensures that if
the table is renamed in-memory by a preceding operation, trigger
creation still uses the correct table name.
When dropping the temporary column, use the physical table name instead
of the logical table name. This ensures that if the table was renamed by
a preceding operation, the correct table name is used.
When a column is renamed, update the column name in any constraints
affecting the column in the in-memory schema.

This ensures that subsequent operations can find the column in the
constraint list by its expected name.
When duplicating columns to remove a constraint, use the name of the
column as it will be when the migration is completed as the basis for
its name under duplication.
Save the old column name for use as the physical column name in the down
trigger.
@andrew-farries andrew-farries merged commit d927f3e into main Feb 14, 2025
28 checks passed
@andrew-farries andrew-farries deleted the support-multi-op-drop-constraint branch February 14, 2025 11:43
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