aboutsummaryrefslogtreecommitdiff
path: root/database
diff options
context:
space:
mode:
author8cy <[email protected]>2020-05-23 02:24:18 -0700
committer8cy <[email protected]>2020-05-23 02:24:18 -0700
commit454825558aef4320c82b3d3148537038364c9427 (patch)
treefc8366ce0203fd58bb65d843c04608d25a08ab16 /database
downloadstrelizia-master.tar.xz
strelizia-master.zip
DARLING in the FRANXXHEADmaster
Diffstat (limited to 'database')
-rw-r--r--database/db.js53
-rw-r--r--database/migration.js13
2 files changed, 66 insertions, 0 deletions
diff --git a/database/db.js b/database/db.js
new file mode 100644
index 0000000..8655f76
--- /dev/null
+++ b/database/db.js
@@ -0,0 +1,53 @@
+let init = function(db){
+
+ // Create the tables we need to store galleries and files
+ db.schema.createTableIfNotExists('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');
+ }).then(() => {});
+
+ db.schema.createTableIfNotExists('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');
+ }).then(() => {});
+
+ db.schema.createTableIfNotExists('users', function (table) {
+ table.increments();
+ table.string('username');
+ table.string('password');
+ table.string('token');
+ table.integer('enabled');
+ table.integer('timestamp');
+ }).then(() => {
+ 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(() => {});
+ });
+ });
+ });
+};
+
+module.exports = init;
diff --git a/database/migration.js b/database/migration.js
new file mode 100644
index 0000000..7e5b0e9
--- /dev/null
+++ b/database/migration.js
@@ -0,0 +1,13 @@
+const config = require('../config.js');
+const db = require('knex')(config.database);
+
+const migration = {};
+migration.start = async () => {
+ await db.schema.table('albums', table => {
+ table.integer('editedAt');
+ table.integer('zipGeneratedAt');
+ });
+ console.log('Migration finished! Now start strelizia normally');
+};
+
+migration.start();