From 2c3855e80df3f3ca7acaf0fc919bca66d495230c Mon Sep 17 00:00:00 2001
From: Joris
Date: Fri, 7 Feb 2025 14:54:22 +0100
Subject: Move migration to migrations folder

---
 src/db/migration/02-payment-category.sql | 44 --------------------------------
 1 file changed, 44 deletions(-)
 delete mode 100644 src/db/migration/02-payment-category.sql

(limited to 'src/db/migration/02-payment-category.sql')

diff --git a/src/db/migration/02-payment-category.sql b/src/db/migration/02-payment-category.sql
deleted file mode 100644
index c1d502f..0000000
--- a/src/db/migration/02-payment-category.sql
+++ /dev/null
@@ -1,44 +0,0 @@
--- Add payment categories with accents from payment with accents
-
-INSERT INTO
-  payment_category (name, category, created_at)
-SELECT
-  DISTINCT lower(payment.name), payment_category.category, datetime('now')
-FROM
-  payment
-INNER JOIN
-  payment_category
-ON
-  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(lower(payment.name), 'é', 'e'), 'è', 'e'), 'à', 'a'), 'û', 'u'), 'â', 'a'), 'ê', 'e'), 'â', 'a'), 'î', 'i'), 'ï', 'i'), 'ô', 'o'), 'ë', 'e') = payment_category.name
-WHERE
-  payment.name
-IN
-  (SELECT DISTINCT payment.name FROM payment WHERE lower(payment.name) NOT IN (SELECT payment_category.name FROM payment_category) AND payment.deleted_at IS NULL);
-
--- Remove unused payment categories
-
-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;
-- 
cgit v1.2.3

