aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrations/s2
diff options
context:
space:
mode:
authorRan Guin <[email protected]>2021-07-19 12:19:18 -0700
committerRan Guin <[email protected]>2021-07-19 12:19:18 -0700
commite238eab45f1f5b6f3dbf40ddff59b9db804ffb4f (patch)
tree9bcfd0547a97a49aad19f8db240364bc8b53f235 /db/migrations/s2
parent1b00cc812f7a9fdbefd9e05553d694fbca918ed0 (diff)
downloadcoinos-server-e238eab45f1f5b6f3dbf40ddff59b9db804ffb4f.tar.gz
coinos-server-e238eab45f1f5b6f3dbf40ddff59b9db804ffb4f.zip
update migrations
Diffstat (limited to 'db/migrations/s2')
-rw-r--r--db/migrations/s2/user_adjustments.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/db/migrations/s2/user_adjustments.js b/db/migrations/s2/user_adjustments.js
new file mode 100644
index 00000000..010bbc76
--- /dev/null
+++ b/db/migrations/s2/user_adjustments.js
@@ -0,0 +1,67 @@
+
+exports.up = function(knex) {
+ return Promise.all([
+
+ // move security fields to separate t (potentially different access permissions)
+
+ knex.schema.createTable('user_security', function (t) {
+ t.increments('id').unsigned().primary();
+ t.int('user_id').notNull();
+ t.foreign('user_id').references('users.user_id');
+
+ t.boolean('twofa').notNull().defaultTo(false);
+ t.string('pin').notNull();
+ t.string('otp_secret').nullable();
+ t.string('seed').nullable();
+ }),
+
+ knex.raw("INSERT INTO user_security (user_id, twofa, pin, otp_secret, seed) SELECT users.id, twofa, pin, otpsecret, seed FROM users"),
+
+ // move user-customizeable fields to separate t (potentially different access permissions)
+
+ knex.schema.createTable('user_preferences', function (t) {
+ t.increments('id').unsigned().primary();
+ t.int('user_id').notNull();
+ t.foreign('user_id').references('users.user_id');
+
+ t.enum('default_unit', ['SAT', 'BTC', 'CAD']).notNull().defaultTo('SAT');
+ t.enum('default_currency', ['CAD', 'USD']).notNull().defaultTo('CAD');
+ t.enum('default_fiat', ['CAD', 'USD']).notNull().defaultTo('CAD');
+ t.set('show_currencies', ['CAD', 'USD']).notNull().defaultTo('CAD');
+ }),
+
+ knex.raw("INSERT INTO user_preferences (user_id, default_unit, default_currency, default_fiat, show_currencies) SELECT users.id, unit, currency, fiat, currencies FROM users"),
+
+ // remove deprecated fields
+
+ knex.schema.table('users', function (t) {
+ t.string('uuid');
+ t.enum('access', ['Anonymous', 'Member', 'Admin']).defaultTo('Anonymous');
+
+ t.dropColumn('account_id');
+ t.dropColumn('unit');
+ t.dropColumn('fiat');
+ t.dropColumn('currency');
+ t.dropColumn('currencies');
+ })
+ ])
+
+};
+
+exports.down = function(knex) {
+ return Promise.all([
+ knex.schema.table('users', function (t) {
+ t.dropColumn('uuid');
+ t.dropColumn('access');
+
+ t.int('account_id');
+ t.string('unit');
+ t.string('fiat');
+ t.string('currency');
+ t.string('currencies');
+ }),
+
+ knex.schema.dropTable('user_preferences'),
+ knex.schema.dropTable('user_security'),
+ ]);
+};