Skip to content

Commit

Permalink
db: Add a migrate-test:rollback command
Browse files Browse the repository at this point in the history
This commands can undo database migrations in test mode.

Also fix the down migration of the household size and car number indexes
which failed to get the right index name.
  • Loading branch information
tahini committed Apr 4, 2024
1 parent 65869ed commit 543a4d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/evolution-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"migrate": "knex migrate:latest --knexfile lib/config/knexfile.js",
"migrate:rollback": "knex migrate:down --knexfile lib/config/knexfile.js",
"migrate-test": "cross-env NODE_ENV=test knex migrate:latest --knexfile lib/config/knexfile.js",
"migrate-test:rollback": "PROJECT_CONFIG=${PWD}/../../transition/tests/config_test.js cross-env NODE_ENV=test knex migrate:down --knexfile lib/config/knexfile.js",
"test": "cross-env NODE_ENV=test jest --config=jest.config.js",
"test:unit": "cross-env NODE_ENV=test jest --config=jest.config.js",
"test:sequential": "cross-env NODE_ENV=test jest --config=jest.sequential.config.js --runInBand",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function up(knex: Knex): Promise<unknown> {

export async function down(knex: Knex): Promise<unknown> {
return knex.schema.table(interviewsTbl, (table: Knex.TableBuilder) => {
table.dropIndex(indexNameSize);
table.dropIndex(indexNameCarNumber);
table.dropIndex([knex.raw('("responses"->\'household\'->>\'size\')')], indexNameSize);
table.dropIndex([knex.raw('("responses"->\'household\'->>\'carNumber\')')], indexNameCarNumber);
});
}

0 comments on commit 543a4d8

Please sign in to comment.