Make set_unique
operations respect the contract for old schema versions
#118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
pg-roll
makes a schema change, the contract with the user is that it will leave the old version of schema unchanged.When the operation to add a
UNIQUE
constraint was implemented (#53), this contract was not respected. The operation adds a unique index to the existing column, changing the behaviour for users of the old schema.This PR changes the operation so that it follows a similar pattern to other operations that were implemented later:
Start
:UNIQUE
index concurrentlyup
anddown
triggers to copy values between the old and new columns.up
SQLComplete
up
anddown
triggers.Writing correct
up
SQL for the operation is a little more difficult than for other operations (eg setNOT NULL
) as it is up to the user to ensure uniqueness of values. The example migration in this PR appends a random suffix to each value.