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) {
|
2018-04-26 06:50:35 +00:00
|
|
|
table.increments();
|
|
|
|
table.integer('userid');
|
|
|
|
table.string('name');
|
|
|
|
table.string('identifier');
|
|
|
|
table.integer('enabled');
|
|
|
|
table.integer('timestamp');
|
2018-04-04 22:37:53 +00:00
|
|
|
table.integer('editedAt');
|
|
|
|
table.integer('zipGeneratedAt');
|
2018-04-26 06:50:35 +00:00
|
|
|
}).then(() => {});
|
2017-01-14 08:50:18 +00:00
|
|
|
|
|
|
|
db.schema.createTableIfNotExists('files', function (table) {
|
2018-04-26 06:50:35 +00:00
|
|
|
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');
|
|
|
|
}).then(() => {});
|
2017-01-14 08:50:18 +00:00
|
|
|
|
2017-01-29 07:19:02 +00:00
|
|
|
db.schema.createTableIfNotExists('users', function (table) {
|
2018-04-26 06:50:35 +00:00
|
|
|
table.increments();
|
|
|
|
table.string('username');
|
|
|
|
table.string('password');
|
|
|
|
table.string('token');
|
|
|
|
table.integer('enabled');
|
|
|
|
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) => {
|
2018-04-26 06:50:35 +00:00
|
|
|
if(user.length > 0) return;
|
2017-01-29 07:19:02 +00:00
|
|
|
|
|
|
|
require('bcrypt').hash('root', 10, function(err, hash) {
|
2018-04-26 06:50:35 +00:00
|
|
|
if(err) console.error('Error generating password hash for root');
|
2017-01-29 07:19:02 +00:00
|
|
|
|
|
|
|
db.table('users').insert({
|
|
|
|
username: 'root',
|
|
|
|
password: hash,
|
|
|
|
token: require('randomstring').generate(64),
|
|
|
|
timestamp: Math.floor(Date.now() / 1000)
|
2018-04-26 06:50:35 +00:00
|
|
|
}).then(() => {});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-01-16 07:45:29 +00:00
|
|
|
|
2018-04-26 06:50:35 +00:00
|
|
|
module.exports = init;
|