filesafe/database/migration.js
Bobby Wibowo aea89ecbd4
Updates and merged changes from 'master'
* Removing files from an album will now update the state of the said album. Which means, the Download Album as zip feature will properly make a new zip instead of re-using the old one which would obviously still have the said files.

* "migration.js" will no longer try to create column if it already exists.

* Changed type of all columns that used to be DATETIME to INTEGER. Apparently SQLite would have stored them as INTEGER anyways, so you don't have to change anything else.
2018-04-05 10:10:10 +07:00

34 lines
870 B
JavaScript

const config = require('../config.js')
const db = require('knex')(config.database)
const map = {
albums: {
editedAt: 'integer',
zipGeneratedAt: 'integer'
},
users: {
enabled: 'integer',
fileLength: 'integer'
}
}
const migration = {}
migration.start = async () => {
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)
}))
}))
console.log('Migration finished! Now start lolisafe normally')
process.exit(0)
}
migration.start()