2017-01-29 08:19:02 +01:00
|
|
|
let init = function(db){
|
2017-01-14 09:50:18 +01:00
|
|
|
|
|
|
|
// Create the tables we need to store galleries and files
|
2017-01-17 23:05:00 +01:00
|
|
|
db.schema.createTableIfNotExists('albums', function (table) {
|
2017-01-14 09:50:18 +01:00
|
|
|
table.increments()
|
2017-01-29 08:19:02 +01:00
|
|
|
table.integer('userid')
|
2017-01-14 09:50:18 +01:00
|
|
|
table.string('name')
|
2017-02-07 08:32:55 +01:00
|
|
|
table.string('identifier')
|
2017-01-18 09:06:53 +01:00
|
|
|
table.integer('enabled')
|
2017-01-18 06:40:14 +01:00
|
|
|
table.integer('timestamp')
|
2017-01-14 09:50:18 +01:00
|
|
|
}).then(() => {})
|
|
|
|
|
|
|
|
db.schema.createTableIfNotExists('files', function (table) {
|
|
|
|
table.increments()
|
2017-01-29 08:19:02 +01:00
|
|
|
table.integer('userid')
|
2017-01-16 09:22:19 +01:00
|
|
|
table.string('name')
|
2017-01-16 08:21:46 +01:00
|
|
|
table.string('original')
|
|
|
|
table.string('type')
|
|
|
|
table.string('size')
|
2017-01-19 07:34:48 +01:00
|
|
|
table.string('hash')
|
2017-01-16 08:21:46 +01:00
|
|
|
table.string('ip')
|
2017-01-17 23:05:00 +01:00
|
|
|
table.integer('albumid')
|
2017-01-18 06:40:14 +01:00
|
|
|
table.integer('timestamp')
|
2017-01-14 09:50:18 +01:00
|
|
|
}).then(() => {})
|
|
|
|
|
2017-01-29 08:19:02 +01:00
|
|
|
db.schema.createTableIfNotExists('users', function (table) {
|
|
|
|
table.increments()
|
|
|
|
table.string('username')
|
|
|
|
table.string('password')
|
|
|
|
table.string('token')
|
2017-01-18 06:40:14 +01:00
|
|
|
table.integer('timestamp')
|
2017-01-16 08:37:42 +01:00
|
|
|
}).then(() => {
|
2017-01-29 08:19:02 +01:00
|
|
|
db.table('users').where({username: 'root'}).then((user) => {
|
|
|
|
if(user.length > 0) return
|
|
|
|
|
|
|
|
require('bcrypt').hash('root', 10, function(err, hash) {
|
|
|
|
if(err) console.error('Error generating password hash for root')
|
|
|
|
|
|
|
|
db.table('users').insert({
|
|
|
|
username: 'root',
|
|
|
|
password: hash,
|
|
|
|
token: require('randomstring').generate(64),
|
|
|
|
timestamp: Math.floor(Date.now() / 1000)
|
|
|
|
}).then(() => {})
|
|
|
|
})
|
|
|
|
})
|
2017-01-16 08:37:42 +01:00
|
|
|
})
|
2017-01-16 08:45:29 +01:00
|
|
|
}
|
|
|
|
|
2017-01-14 09:50:18 +01:00
|
|
|
module.exports = init
|