filesafe/database/migration.js
Bobby Wibowo da86f605c6
Updates [!! run database/migration.js !!]
Added description column into albums.
So yeah, now albums can have description.
It'll only be shown in the album's edit popup and public link.

HTML chars will now be escaped from album's name and description.

Removed message warning about CDN cache from album's public link.
A shortened version will be shown as the download button's tooltip.

Darkened color of textarea's placeholder.

Bumped v1 version string.
2018-12-13 16:09:46 +07:00

54 lines
1.6 KiB
JavaScript

const config = require('./../config')
const db = require('knex')(config.database)
const perms = require('./../controllers/permissionController')
const map = {
albums: {
editedAt: 'integer',
zipGeneratedAt: 'integer',
download: 'integer',
public: 'integer',
description: 'string'
},
users: {
enabled: 'integer',
fileLength: 'integer',
permission: '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 // console.log(`SKIP: ${column} => ${table}.`)
}
const columnType = map[table][column]
return db.schema.table(table, t => { t[columnType](column) })
.then(() => console.log(`OK: ${column} (${columnType}) => ${table}.`))
.catch(console.error)
}))
}))
await db.table('users')
.where('username', 'root')
.first()
.update({
permission: perms.permissions.superadmin
})
.then(rows => {
// NOTE: permissionController.js actually have a hard-coded check for "root" account so that
// it will always have "superadmin" permission regardless of its permission value in database
if (!rows) { return console.log('Unable to update root\'s permission into superadmin.') }
console.log(`Updated root's permission to ${perms.permissions.superadmin} (superadmin).`)
})
console.log('Migration finished! Now you may start lolisafe normally.')
process.exit(0)
}
migration.start()