feat: add renameIndex method#1638
Conversation
…dditional scenarios
Shinigami92
left a comment
There was a problem hiding this comment.
Needs test/migrations test
I'm working on it.I didn't see |
|
I'm still working onit.I'm traveling to another region of my country.I'm not full operational at the moment.As soon as possible will be back.Few days to be more precisely |
This reverts commit b308608.
|
@beterrabaA could you please come back and work further on this PR? I would like to merge it and plan the v9 stable release :3 |
|
Ok. Maybe it's better keep this method simple. Alter Index has too many variations. It's ok to do this? @Shinigami92 . I can't make tests for table spaces |
sure I can live with a first version and we can iterate incrementally |
|
@Shinigami92 check it out. I fixed the
|
There was a problem hiding this comment.
@Shinigami92 check it out. I fixed the
renameIndexand removed thealterIndexmethod.I just don't know how to usereversein migration tests.There's no examples using ondown. If u gimme the answer I'll use it.
test/migrations/098_rename_index.js![]()
Hey @beterrabaA, thanks for the update! 🙌
You don't need to call reverse manually — and you actually shouldn't write a down at all here. When a migration exports only up and every operation in it is reversible, node-pg-migrate auto-generates the down for you by calling each operation's .reverse in reverse order.
Both operations you use are reversible:
createIndex.reverse→dropIndexrenameIndex.reverse→ the one you just added 🎉
There are already examples of this pattern in the test suite that omit down entirely, e.g. test/migrations/006_table_rename.js:
export const up = (pgm) => {
pgm.renameTable('t2', 't2r');
};So test/migrations/098_rename_index.js can be simplified to just:
export const up = (pgm) => {
pgm.createIndex('t1', ['nmbr'], { name: 'idxfoo' });
pgm.renameIndex('idxfoo', 'quxfoo');
};The auto-generated down will then run the reverses in reverse order:
ALTER INDEX "quxfoo" RENAME TO "idxfoo";
DROP INDEX "idxfoo";This is also better than the current hand-written down: right now down only renames quxfoo back to idxfoo and leaves the created index behind, so it isn't a true inverse of up. The auto-reverse drops it too.
One last thing: after this change the integration snapshots need refreshing (the migrations-down.*.stdout.log files), since the down output now includes the DROP INDEX. You can update them with the test runner's update flag.
|
I'm preparing some food to eat.After it I'll make the changes |
|
@Shinigami92 I did it |



I created a method and tests cases to rename index with options.
Solving the problem from issue #1178