Skip to content
Snippets Groups Projects
Unverified Commit bf05b759 authored by Jed Fox's avatar Jed Fox Committed by GitHub
Browse files

Remove duplicate migration and default-db.sqlite files (#870)

These files will be automatically recreated by `yarn build:api`,
`yarn build:browser`, and `yarn start:browser`, so we don’t need
them in the repo.
parent 835c1a54
No related branches found
No related tags found
No related merge requests found
Showing
with 13 additions and 416 deletions
File deleted
BEGIN TRANSACTION;
DROP TABLE db_version;
COMMIT;
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;
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;
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;
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;
BEGIN TRANSACTION;
ALTER TABLE transactions ADD COLUMN cleared INTEGER DEFAULT 1;
ALTER TABLE transactions ADD COLUMN pending INTEGER DEFAULT 0;
COMMIT;
BEGIN TRANSACTION;
CREATE TABLE rules
(id TEXT PRIMARY KEY,
stage TEXT,
conditions TEXT,
actions TEXT,
tombstone INTEGER DEFAULT 0);
COMMIT;
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;
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;
BEGIN TRANSACTION;
CREATE INDEX messages_crdt_search ON messages_crdt(dataset, row, column, timestamp);
ANALYZE;
COMMIT;
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;
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;
BEGIN TRANSACTION;
ALTER TABLE accounts ADD COLUMN sort_order REAL;
COMMIT;
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;
export default async function runMigration(db, uuid) {
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.forEach(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.forEach(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;
`);
}
BEGIN TRANSACTION;
ALTER TABLE rules ADD COLUMN conditions_op TEXT DEFAULT 'and';
COMMIT;
......@@ -4,7 +4,13 @@ cd `dirname "$0"`
ROOT=`pwd -P`
WEBPACK_ARGS=""
"$ROOT"/copy-migrations
DATA_DIR="$ROOT"/../../desktop-client/public/data
mkdir -p "$DATA_DIR"
"$ROOT"/copy-migrations "$DATA_DIR"
cd "$DATA_DIR"
find * -type f | sort > ../data-file-index.txt
cd "$ROOT"
OUTPUT_HASH="[hash]"
if [ $NODE_ENV == 'development' ]; then
......
#!/bin/sh -e
dest_dir=$(realpath "$1")
ROOT=`dirname "$0"`
cd "$ROOT"
# Copy them to the browser version
$(
cd ../../desktop-client/public;
rm -rf ./data;
mkdir ./data;
cp -r ../../loot-core/migrations ./data;
cp ../../loot-core/default-db.sqlite ./data;
cd data && find * -type f | sort > ../data-file-index.txt;
)
rm -rf "$dest_dir"/migrations
mkdir -p "$dest_dir"/migrations
cp ../migrations/* "$dest_dir"/migrations/
cp ../default-db.sqlite "$dest_dir"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment