Files
speckle-server/packages/server/modules/cli/commands/db/migrate/down.ts
T
Kristaps Fabians Geikins a9a313ee63 feat(server): cli and cross-server-sync multiregion support (#3527)
* feat(server): cross-server-sync multiregion ready

* fixed various db commands

* db cli works

* final changes
2024-11-22 19:52:58 +01:00

38 lines
968 B
TypeScript

import { logger } from '@/logging/logging'
import { CommonDbArgs, getTargettedDbClients } from '@/modules/cli/commands/db/helpers'
import { CommandModule } from 'yargs'
const command: CommandModule<unknown, { times: number } & CommonDbArgs> = {
command: 'down [times]',
describe: 'Undo last migration',
builder: {
times: {
type: 'number',
default: 1,
describe: 'Number of migrations to undo'
}
},
async handler(argv) {
const { times, regionKey } = argv
const howManyTimes = times || 1
logger.info(
howManyTimes === 1
? 'Undoing last migration...'
: `Undoing last ${howManyTimes} migrations...`
)
const dbs = await getTargettedDbClients({ regionKey })
for (const db of dbs) {
logger.info(`Migrating DB ${db.regionKey}...`)
for (let i = 0; i < howManyTimes; i++) {
await db.client.migrate.down()
}
}
logger.info('Completed!')
}
}
export = command