I use pg_dump
to make a copy of the database, copy1.sql
.
I run an up migration to create a new instance
up: asyn (queryInterface) => {
return await queryInterface.bulkInsert('keys', [{ clientKey: 'key123' }]);
}
I run a down migration to delete the instance
down: async (queryInterface) => {
return await queryInterface.bulkDelete('keys', { clientKey: ['key123'] });
}
I do another pg_dump
of the database, copy2.sql
. I compare the first copy of the database with the second copy of the database to show that the down migration worked properly by running a bash script
diff "copy1.sql" "copy2.sql"
The difference is
-SELECT pg_catalog.setval('public.keys_id_seq', 6, true);
+SELECT pg_catalog.setval('public.keys_id_seq', 7, true);
This makes my test fail because the copies of both databases are not identical due to this difference. Even though I deleted that key, it's saying the next id sequence is going to start at 8 instead of 7 according to this document. The table rows that currently exists are 1 through 6. Is there a way to delete the instance so that the sequence will start at 7 instead of 8? Meaning both copies of the database should have
SELECT pg_catalog.setval('public.keys_id_seq', 6, true);
Are there options I can include? Maybe something like
down: async (queryInterface) => {
return await queryInterface.bulkDelete('keys', { clientKey: ['key123'] }, { resetIdSequence: true });
}