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

No way to delete unique constraint when it was created with a custom name #441

Open
Mordil opened this issue Jul 12, 2021 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Mordil
Copy link
Member

Mordil commented Jul 12, 2021

When creating a .unique constraint using the unique(on:name:) method, the constraint name will use the given name value, rather than an automatically generated one.

When attempting to delete the unique constraint in revert(on:) using the deleteUnique(on:) method, it will attempt to delete the constraint with an automatically generated name from the unique keys, rather than the custom name provided in the unique(on:name:) method - which causes the migration revert to fail.

To Reproduce

  1. Create a new migration
  2. Add a .unique constraint using .unique(on:name:)
  3. In the revert(on:) method, call .deleteUnique(on:)
  4. Run swift run migrate -y
  5. Run swift run migrate --revert -y

You will see the following error:

$ vapor run migrate --revert -y
Migrate Command: Revert
The following migration(s) will be reverted:
- App.Tool.Seed on default
- App.Tool.MakeToolUnique on default
- App.Tool.AddMaker on default
- App.Tool.Create on default
Would you like to continue?
y/n> yes
[ WARNING ] previousError(server: constraint "uq:tools.name+tools.maker" of relation "tools" does not exist (ATExecDropConstraint))
Swift/ErrorType.swift:200: Fatal error: Error raised at top level: previousError(server: constraint "uq:tools.name+tools.maker" of relation "tools" does not exist (ATExecDropConstraint))
@Mordil Mordil added the bug Something isn't working label Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant