Skip to content

A local-first personal finance app

Remove the unused `migrations` folder (#195)

Jed Fox996f23864821
diff --git a/migrations/.force-copy-windows b/migrations/.force-copy-windows
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/migrations/1548957970627_remove-db-version.sql b/migrations/1548957970627_remove-db-version.sql
deleted file mode 100644
index d93af5d93d..0000000000
--- a/migrations/1548957970627_remove-db-version.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-BEGIN TRANSACTION;
-
-DROP TABLE db_version;
-
-COMMIT;
diff --git a/migrations/1550601598648_payees.sql b/migrations/1550601598648_payees.sql
deleted file mode 100644
index 9cab950471..0000000000
--- a/migrations/1550601598648_payees.sql
+++ /dev/null
@@ -1,23 +0,0 @@
-BEGIN TRANSACTION;
-
-CREATE TABLE payees
- (id TEXT PRIMARY KEY,
- name TEXT,
- category TEXT,
- tombstone INTEGER DEFAULT 0,
- transfer_acct TEXT);
-
-CREATE TABLE payee_rules
- (id TEXT PRIMARY KEY,
- payee_id TEXT,
- type TEXT,
- value TEXT,
- tombstone INTEGER DEFAULT 0);
-
-CREATE INDEX payee_rules_lowercase_index ON payee_rules(LOWER(value));
-
-CREATE TABLE payee_mapping
- (id TEXT PRIMARY KEY,
- targetId TEXT);
-
-COMMIT;
diff --git a/migrations/1555786194328_remove_category_group_unique.sql b/migrations/1555786194328_remove_category_group_unique.sql
deleted file mode 100644
index f97e2d7417..0000000000
--- a/migrations/1555786194328_remove_category_group_unique.sql
+++ /dev/null
@@ -1,25 +0,0 @@
-BEGIN TRANSACTION;
-
-CREATE TEMPORARY TABLE category_groups_tmp
- (id TEXT PRIMARY KEY,
- name TEXT UNIQUE,
- is_income INTEGER DEFAULT 0,
- sort_order REAL,
- tombstone INTEGER DEFAULT 0);
-
-INSERT INTO category_groups_tmp SELECT * FROM category_groups;
-
-DROP TABLE category_groups;
-
-CREATE TABLE category_groups
- (id TEXT PRIMARY KEY,
- name TEXT,
- is_income INTEGER DEFAULT 0,
- sort_order REAL,
- tombstone INTEGER DEFAULT 0);
-
-INSERT INTO category_groups SELECT * FROM category_groups_tmp;
-
-DROP TABLE category_groups_tmp;
-
-COMMIT;
diff --git a/migrations/1561751833510_indexes.sql b/migrations/1561751833510_indexes.sql
deleted file mode 100644
index 733dfa5d2c..0000000000
--- a/migrations/1561751833510_indexes.sql
+++ /dev/null
@@ -1,7 +0,0 @@
-BEGIN TRANSACTION;
-
-CREATE INDEX trans_category_date ON transactions(category, date);
-CREATE INDEX trans_category ON transactions(category);
-CREATE INDEX trans_date ON transactions(date);
-
-COMMIT;
diff --git a/migrations/1567699552727_budget.sql b/migrations/1567699552727_budget.sql
deleted file mode 100644
index 6f0519da62..0000000000
--- a/migrations/1567699552727_budget.sql
+++ /dev/null
@@ -1,38 +0,0 @@
-BEGIN TRANSACTION;
-
-DELETE FROM spreadsheet_cells WHERE
- name NOT LIKE '%!budget\_%' ESCAPE '\' AND
- name NOT LIKE '%!carryover\_%' ESCAPE '\' AND
- name NOT LIKE '%!buffered';
-
-UPDATE OR REPLACE spreadsheet_cells SET name = REPLACE(name, '_', '-');
-
-UPDATE OR REPLACE spreadsheet_cells SET
- name =
- SUBSTR(name, 1, 28) ||
- '-' ||
- SUBSTR(name, 29, 4) ||
- '-' ||
- SUBSTR(name, 33, 4) ||
- '-' ||
- SUBSTR(name, 37, 4) ||
- '-' ||
- SUBSTR(name, 41, 12)
-WHERE name LIKE '%!budget-%' AND LENGTH(name) = 52;
-
-UPDATE OR REPLACE spreadsheet_cells SET
- name =
- SUBSTR(name, 1, 31) ||
- '-' ||
- SUBSTR(name, 32, 4) ||
- '-' ||
- SUBSTR(name, 36, 4) ||
- '-' ||
- SUBSTR(name, 40, 4) ||
- '-' ||
- SUBSTR(name, 44, 12)
-WHERE name LIKE '%!carryover-%' AND LENGTH(name) = 55;
-
-UPDATE spreadsheet_cells SET expr = SUBSTR(expr, 2) WHERE name LIKE '%!carryover-%';
-
-COMMIT;
diff --git a/migrations/1582384163573_cleared.sql b/migrations/1582384163573_cleared.sql
deleted file mode 100644
index 5d6f8ce662..0000000000
--- a/migrations/1582384163573_cleared.sql
+++ /dev/null
@@ -1,6 +0,0 @@
-BEGIN TRANSACTION;
-
-ALTER TABLE transactions ADD COLUMN cleared INTEGER DEFAULT 1;
-ALTER TABLE transactions ADD COLUMN pending INTEGER DEFAULT 0;
-
-COMMIT;
diff --git a/migrations/1597756566448_rules.sql b/migrations/1597756566448_rules.sql
deleted file mode 100644
index 291e2b1beb..0000000000
--- a/migrations/1597756566448_rules.sql
+++ /dev/null
@@ -1,10 +0,0 @@
-BEGIN TRANSACTION;
-
-CREATE TABLE rules
- (id TEXT PRIMARY KEY,
- stage TEXT,
- conditions TEXT,
- actions TEXT,
- tombstone INTEGER DEFAULT 0);
-
-COMMIT;
diff --git a/migrations/1608652596043_parent_field.sql b/migrations/1608652596043_parent_field.sql
deleted file mode 100644
index a5bdf8796e..0000000000
--- a/migrations/1608652596043_parent_field.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-BEGIN TRANSACTION;
-
-ALTER TABLE transactions ADD COLUMN parent_id TEXT;
-
-UPDATE transactions SET
- parent_id = CASE
- WHEN isChild THEN SUBSTR(id, 1, INSTR(id, '/') - 1)
- ELSE NULL
- END;
-
-CREATE INDEX trans_parent_id ON transactions(parent_id);
-
-COMMIT;
diff --git a/migrations/1608652596044_trans_views.sql b/migrations/1608652596044_trans_views.sql
deleted file mode 100644
index 345fc234da..0000000000
--- a/migrations/1608652596044_trans_views.sql
+++ /dev/null
@@ -1,56 +0,0 @@
-BEGIN TRANSACTION;
-
-DROP VIEW IF EXISTS v_transactions_layer2;
-CREATE VIEW v_transactions_layer2 AS
-SELECT
- t.id AS id,
- t.isParent AS is_parent,
- t.isChild AS is_child,
- t.acct AS account,
- CASE WHEN t.isChild = 0 THEN NULL ELSE t.parent_id END AS parent_id,
- CASE WHEN t.isParent = 1 THEN NULL ELSE cm.transferId END AS category,
- pm.targetId AS payee,
- t.imported_description AS imported_payee,
- IFNULL(t.amount, 0) AS amount,
- t.notes AS notes,
- t.date AS date,
- t.financial_id AS imported_id,
- t.error AS error,
- t.starting_balance_flag AS starting_balance_flag,
- t.transferred_id AS transfer_id,
- t.sort_order AS sort_order,
- t.cleared AS cleared,
- t.tombstone AS tombstone
-FROM transactions t
-LEFT JOIN category_mapping cm ON cm.id = t.category
-LEFT JOIN payee_mapping pm ON pm.id = t.description
-WHERE
- t.date IS NOT NULL AND
- t.acct IS NOT NULL;
-
-CREATE INDEX trans_sorted ON transactions(date desc, starting_balance_flag, sort_order desc, id);
-
-DROP VIEW IF EXISTS v_transactions_layer1;
-CREATE VIEW v_transactions_layer1 AS
-SELECT t.* FROM v_transactions_layer2 t
-LEFT JOIN transactions t2 ON (t.is_child = 1 AND t2.id = t.parent_id)
-WHERE IFNULL(t.tombstone, 0) = 0 AND IFNULL(t2.tombstone, 0) = 0;
-
-DROP VIEW IF EXISTS v_transactions;
-CREATE VIEW v_transactions AS
-SELECT t.* FROM v_transactions_layer1 t
-ORDER BY t.date desc, t.starting_balance_flag, t.sort_order desc, t.id;
-
-
-DROP VIEW IF EXISTS v_categories;
-CREATE VIEW v_categories AS
-SELECT
- id,
- name,
- is_income,
- cat_group AS "group",
- sort_order,
- tombstone
-FROM categories;
-
-COMMIT;
diff --git a/migrations/1612625548236_optimize.sql b/migrations/1612625548236_optimize.sql
deleted file mode 100644
index 6e7075ff0e..0000000000
--- a/migrations/1612625548236_optimize.sql
+++ /dev/null
@@ -1,7 +0,0 @@
-BEGIN TRANSACTION;
-
-CREATE INDEX messages_crdt_search ON messages_crdt(dataset, row, column, timestamp);
-
-ANALYZE;
-
-COMMIT;
diff --git a/migrations/1614782639336_trans_views2.sql b/migrations/1614782639336_trans_views2.sql
deleted file mode 100644
index c95a92ca6e..0000000000
--- a/migrations/1614782639336_trans_views2.sql
+++ /dev/null
@@ -1,33 +0,0 @@
-BEGIN TRANSACTION;
-
--- This adds the isChild/parent_id constraint in `where`
-DROP VIEW IF EXISTS v_transactions_layer2;
-CREATE VIEW v_transactions_layer2 AS
-SELECT
- t.id AS id,
- t.isParent AS is_parent,
- t.isChild AS is_child,
- t.acct AS account,
- CASE WHEN t.isChild = 0 THEN NULL ELSE t.parent_id END AS parent_id,
- CASE WHEN t.isParent = 1 THEN NULL ELSE cm.transferId END AS category,
- pm.targetId AS payee,
- t.imported_description AS imported_payee,
- IFNULL(t.amount, 0) AS amount,
- t.notes AS notes,
- t.date AS date,
- t.financial_id AS imported_id,
- t.error AS error,
- t.starting_balance_flag AS starting_balance_flag,
- t.transferred_id AS transfer_id,
- t.sort_order AS sort_order,
- t.cleared AS cleared,
- t.tombstone AS tombstone
-FROM transactions t
-LEFT JOIN category_mapping cm ON cm.id = t.category
-LEFT JOIN payee_mapping pm ON pm.id = t.description
-WHERE
- t.date IS NOT NULL AND
- t.acct IS NOT NULL AND
- (t.isChild = 0 OR t.parent_id IS NOT NULL);
-
-COMMIT;
diff --git a/migrations/1615745967948_meta.sql b/migrations/1615745967948_meta.sql
deleted file mode 100644
index 6bcb3d76f7..0000000000
--- a/migrations/1615745967948_meta.sql
+++ /dev/null
@@ -1,10 +0,0 @@
-BEGIN TRANSACTION;
-
-CREATE TABLE __meta__ (key TEXT PRIMARY KEY, value TEXT);
-
-DROP VIEW IF EXISTS v_transactions_layer2;
-DROP VIEW IF EXISTS v_transactions_layer1;
-DROP VIEW IF EXISTS v_transactions;
-DROP VIEW IF EXISTS v_categories;
-
-COMMIT;
diff --git a/migrations/1616167010796_accounts_order.sql b/migrations/1616167010796_accounts_order.sql
deleted file mode 100644
index 6e259794a1..0000000000
--- a/migrations/1616167010796_accounts_order.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-BEGIN TRANSACTION;
-
-ALTER TABLE accounts ADD COLUMN sort_order REAL;
-
-COMMIT;
diff --git a/migrations/1618975177358_schedules.sql b/migrations/1618975177358_schedules.sql
deleted file mode 100644
index 6c57a5d140..0000000000
--- a/migrations/1618975177358_schedules.sql
+++ /dev/null
@@ -1,28 +0,0 @@
-BEGIN TRANSACTION;
-
-CREATE TABLE schedules
- (id TEXT PRIMARY KEY,
- rule TEXT,
- active INTEGER DEFAULT 0,
- completed INTEGER DEFAULT 0,
- posts_transaction INTEGER DEFAULT 0,
- tombstone INTEGER DEFAULT 0);
-
-CREATE TABLE schedules_next_date
- (id TEXT PRIMARY KEY,
- schedule_id TEXT,
- local_next_date INTEGER,
- local_next_date_ts INTEGER,
- base_next_date INTEGER,
- base_next_date_ts INTEGER);
-
-CREATE TABLE schedules_json_paths
- (schedule_id TEXT PRIMARY KEY,
- payee TEXT,
- account TEXT,
- amount TEXT,
- date TEXT);
-
-ALTER TABLE transactions ADD COLUMN schedule TEXT;
-
-COMMIT;
diff --git a/migrations/1632571489012_remove_cache.js b/migrations/1632571489012_remove_cache.js
deleted file mode 100644
index 7d44a37271..0000000000
--- a/migrations/1632571489012_remove_cache.js
+++ /dev/null
@@ -1,135 +0,0 @@
-export default async function runMigration(db) {
- function getValue(node) {
- return node.expr != null ? node.expr : node.cachedValue;
- }
-
- db.execQuery(`
-CREATE TABLE zero_budget_months
- (id TEXT PRIMARY KEY,
- buffered INTEGER DEFAULT 0);
-
-CREATE TABLE zero_budgets
- (id TEXT PRIMARY KEY,
- month INTEGER,
- category TEXT,
- amount INTEGER DEFAULT 0,
- carryover INTEGER DEFAULT 0);
-
-CREATE TABLE reflect_budgets
- (id TEXT PRIMARY KEY,
- month INTEGER,
- category TEXT,
- amount INTEGER DEFAULT 0,
- carryover INTEGER DEFAULT 0);
-
-CREATE TABLE notes
- (id TEXT PRIMARY KEY,
- note TEXT);
-
-CREATE TABLE kvcache (key TEXT PRIMARY KEY, value TEXT);
-CREATE TABLE kvcache_key (id INTEGER PRIMARY KEY, key REAL);
-`);
-
- // Migrate budget amounts and carryover
- let budget = db.runQuery(
- `SELECT * FROM spreadsheet_cells WHERE name LIKE 'budget%!budget-%'`,
- [],
- true,
- );
- db.transaction(() => {
- budget.map((monthBudget) => {
- let match = monthBudget.name.match(
- /^(budget-report|budget)(\d+)!budget-(.+)$/,
- );
- if (match == null) {
- console.log('Warning: invalid budget month name', monthBudget.name);
- return;
- }
-
- let type = match[1];
- let month = match[2].slice(0, 4) + '-' + match[2].slice(4);
- let dbmonth = parseInt(match[2]);
- let cat = match[3];
-
- let amount = parseInt(getValue(monthBudget));
- if (isNaN(amount)) {
- amount = 0;
- }
-
- let sheetName = monthBudget.name.split('!')[0];
- let carryover = db.runQuery(
- 'SELECT * FROM spreadsheet_cells WHERE name = ?',
- [`${sheetName}!carryover-${cat}`],
- true,
- );
-
- let table = type === 'budget-report' ? 'reflect_budgets' : 'zero_budgets';
- db.runQuery(
- `INSERT INTO ${table} (id, month, category, amount, carryover) VALUES (?, ?, ?, ?, ?)`,
- [
- `${month}-${cat}`,
- dbmonth,
- cat,
- amount,
- carryover.length > 0 && getValue(carryover[0]) === 'true' ? 1 : 0,
- ],
- );
- });
- });
-
- // Migrate buffers
- let buffers = db.runQuery(
- `SELECT * FROM spreadsheet_cells WHERE name LIKE 'budget%!buffered'`,
- [],
- true,
- );
- db.transaction(() => {
- buffers.map((buffer) => {
- let match = buffer.name.match(/^budget(\d+)!buffered$/);
- if (match) {
- let month = match[1].slice(0, 4) + '-' + match[1].slice(4);
- let amount = parseInt(getValue(buffer));
- if (isNaN(amount)) {
- amount = 0;
- }
-
- db.runQuery(
- `INSERT INTO zero_budget_months (id, buffered) VALUES (?, ?)`,
- [month, amount],
- );
- }
- });
- });
-
- // Migrate notes
- let notes = db.runQuery(
- `SELECT * FROM spreadsheet_cells WHERE name LIKE 'notes!%'`,
- [],
- true,
- );
-
- let parseNote = (str) => {
- try {
- let value = JSON.parse(str);
- return value && value !== '' ? value : null;
- } catch (e) {
- return null;
- }
- };
-
- db.transaction(() => {
- notes.forEach((note) => {
- let parsed = parseNote(getValue(note));
- if (parsed) {
- let [, id] = note.name.split('!');
- db.runQuery(`INSERT INTO notes (id, note) VALUES (?, ?)`, [id, parsed]);
- }
- });
- });
-
- db.execQuery(`
- DROP TABLE spreadsheet_cells;
- ANALYZE;
- VACUUM;
- `);
-}
diff --git a/upcoming-release-notes/195.md b/upcoming-release-notes/195.md
new file mode 100644
index 0000000000..00f49526be
--- /dev/null
+++ b/upcoming-release-notes/195.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [j-f1]
+---
+
+Remove the unused `migrations` folder