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

dropIndex doesn't generate the correct name for a unique index #857

Closed
georgeroman opened this issue Dec 16, 2021 · 4 comments · Fixed by #858
Closed

dropIndex doesn't generate the correct name for a unique index #857

georgeroman opened this issue Dec 16, 2021 · 4 comments · Fixed by #858

Comments

@georgeroman
Copy link

Unique indexes created via createIndex(table, column, { unique: true }) get assigned a name following the pattern: table_column_unique_index. However, when the same index needs to be dropped via dropIndex, there is no option to specify that the index is unique and so dropIndex will try to drop the index named table_column_index which is different than what we want. A fix for this would add a unique option to dropIndex so that it can generate the correct index name.

@littlewhywhat
Copy link
Contributor

hi @georgeroman!

Yes, i see the problem.

While we fixing it - some other options to consider for you:

  • you can provide the name explicitly via name option. Smth like this should work:
pgm.createIndex('table', ['col1', 'col2'], { name: 'example_index' })

pgm.dropIndex('table', ['col1', 'col2'], { name: 'example_index' })
  • it should work at the moment if you let node-pg-migrate to generate down migration (by not exporting down function from your migration file).

@littlewhywhat
Copy link
Contributor

@georgeroman one other note - the fix seems to be just in type - so if you ignore ts error or use js then you can just provide { unique: true } option to dropIndex and it should work as well:

pgm.dropIndex('table', ['col1', 'col2'], { unique: true })

@littlewhywhat
Copy link
Contributor

Fix is realized in https://github.com/salsita/node-pg-migrate/releases/tag/v6.1.0.

Thank you!

@georgeroman
Copy link
Author

Perfect, thank you for the quick response and fix!

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 a pull request may close this issue.

2 participants