4d01e13a84
* Revert "Revert structured logging 2 (#1240)"
This reverts commit 78ecaeffcb.
* Logging should not be bundled into core shared directory
* making sure observability stuff isnt bundled into frontend
Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
44 lines
1.1 KiB
JavaScript
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
|