2017-01-29 07:19:02 +00:00
|
|
|
let init = function(db){
|
2017-01-14 08:50:18 +00:00
|
|
|
|
|
|
|
// Create the tables we need to store galleries and files
|
2017-01-17 22:05:00 +00:00
|
|
|
db.schema.createTableIfNotExists('albums', function (table) {
|
2017-01-14 08:50:18 +00:00
|
|
|
table.increments()
|
2017-01-29 07:19:02 +00:00
|
|
|
table.integer('userid')
|
2017-01-14 08:50:18 +00:00
|
|
|
table.string('name')
|
2017-01-18 08:06:53 +00:00
|
|
|
table.integer('enabled')
|
2017-01-18 05:40:14 +00:00
|
|
|
table.integer('timestamp')
|
2017-01-14 08:50:18 +00:00
|
|
|
}).then(() => {})
|
|
|
|
|
|
|
|
db.schema.createTableIfNotExists('files', function (table) {
|
|
|
|
table.increments()
|
2017-01-29 07:19:02 +00:00
|
|
|
table.integer('userid')
|
2017-01-16 08:22:19 +00:00
|
|
|
table.string('name')
|
2017-01-16 07:21:46 +00:00
|
|
|
table.string('original')
|
|
|
|
table.string('type')
|
|
|
|
table.string('size')
|
2017-01-19 06:34:48 +00:00
|
|
|
table.string('hash')
|
2017-01-16 07:21:46 +00:00
|
|
|
table.string('ip')
|
2017-01-17 22:05:00 +00:00
|
|
|
table.integer('albumid')
|
2017-01-18 05:40:14 +00:00
|
|
|
table.integer('timestamp')
|
2017-01-14 08:50:18 +00:00
|
|
|
}).then(() => {})
|
|
|
|
|
2017-01-29 07:19:02 +00:00
|
|
|
db.schema.createTableIfNotExists('users', function (table) {
|
|
|
|
table.increments()
|
|
|
|
table.string('username')
|
|
|
|
table.string('password')
|
|
|
|
table.string('token')
|
2017-01-18 05:40:14 +00:00
|
|
|
table.integer('timestamp')
|
2017-01-16 07:37:42 +00:00
|
|
|
}).then(() => {
|
2017-01-29 07:19:02 +00: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 07:37:42 +00:00
|
|
|
})
|
2017-01-16 07:45:29 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 08:50:18 +00:00
|
|
|
module.exports = init
|