Commit 43af70cf authored by Jure's avatar Jure

Merge branch 'improve_migration_cli' into 'master'

Improve CLI's migrate command

Closes #450

See merge request !572
parents af9354db 999b47ed
Pipeline #13040 passed with stages
in 14 minutes and 31 seconds
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
"express-fileupload": "v1.1.1-alpha.2", "express-fileupload": "v1.1.1-alpha.2",
"passport": "^0.4.0", "passport": "^0.4.0",
"pubsweet-server": "^13.5.1", "pubsweet-server": "^13.5.1",
"tmp-promise": "^1.0.5" "tmp-promise": "^2.0.0"
}, },
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
"lodash": "^4.17.11", "lodash": "^4.17.11",
"objection": "^1.5.3", "objection": "^1.5.3",
"pg": "^7.8.0", "pg": "^7.8.0",
"tmp-promise": "^1.0.5", "tmp-promise": "^2.0.0",
"umzug": "^2.1.0" "umzug": "^2.1.0"
}, },
"peerDependencies": { "peerDependencies": {
......
...@@ -8,9 +8,10 @@ const migrate = async options => { ...@@ -8,9 +8,10 @@ const migrate = async options => {
try { try {
await umzug.up(options) await umzug.up(options)
} catch (e) { } catch (e) {
logger.error('Error while running migrations:', e.message, e.stack) logger.error('Error while running migrations:', e.message)
throw e
} finally { } finally {
cleanup() await cleanup()
} }
} }
......
...@@ -4,6 +4,9 @@ const Umzug = require('umzug') ...@@ -4,6 +4,9 @@ const Umzug = require('umzug')
const fs = require('fs-extra') const fs = require('fs-extra')
const { extname, resolve } = require('path') const { extname, resolve } = require('path')
const tmp = require('tmp-promise') const tmp = require('tmp-promise')
tmp.setGracefulCleanup()
const storage = require('./umzugStorage') const storage = require('./umzugStorage')
// Load SQL files as migrations // Load SQL files as migrations
......
const config = require('config')
Object.assign(config, {
pubsweet: {
components: [`${__dirname}/../mocks/componentWithBrokenMigration`],
},
})
const migrate = require('../../src/commands/migrate')
describe('broken migrations', () => {
it('throws an error when they run', async () => {
await expect(migrate()).rejects.toThrow(
'CREATE A TABLE WITH BROKEN MIGRATION; - syntax error at or near "A"',
)
})
})
...@@ -19,18 +19,20 @@ describe('create tables', () => { ...@@ -19,18 +19,20 @@ describe('create tables', () => {
it('runs migrations', async () => { it('runs migrations', async () => {
await createTables() await createTables()
const { umzug } = await getUmzug([]) const { umzug, cleanup } = await getUmzug([])
const executedMigrations = await umzug.executed() const executedMigrations = await umzug.executed()
expect(executedMigrations.map(migration => migration.file)).toEqual([ expect(executedMigrations.map(migration => migration.file)).toEqual([
'0001-component.js', '0001-component.js',
'0002-app.js', '0002-app.js',
'1524494862-entities.sql', '1524494862-entities.sql',
]) ])
await cleanup()
}) })
it('does run them again', async () => { it('does run them again', async () => {
const { umzug } = await getUmzug([]) const { umzug, cleanup } = await getUmzug([])
const pendingMigrations = await umzug.pending() const pendingMigrations = await umzug.pending()
expect(pendingMigrations).toEqual([]) expect(pendingMigrations).toEqual([])
await cleanup()
}) })
}) })
CREATE A TABLE WITH BROKEN MIGRATION;
\ No newline at end of file
...@@ -17257,12 +17257,11 @@ tiny-warning@^1.0.0, tiny-warning@^1.0.2: ...@@ -17257,12 +17257,11 @@ tiny-warning@^1.0.0, tiny-warning@^1.0.2:
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.2.tgz#1dfae771ee1a04396bdfde27a3adcebc6b648b28" resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.2.tgz#1dfae771ee1a04396bdfde27a3adcebc6b648b28"
integrity sha512-rru86D9CpQRLvsFG5XFdy0KdLAvjdQDyZCsRcuu60WtzFylDM3eAWSxEVz5kzL2Gp544XiUvPbVKtOA/txLi9Q== integrity sha512-rru86D9CpQRLvsFG5XFdy0KdLAvjdQDyZCsRcuu60WtzFylDM3eAWSxEVz5kzL2Gp544XiUvPbVKtOA/txLi9Q==
tmp-promise@^1.0.5: tmp-promise@^2.0.0:
version "1.1.0" version "2.0.2"
resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-1.1.0.tgz#bb924d239029157b9bc1d506a6aa341f8b13e64c" resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-2.0.2.tgz#ee605edb10f100954be5dd8b9dbe1bfd56194202"
integrity sha512-8+Ah9aB1IRXCnIOxXZ0uFozV1nMU5xiu7hhFVUSxZ3bYu+psD4TzagCzVbexUCgNNGJnsmNDQlS4nG3mTyoNkw== integrity sha512-zl71nFWjPKW2KXs+73gEk8RmqvtAeXPxhWDkTUoa3MSMkjq3I+9OeknjF178MQoMYsdqL730hfzvNfEkePxq9Q==
dependencies: dependencies:
bluebird "^3.5.0"
tmp "0.1.0" tmp "0.1.0"
tmp@0.1.0: tmp@0.1.0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment