mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
51c5a81b18
Added "yarn migrate" as alias for "node ./database/migration.js". Updated README.md about it. Added a new column to users database: registration. It will be used to store user's registration timestamp. Registration date will be displayed in Dashboard's Manage Users. Since this is a new column, existing users will not have registration dates. Last token change date will now be displayed in Dashboard as well. <code> elements will now properly have relative font size. User ID will now be displayed in Edit user dialog for reference purpose. Bumped v1 version string and rebuilt client assets.
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
const perms = require('./../controllers/permissionController')
|
|
const config = require('./../config')
|
|
const db = require('knex')(config.database)
|
|
|
|
const map = {
|
|
files: {
|
|
expirydate: 'integer'
|
|
},
|
|
albums: {
|
|
editedAt: 'integer',
|
|
zipGeneratedAt: 'integer',
|
|
download: 'integer',
|
|
public: 'integer',
|
|
description: 'string'
|
|
},
|
|
users: {
|
|
enabled: 'integer',
|
|
permission: 'integer',
|
|
registration: 'integer'
|
|
}
|
|
}
|
|
|
|
;(async () => {
|
|
const tableNames = Object.keys(map)
|
|
for (const tableName of tableNames) {
|
|
const columnNames = Object.keys(map[tableName])
|
|
for (const columnName of columnNames) {
|
|
if (await db.schema.hasColumn(tableName, columnName))
|
|
continue
|
|
|
|
const columnType = map[tableName][columnName]
|
|
await db.schema.table(tableName, table => {
|
|
table[columnType](columnName)
|
|
})
|
|
console.log(`OK: ${tableName} <- ${columnName} (${columnType})`)
|
|
}
|
|
}
|
|
|
|
await db.table('users')
|
|
.where('username', 'root')
|
|
.first()
|
|
.update({
|
|
permission: perms.permissions.superadmin
|
|
})
|
|
.then(result => {
|
|
// NOTE: permissionController.js actually has a hard-coded check for "root" account so that
|
|
// it will always have "superadmin" permission regardless of its permission value in database
|
|
if (!result) 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.')
|
|
})()
|
|
.then(() => process.exit(0))
|
|
.catch(error => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|