aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorRan Guin <[email protected]>2021-07-19 15:28:20 -0700
committerRan Guin <[email protected]>2021-07-19 15:28:20 -0700
commit8f7685f63fdcc817cc4aab3970d81ea93f04341f (patch)
treea9b2222e31447963de0648d079778adc95dd67a1 /db
parentb0840c3554be45ae7dad6999395eb78e44975923 (diff)
downloadcoinos-server-8f7685f63fdcc817cc4aab3970d81ea93f04341f.tar.gz
coinos-server-8f7685f63fdcc817cc4aab3970d81ea93f04341f.zip
update migrations
Diffstat (limited to 'db')
l---------db/knexfile.js2
-rw-r--r--db/migrations/20210714123455_data_fixes_merge.js22
-rw-r--r--db/migrations/20210714123456_add_fks_merge.js9
3 files changed, 32 insertions, 1 deletions
diff --git a/db/knexfile.js b/db/knexfile.js
index 10bb1d03..3cf75ae7 120000
--- a/db/knexfile.js
+++ b/db/knexfile.js
@@ -1 +1 @@
-../config/knexfile.js \ No newline at end of file
+./../config/knexfile.js \ No newline at end of file
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
diff --git a/db/migrations/20210714123456_add_fks_merge.js b/db/migrations/20210714123456_add_fks_merge.js
index a13ea5c9..ecdd08f3 100644
--- a/db/migrations/20210714123456_add_fks_merge.js
+++ b/db/migrations/20210714123456_add_fks_merge.js
@@ -1,26 +1,35 @@
exports.up = function(knex) {
return Promise.all([
+ // alter table invoices add foreign key (user_id) references users (id);
+ // alter table invoices add foreign key (account_id) references accounts (id);
knex.schema.alterTable("invoices", function(t) {
t.foreign('user_id').references('users.id')
t.foreign('account_id').references('accounts.id')
}),
+ // alter table payments add foreign key (user_id) references users (id);
+ // alter table payments add foreign key (account_id) references accounts (id);
knex.schema.alterTable("payments", function(t) {
t.foreign('user_id').references('users.id')
t.foreign('account_id').references('accounts.id')
}),
+ // alter table orders add foreign key (user_id) references users (id);
+ // alter table orders add foreign key (a1_id) references accounts (id);
+ // alter table orders add foreign key (a2_id) references accounts (id);
knex.schema.alterTable("orders", function(t) {
t.foreign('user_id').references('users.id')
t.foreign('a1_id').references('accounts.id')
t.foreign('a2_id').references('accounts.id')
}),
+ // alter table deposits add foreign key (user_id) references users (id)
knex.schema.alterTable("deposits", function(t) {
t.foreign('user_id').references('users.id')
}),
+ // alter table withdrawals add foreign key (user_id) references users (id)
knex.schema.alterTable("withdrawals", function(t) {
t.foreign('user_id').references('users.id')
}),