Files
speckle-server/packages/server/modules/cli/commands/db/migrate/create.js
T
Iain Sproat 84cb74e8b3 feat(structured logging): implements structured logging for backend (#1217)
* each log line is a json object
* structured logging allows logs to be ingested by machines and the logs to be indexed and queried addresses #1105
* structured logging allows arbitrary properties to be appended to each log line, and ingestion of logs to remain robust
* Structured logging provided by `pino` library
* Add `express-pino-logger` dependency
* Remove `debug`, `morgan`, and `morgan-debug` and replace with structured logging
* `console.log` & `console.error` replaced with structured logging in backend
* Remove `DEBUG` environment variable and replace with `LOG_LEVEL`
- Note that there is a test which reads from a logged line on `stdout`. This is not robust, it would be better to use the childProcess.pid to look up the port number.
* Log errors at points we explicitly send error to Sentry
* Amend indentation of a couple of log messages to align indentation with others
2022-11-25 16:05:05 +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