aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrations/20210714123455_data_fixes_merge.js
blob: eb87355493de2ae05cbd29973e40828e97952b3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
exports.up = function(knex) {
  return Promise.all([
    knex.raw("delete from invoices where invoices.account_id not in (select id from accounts)"),
    knex.raw("delete from orders where orders.a1_id not in (select id from accounts) or orders.a2_id not in (select id from accounts)"),
    knex.raw("update users set account_id = 10427 where id = 6262 and account_id = 10428"),
    knex.raw("delete from payments where account_id not in (select id from accounts)"),
    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')
  ])
}

exports.down = function(knex) {
  return Promise.all([

  ])
}