Save migrations file on db (#215)

* Revert "Migration sql changes (#199)"

This reverts commit 12c834469c.

* Save migrate file on db

* Add message on migration error in lamassu-update
This commit is contained in:
Rafael Taranto 2018-11-18 07:15:22 -02:00 committed by Josh Harvey
parent 9af204e609
commit 06f8c57608
58 changed files with 1516 additions and 567 deletions

22
lib/db-migrate-store.js Normal file
View file

@ -0,0 +1,22 @@
const db = require('../lib/db')
const upsert = 'insert into migrations (id, data) values (1, $1) on conflict (id) do update set data = $1'
function DbMigrateStore () {
}
DbMigrateStore.prototype.save = function (set, fn) {
let insertData = JSON.stringify({
lastRun: set.lastRun,
migrations: set.migrations
})
db.none(upsert, [insertData]).then(fn).catch(err => console.log(err))
}
DbMigrateStore.prototype.load = function (fn) {
db.one('select data from migrations').then(({ data }) => {
fn(null, data)
})
}
module.exports = DbMigrateStore