diff options
| author | Ran Guin <[email protected]> | 2021-06-16 22:12:16 -0700 |
|---|---|---|
| committer | Ran Guin <[email protected]> | 2021-06-16 22:12:16 -0700 |
| commit | 0f7b673325b60b3cb7cbb9cab1a4580655762500 (patch) | |
| tree | 2ef44958959b458ff423b4345e5817edfbc86eab /db | |
| parent | 83e4676edf8dff5bd6423e6c860f8a93cda17a79 (diff) | |
| download | coinos-server-0f7b673325b60b3cb7cbb9cab1a4580655762500.tar.gz coinos-server-0f7b673325b60b3cb7cbb9cab1a4580655762500.zip | |
initialize migrations dir
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrations/20210612181508_init_referrals.js | 19 | ||||
| -rw-r--r-- | db/migrations/20210612192804_init_waiting_list.js.js | 17 | ||||
| -rw-r--r-- | db/migrations/user_adjustments.js | 53 |
3 files changed, 89 insertions, 0 deletions
diff --git a/db/migrations/20210612181508_init_referrals.js b/db/migrations/20210612181508_init_referrals.js new file mode 100644 index 00000000..260a2c8f --- /dev/null +++ b/db/migrations/20210612181508_init_referrals.js @@ -0,0 +1,19 @@ + +exports.up = function(knex) { + return knex.schema.createTable('referrals', function(t) { + t.increments('id').unsigned().primary(); + + t.string('token').notNull(); + t.string('expiry').nullable(); + t.enum('status', ['pending', 'active', 'expired', 'cancelled')).notNull().defaultTo('pending'); + t.int('sponsor_id').notNull(); + t.foreign('sponsor_id').references('users.user_id') + t.int('user_id').nullable(); + t.foreign('user_id').references('users.user_id') + + t.timestamps(); +}; + +exports.down = function(knex) { + return knex.schema.dropTable('referrals'); +}; diff --git a/db/migrations/20210612192804_init_waiting_list.js.js b/db/migrations/20210612192804_init_waiting_list.js.js new file mode 100644 index 00000000..5322cf6d --- /dev/null +++ b/db/migrations/20210612192804_init_waiting_list.js.js @@ -0,0 +1,17 @@ + +exports.up = function(knex) { + return knex.schema.createTable('waiting_list', function(t) { + t.increments('id').unsigned().primary(); + + t.string('email').nullable(); + t.string('sms').nullable(); + t.enum('status', ['pending', 'contacted', 'registered', 'cancelled')).notNull().defaultTo('pending'); + t.int('user_id').notNull(); + t.foreign('user_id').references('users.user_id'); + + t.timestamps(); +}; + +exports.down = function(knex) { + return knex.schema.dropTable('waiting_list'); +}; diff --git a/db/migrations/user_adjustments.js b/db/migrations/user_adjustments.js new file mode 100644 index 00000000..b4273848 --- /dev/null +++ b/db/migrations/user_adjustments.js @@ -0,0 +1,53 @@ + +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) { + +}; |
