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