8000 Support table and column rename operations preceding `create_constraint` `UNIQUE` operations by andrew-farries · Pull Request #676 · xataio/pgroll · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support table and column rename operations preceding create_constraint UNIQUE operations #676

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 3 commits into from
Feb 11, 2025

Conversation

andrew-farries
Copy link
Collaborator
@andrew-farries andrew-farries commented Feb 11, 2025

Follow up to #674 which ensured that create_constraint CHECK operations could be preceded by rename table and rename column operations.

This PR ensures that create_constraint UNIQUE operations can be preceded by rename table and rename column operations as in the following example:

{
  "name": "19_multiple_ops",
  "operations": [
    {
      "rename_table": {
        "from": "items",
        "to": "products"
      }
    },
    {
      "rename_column": {
        "table": "products",
        "from": "name",
        "to": "item_name"
      }
    },
    {
      "create_constraint": {
        "table": "products",
        "type": "unique",
        "name": "unique_item_name",
        "columns": ["item_name"],
        "up": {
          "item_name": "item_name || '-from-up'"
        },
        "down": {
          "item_name": "item_name || '-from-down'"
        }
      }
    }
  ]
}

Part of #239

Now that we will add testcases for other constraint types too.
Use the physical name of the table when creating a unique constraint
index concurrently. This ensures that if the table has been renamed in
the in-memory schema by a preceding operation, the constraint is still
applied correctly.
@andrew-farries andrew-farries merged commit 1f26ef1 into main Feb 11, 2025
28 checks passed
@andrew-farries andrew-farries deleted the support-multi-op-create-unique-constraint branch February 11, 2025 16:25
andrew-farries added a commit that referenced this pull request Feb 14, 2025
…nt` `FOREIGN KEY` operations (#682)

Ensure that `create_constraint` `FOREIGN KEY` operations can be preceded
by rename table and rename column operations as in the following
example:

```json
{
  "name": "22_multiple_ops",
  "operations": [
    {
      "rename_table": {
        "from": "items",
        "to": "products"
      }
    },
    {
      "rename_column": {
        "table": "products",
        "from": "owner",
        "to": "owner_id"
      }
    },
    {
      "create_constraint": {
        "table": "products",
        "type": "foreign_key",
        "name": "fk_items_users",
        "columns": ["owner_id"],
        "references": {
          "table": "users",
          "columns": ["id"]
        },
        "up": {
          "owner_id": "owner_id"
        },
        "down": {
          "owner_id": "owner_id"
        }
      }
    }
  ]
}
```

Follow up to #674 and #676. 

Part of #239.
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