Commit 87f45280 authored by Jure's avatar Jure

fix(db-manager): rethrow an error during migrations

parent af9354db
......@@ -35,7 +35,7 @@
"lodash": "^4.17.11",
"objection": "^1.5.3",
"pg": "^7.8.0",
"tmp-promise": "^1.0.5",
"tmp-promise": "^2.0.0",
"umzug": "^2.1.0"
},
"peerDependencies": {
......
......@@ -8,9 +8,10 @@ const migrate = async options => {
try {
await umzug.up(options)
} catch (e) {
logger.error('Error while running migrations:', e.message, e.stack)
logger.error('Error while running migrations:', e.message)
throw e
} finally {
cleanup()
await cleanup()
}
}
......
......@@ -4,6 +4,9 @@ const Umzug = require('umzug')
const fs = require('fs-extra')
const { extname, resolve } = require('path')
const tmp = require('tmp-promise')
tmp.setGracefulCleanup()
const storage = require('./umzugStorage')
// 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', () => {
it('runs migrations', async () => {
await createTables()
const { umzug } = await getUmzug([])
const { umzug, cleanup } = await getUmzug([])
const executedMigrations = await umzug.executed()
expect(executedMigrations.map(migration => migration.file)).toEqual([
'0001-component.js',
'0002-app.js',
'1524494862-entities.sql',
])
await cleanup()
})
it('does run them again', async () => {
const { umzug } = await getUmzug([])
const { umzug, cleanup } = await getUmzug([])
const pendingMigrations = await umzug.pending()
expect(pendingMigrations).toEqual([])
await cleanup()
})
})
CREATE A TABLE WITH BROKEN MIGRATION;
\ No newline at end of file
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