Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The relations are defined in [create-relations.sql](sqlite_export_for_ynab/ddl/c

1. Some objects are pulled out into their own tables so they can be more cleanly modeled in SQLite (ex: subtransactions, loan account periodic values).
1. Foreign keys are added as needed (ex: plan ID, transaction ID) so data across plans remains separate.
1. Two new views called `flat_transactions` and `scheduled_flat_transactions`. These allow you to query split and non-split transactions easily, without needing to also query `subtransactions` and `scheduled_subtransactions` respectively. They also filter out deleted transactions/subtransactions and project payee/category fields to make querying more ergonomic.
1. Two new views called `flat_transactions` and `scheduled_flat_transactions`. These allow you to query split and non-split transactions easily, without needing to also query `subtransactions` and `scheduled_subtransactions` respectively. They also filter out deleted/unapproved transactions/subtransactions and project payee/category fields to make querying more ergonomic.

## Querying

Expand Down Expand Up @@ -116,6 +116,7 @@ WITH used_payees AS (
FROM transactions
WHERE
TRUE
AND approved
AND payee_id IS NOT NULL
AND NOT deleted
UNION
Expand Down
2 changes: 1 addition & 1 deletion sqlite_export_for_ynab/ddl/create-relations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ SELECT
, t.plan_id
, t.account_id
, t.account_name
, t.approved
, t.cleared
, t."date"
, t.debt_transaction_type
Expand Down Expand Up @@ -227,6 +226,7 @@ INNER JOIN categories AS c
)
WHERE
TRUE
AND t.approved
AND NOT COALESCE(st.deleted, t.deleted)
;

Expand Down
3 changes: 3 additions & 0 deletions testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"amount": -10000,
"amount_formatted": "$10.00",
"amount_currency": 10.0,
"approved": True,
"category_id": CATEGORY_ID_3,
"category_name": CATEGORY_NAME_3,
"deleted": False,
Expand Down Expand Up @@ -239,6 +240,7 @@
"amount": -15000,
"amount_formatted": "$15.00",
"amount_currency": 15.0,
"approved": True,
"category_id": CATEGORY_ID_2,
"category_name": CATEGORY_NAME_2,
"deleted": True,
Expand All @@ -250,6 +252,7 @@
"amount": -19000,
"amount_formatted": "$19.00",
"amount_currency": 19.0,
"approved": False,
"category_id": CATEGORY_ID_4,
"category_name": CATEGORY_NAME_4,
"deleted": False,
Expand Down
16 changes: 3 additions & 13 deletions tests/_main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def test_insert_transactions(cur):
"amount": -10000,
"amount_formatted": "$10.00",
"amount_currency": 10.0,
"approved": 1,
"category_id": CATEGORY_ID_3,
"category_name": CATEGORY_NAME_3,
"deleted": False,
Expand All @@ -325,6 +326,7 @@ def test_insert_transactions(cur):
"amount": -15000,
"amount_formatted": "$15.00",
"amount_currency": 15.0,
"approved": 1,
"category_id": CATEGORY_ID_2,
"category_name": CATEGORY_NAME_2,
"deleted": True,
Expand All @@ -336,6 +338,7 @@ def test_insert_transactions(cur):
"amount": -19000,
"amount_formatted": "$19.00",
"amount_currency": 19.0,
"approved": 0,
"category_id": CATEGORY_ID_4,
"category_name": CATEGORY_NAME_4,
"deleted": False,
Expand Down Expand Up @@ -370,19 +373,6 @@ def test_insert_transactions(cur):

cur.execute("SELECT * FROM flat_transactions ORDER BY amount")
assert [strip_nones(d) for d in cur.fetchall()] == [
{
"transaction_id": TRANSACTION_ID_3,
"plan_id": PLAN_ID_1,
"date": "2024-03-01",
"id": TRANSACTION_ID_3,
"amount": -19000,
"amount_formatted": "$19.00",
"amount_currency": 19.0,
"category_id": CATEGORY_ID_4,
"category_name": CATEGORY_NAME_4,
"category_group_id": CATEGORY_GROUP_ID_2,
"category_group_name": CATEGORY_GROUP_NAME_2,
},
{
"transaction_id": TRANSACTION_ID_1,
"subtransaction_id": SUBTRANSACTION_ID_1,
Expand Down
Loading