Files
speckle-server/packages/server/modules/cli/commands/db/migrate/create.js
T
Iain Sproat 444d2ca7dd Structured logging (attempt 2) (#1234)
* Revert "Revert "feat(structured logging): implements structured logging for backend (#1217)" (#1227)"

This reverts commit 63e6581162.

* Use pino-http instead of express pino logger
* Use correct reference to knex and do not instantiate HttpLogger prematurely
* Adds missing dependency for pino to webhook-service
* Do not instantiate middleware when passed to express
* Refactor to move logging into shared
* Copy shared packages into dockerfiles
* Build shared workspace in docker build-stage for fileimport & webhook
2022-12-05 14:49:52 +00:00

44 lines
1.1 KiB
JavaScript

const knex = require('@/db/knex')
const { appRoot } = require('@/bootstrap')
const fs = require('fs/promises')
const { logger } = require('@/logging/logging')
/** @type {import('yargs').CommandModule} */
const command = {
command: 'create <name> [module]',
describe: 'Create a new migration',
builder(yargs) {
return yargs
.positional('name', {
describe: 'Migration name',
type: 'string'
})
.positional('module', {
describe: 'The server module into which this migration should be generated',
type: 'string',
default: 'core'
})
},
async handler(argv) {
const name = argv.name
const migrationDir = `${appRoot}/modules/${argv.module}/migrations`
try {
await fs.access(migrationDir)
} catch (e) {
throw new Error(
`Migration directory '${migrationDir}' is not accessible! Check if it exists.`
)
}
logger.info('Creating migration...')
await knex.migrate.make(name, {
directory: migrationDir,
extension: 'ts'
})
logger.info('migration is complete')
}
}
module.exports = command