refactoring sequelize migrations
This commit is contained in:
parent
a3c81d8f47
commit
f5511efd32
3 changed files with 7 additions and 34 deletions
|
@ -7,14 +7,11 @@
|
|||
"dev:nuxt": "cross-env NODE_ENV=development nuxt dev",
|
||||
"dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
|
||||
"build": "nuxt build",
|
||||
"start": "cross-env NODE_ENV=production node server/cli.js",
|
||||
"start:nuxt": "cross-env NODE_ENV=development nuxt start",
|
||||
"start": "cross-env sequelize db:migrate && NODE_ENV=production node server/cli.js",
|
||||
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
|
||||
"doc": "cd docs && bundle exec jekyll b",
|
||||
"precommit": "npm run lint",
|
||||
"migrate:dev": "sequelize db:migrate",
|
||||
"migrate": "NODE_ENV=production sequelize db:migrate",
|
||||
"prepublish": "nuxt build"
|
||||
"migrate": "NODE_ENV=production sequelize db:migrate"
|
||||
},
|
||||
"license": "AGPL-3.0",
|
||||
"bugs": {
|
||||
|
|
|
@ -160,11 +160,10 @@ async function setupQuestionnaire() {
|
|||
async function start (options) {
|
||||
// is first run?
|
||||
if (firstrun.check(options.config)) {
|
||||
consola.error(`Configuration file "${options.config}" not found!
|
||||
This is your first run? Run 'gancio setup'`)
|
||||
consola.error(`Configuration file "${options.config}" not found! Use "--config <CONFIG_FILE.json>" to specify another path.
|
||||
If this is your first run use 'gancio setup --config <CONFIG_FILE.json>' `)
|
||||
process.exit(-1)
|
||||
}
|
||||
await upgrade(options)
|
||||
require('./index')
|
||||
}
|
||||
|
||||
|
@ -173,32 +172,10 @@ async function setup (options) {
|
|||
const config = await setupQuestionnaire()
|
||||
await firstrun.setup(config, options.config)
|
||||
consola.info(`You can edit '${options.config}' to modify your configuration. `)
|
||||
consola.info(`Run "gancio --config ${options.config}"`)
|
||||
consola.info(`Start the server with "gancio --config ${options.config}"`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
async function upgrade (options) {
|
||||
const Umzug = require('umzug')
|
||||
const Sequelize = require('sequelize')
|
||||
const config = require('config')
|
||||
const db = new Sequelize(config.db)
|
||||
const umzug = new Umzug({
|
||||
storage: 'sequelize',
|
||||
storageOptions: { sequelize: db },
|
||||
migrations: {
|
||||
wrap: fun => {
|
||||
return () => fun(db.queryInterface, Sequelize)
|
||||
},
|
||||
path: path.resolve(__dirname, 'migrations')
|
||||
}
|
||||
})
|
||||
const migrations = await umzug.up()
|
||||
if (migrations.length) {
|
||||
consola.info('Migrations executed: ', migrations.map(m => m.file))
|
||||
}
|
||||
db.close()
|
||||
}
|
||||
|
||||
consola.info(`${package.name} - v${package.version} - ${package.description}`)
|
||||
|
||||
require('yargs')
|
||||
|
@ -215,8 +192,7 @@ require('yargs')
|
|||
})
|
||||
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
|
||||
.command('setup', 'Setup a new instance', {}, setup)
|
||||
.command('upgrade', 'Upgrade gancio to a new release (interactive)', {}, upgrade)
|
||||
.help('h')
|
||||
.alias('h', 'help')
|
||||
.epilog('Made with ❤ by underscore hacklab - https://autistici.org/underscore')
|
||||
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
|
||||
.argv
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
const config = require('config')
|
||||
|
||||
modules.exports = config.db
|
||||
module.exports = config.db
|
||||
|
|
Loading…
Reference in a new issue