aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRan Guin <[email protected]>2021-07-19 15:46:29 -0700
committerRan Guin <[email protected]>2021-07-19 15:46:29 -0700
commitf79558e1111b963b4f510c224b3ced7cadc16142 (patch)
tree022d8467b4eeb12d8e87e1d9985d26ad0ce70149
parent5003fe8f50df1fec1c75134fb6c80040ef29f6f2 (diff)
downloadcoinos-server-f79558e1111b963b4f510c224b3ced7cadc16142.tar.gz
coinos-server-f79558e1111b963b4f510c224b3ced7cadc16142.zip
add data fixes
-rw-r--r--db/migrations/20210714123455_data_fixes_merge.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/db/migrations/20210714123455_data_fixes_merge.js b/db/migrations/20210714123455_data_fixes_merge.js
new file mode 100644
index 00000000..0bbc1890
--- /dev/null
+++ b/db/migrations/20210714123455_data_fixes_merge.js
@@ -0,0 +1,22 @@
+exports.up = function(knex) {
+ return Promise.all([
+
+ // check with :
+ knex.raw("update invoices as m left join accounts on accounts.id=account_id left join users on users.id = m.user_id set m.account_id=users.account_id where m.account_id is not null and accounts.id is null"),
+
+ knex.raw("update users left join accounts on users.account_id=accounts.id left join accounts as n on n.user_id = users.id set users.account_id=n.id where account_id is not null and accounts.id is null"),
+
+ knex.raw("update payments as m left join accounts on accounts.id=account_id left join users on users.id = m.user_id set m.account_id=users.account_id where m.account_id is not null and accounts.id is null"),
+
+ knex.raw("update orders as m left join accounts on accounts.id=m.a1_id left join users on users.id = m.user_id set m.a1_id=users.account_id where m.a1_id is not null and accounts.id is null"),
+
+ knex.raw("update orders as m left join accounts on accounts.id=m.a2_id left join users on users.id = m.user_id set m.a2_id=users.account_id where m.a2_id is not null and accounts.id is null"),
+
+ ])
+}
+
+exports.down = function(knex) {
+ return Promise.all([
+
+ ])
+} \ No newline at end of file