aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrations
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-07-29 11:50:23 -0700
committerAdam Soltys <[email protected]>2021-07-29 11:50:23 -0700
commit097001f82bcd2da328c1dd0bf61aec879814a1a5 (patch)
tree8cdd3c857daa0ae21004605bf8ab72c3b51269e9 /db/migrations
parent9bb2eb1dbaaddbd92427705bc2d4747cbf5710a6 (diff)
parented68ee893ae7bb3540f0731c3ccf21a26bc6ac1f (diff)
downloadcoinos-server-097001f82bcd2da328c1dd0bf61aec879814a1a5.tar.gz
coinos-server-097001f82bcd2da328c1dd0bf61aec879814a1a5.zip
Merge branch 'dev'
Diffstat (limited to 'db/migrations')
-rw-r--r--db/migrations/20210612181508_init_referrals.js43
-rw-r--r--db/migrations/20210612192804_init_waiting_list.js.js27
-rw-r--r--db/migrations/20210714123455_data_fixes_merge.js5
3 files changed, 44 insertions, 31 deletions
diff --git a/db/migrations/20210612181508_init_referrals.js b/db/migrations/20210612181508_init_referrals.js
index 875d167f..f9107e15 100644
--- a/db/migrations/20210612181508_init_referrals.js
+++ b/db/migrations/20210612181508_init_referrals.js
@@ -1,21 +1,24 @@
exports.up = function(knex) {
- return knex.schema.createTable('referrals', function(t) {
- t.increments('id').unsigned().primary();
- t.integer('user_id').nullable();
- t.foreign('user_id').references('users.id');
-
- t.integer('sponsor_id').notNull();
- t.foreign('sponsor_id').references('users.id');
-
- t.string('token').notNull();
- t.string('expiry').nullable();
- t.enum('status', ['available', 'used', 'expired', 'cancelled']).notNull().defaultTo('available');
-
- t.timestamps();
- })
- };
-
- exports.down = function(knex) {
- return knex.schema.dropTable('referrals');
- };
- \ No newline at end of file
+ return Promise.all([
+ knex.schema.dropTableIfExists('referrals'),
+
+ knex.schema.createTable('referrals', function(t) {
+ t.increments('id').unsigned().primary();
+ t.integer('user_id').nullable();
+ t.foreign('user_id').references('users.id');
+
+ t.integer('sponsor_id').notNull();
+ t.foreign('sponsor_id').references('users.id');
+
+ t.string('token').notNull();
+ t.string('expiry').nullable();
+ t.enum('status', ['available', 'used', 'expired', 'cancelled']).notNull().defaultTo('available');
+
+ 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
index 65d3eb42..67762ff1 100644
--- a/db/migrations/20210612192804_init_waiting_list.js.js
+++ b/db/migrations/20210612192804_init_waiting_list.js.js
@@ -1,17 +1,22 @@
exports.up = function(knex) {
- return knex.schema.createTable('waiting_list', function(t) {
- t.increments('id').unsigned().primary();
+
+ return Promise.all([
+ knex.schema.dropTableIfExists('waiting_list'),
+
+ knex.schema.createTable('waiting_list', function(t) {
+ t.increments('id').unsigned().primary();
+
+ t.string('email').notNull();
+ t.string('phone').notNull();
+ t.enu('status', ['pending', 'activated', 'expired', 'cancelled']).notNull();
- t.string('email').notNull();
- t.string('phone').notNull();
- t.enu('status', ['pending', 'activated', 'expired', 'cancelled']).notNull();
-
- t.integer('user_id').nullable();
- t.foreign('user_id').references('users.id');
- t.text('notes').nullable();
+ t.integer('user_id').nullable();
+ t.foreign('user_id').references('users.id');
+ t.text('notes').nullable();
- t.timestamps();
- })
+ t.timestamps();
+ })
+ ])
}
exports.down = function(knex) {
diff --git a/db/migrations/20210714123455_data_fixes_merge.js b/db/migrations/20210714123455_data_fixes_merge.js
index 70740ce8..eb873554 100644
--- a/db/migrations/20210714123455_data_fixes_merge.js
+++ b/db/migrations/20210714123455_data_fixes_merge.js
@@ -7,6 +7,11 @@ exports.up = function(knex) {
knex.raw("alter table orders drop rate"),
knex.raw("alter table orders add rate double"),
knex.raw("update orders set rate = v1/v2"),
+
+ knex.raw('update accounts left join users on accounts.user_id = users.id set user_id = null where length(username) > 32'),
+ knex.raw('update accounts left join users on accounts.user_id = users.id set user_id = null where users.id is null'),
+ knex.raw('delete from accounts where user_id is null'),
+ knex.raw('delete from users where length(username) > 32')
])
}