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

Strengthen assertions for tests that check preservation of UNIQUE constraints #277

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

andrew-farries
Copy link
Collaborator

Strengthen the tests that check for preservation of UNIQUE constraints when a column is duplicated so that they can check for the failure case in #273.

It's not enough to test that the column does not accept duplicate values after the migration completes. Both a unique index and a unique constraint will have that effect but we need to ensure that the constraint is present on the table once the migration completes.

Duplicating a UNIQUE constraint is a two-step process, first creating a UNIQUE index on migration start and then upgrading the index to a constraint on migration completion. #273 occurs when this upgrade fails and the column is left with the unique index but not the constraint. Subsequent migrations will then fail to duplicate the non-existent unique constraint.

Part of #273

It's not enough to test that the column does not accept duplicate values
after the migration completes. Both a unique index and a unique
constraint will have that effect but we need to ensure that the
**constraint** is present on the table once the migration completes.
@andrew-farries andrew-farries merged commit 5686ddc into main Feb 6, 2024
26 checks passed
@andrew-farries andrew-farries deleted the strengthen-test-assertions branch February 6, 2024 07:39
andrew-farries added a commit that referenced this pull request Feb 7, 2024
Remove the schema component from index names in the internal schema
representation.

A `pgroll` migration is always run in the context of a a specific schema
so the extra qualification is redundant.

Removing the schema component from the index names makes it easy to
identify duplicated indexes by name when temporary columns and
associated attributes are renamed on migration completion.

Tests for this change are already in place (#276, #277). As of this PR,
migration tests run in a non-public schema will pass:

```bash
PGROLL_TEST_SCHEMA=foo go test ./...
```

Part of #273
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