2018-01-23 20:06:30 +00:00
|
|
|
const config = require('../config.js')
|
|
|
|
const db = require('knex')(config.database)
|
2017-10-04 05:05:38 +00:00
|
|
|
|
2018-04-05 03:10:10 +00:00
|
|
|
const map = {
|
|
|
|
albums: {
|
|
|
|
editedAt: 'integer',
|
|
|
|
zipGeneratedAt: 'integer'
|
|
|
|
},
|
|
|
|
users: {
|
|
|
|
enabled: 'integer',
|
|
|
|
fileLength: 'integer'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 20:06:30 +00:00
|
|
|
const migration = {}
|
2017-10-04 05:05:38 +00:00
|
|
|
migration.start = async () => {
|
2018-04-05 03:10:10 +00:00
|
|
|
const tables = Object.keys(map)
|
|
|
|
await Promise.all(tables.map(table => {
|
|
|
|
const columns = Object.keys(map[table])
|
|
|
|
return Promise.all(columns.map(async column => {
|
|
|
|
if (await db.schema.hasColumn(table, column)) { return }
|
|
|
|
const columnType = map[table][column]
|
|
|
|
return db.schema.table(table, t => { t[columnType](column) })
|
|
|
|
.then(() => console.log(`Added column "${column}" to table "${table}".`))
|
|
|
|
.catch(console.error)
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
|
2018-01-23 20:06:30 +00:00
|
|
|
console.log('Migration finished! Now start lolisafe normally')
|
2018-03-14 06:57:09 +00:00
|
|
|
process.exit(0)
|
2018-01-23 20:06:30 +00:00
|
|
|
}
|
2017-10-04 05:05:38 +00:00
|
|
|
|
2018-01-23 20:06:30 +00:00
|
|
|
migration.start()
|