mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-15 00:46:22 +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.
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
const init = async db => {
|
|
// Create the tables we need to store galleries and files
|
|
await db.schema.hasTable('albums').then(exists => {
|
|
if (!exists)
|
|
return db.schema.createTable('albums', function (table) {
|
|
table.increments()
|
|
table.integer('userid')
|
|
table.string('name')
|
|
table.string('identifier')
|
|
table.integer('enabled')
|
|
table.integer('timestamp')
|
|
table.integer('editedAt')
|
|
table.integer('zipGeneratedAt')
|
|
table.integer('download')
|
|
table.integer('public')
|
|
table.string('description')
|
|
})
|
|
})
|
|
|
|
await db.schema.hasTable('files').then(exists => {
|
|
if (!exists)
|
|
return db.schema.createTable('files', function (table) {
|
|
table.increments()
|
|
table.integer('userid')
|
|
table.string('name')
|
|
table.string('original')
|
|
table.string('type')
|
|
table.string('size')
|
|
table.string('hash')
|
|
table.string('ip')
|
|
table.integer('albumid')
|
|
table.integer('timestamp')
|
|
table.integer('expirydate')
|
|
})
|
|
})
|
|
|
|
await db.schema.hasTable('users').then(exists => {
|
|
if (!exists)
|
|
return db.schema.createTable('users', function (table) {
|
|
table.increments()
|
|
table.string('username')
|
|
table.string('password')
|
|
table.string('token')
|
|
table.integer('enabled')
|
|
table.integer('timestamp')
|
|
table.integer('permission')
|
|
table.integer('registration')
|
|
})
|
|
})
|
|
|
|
const root = await db.table('users')
|
|
.where('username', 'root')
|
|
.first()
|
|
|
|
if (!root) {
|
|
const hash = await require('bcrypt').hash('changeme', 10)
|
|
const timestamp = Math.floor(Date.now() / 1000)
|
|
await db.table('users').insert({
|
|
username: 'root',
|
|
password: hash,
|
|
token: require('randomstring').generate(64),
|
|
timestamp,
|
|
permission: require('./../controllers/permissionController').permissions.superadmin,
|
|
registration: timestamp
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = init
|