aboutsummaryrefslogtreecommitdiff
path: root/server/migrations/2.sql
diff options
context:
space:
mode:
authorJoris2019-11-17 18:08:28 +0100
committerJoris2019-11-17 18:08:28 +0100
commitc0ea63f8c1a8c7123b78798cec99726b113fb1f3 (patch)
tree0b92f7e0c125c067a5f1ccafe6a1f04f1edfae86 /server/migrations/2.sql
parent4dc84dbda7ba3ea60d13e6f81eeec556974b7c72 (diff)
downloadbudget-c0ea63f8c1a8c7123b78798cec99726b113fb1f3.tar.gz
budget-c0ea63f8c1a8c7123b78798cec99726b113fb1f3.tar.bz2
budget-c0ea63f8c1a8c7123b78798cec99726b113fb1f3.zip
Optimize and refactor payments
Diffstat (limited to 'server/migrations/2.sql')
-rw-r--r--server/migrations/2.sql21
1 files changed, 21 insertions, 0 deletions
diff --git a/server/migrations/2.sql b/server/migrations/2.sql
index 1c829ec..efed046 100644
--- a/server/migrations/2.sql
+++ b/server/migrations/2.sql
@@ -21,3 +21,24 @@ DELETE FROM
payment_category
WHERE
name NOT IN (SELECT DISTINCT lower(name) FROM payment);
+
+-- Add category id to payment table
+
+PRAGMA foreign_keys = 0;
+
+ALTER TABLE payment ADD COLUMN "category" INTEGER NOT NULL REFERENCES "category" DEFAULT -1;
+
+PRAGMA foreign_keys = 1;
+
+UPDATE
+ payment
+SET
+ category = (SELECT category FROM payment_category WHERE payment_category.name = LOWER(payment.name))
+WHERE
+ EXISTS (SELECT category FROM payment_category WHERE payment_category.name = LOWER(payment.name))
+
+DELETE FROM payment WHERE category = -1;
+
+-- Remove
+
+DROP TABLE payment_category