fix migration so it doesn't error out on existing devices

This commit is contained in:
Josh Harvey 2017-12-19 18:55:14 +02:00
parent 2b3e49fdab
commit d3c2448a12
2 changed files with 29 additions and 5 deletions

View file

@ -1,12 +1,20 @@
const db = require('./db')
const migrateTools = require('./migrate-tools')
exports.up = function (next) {
const sql = [
'alter table devices add column name text not null'
]
db.multi(sql, next)
return migrateTools.migrateNames()
.then(updateSql => {
const sql = [
'alter table devices add column name text',
updateSql,
'alter table devices alter column name set not null'
]
return db.multi(sql, next)
})
}
exports.down = function (next) {
next()
const sql = ['alter table devices drop column name']
db.multi(sql, next)
}