summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-08-27 01:55:59 -0400
committerJesse Luehrs <doy@tozt.net>2019-08-27 01:59:08 -0400
commitc7815088622d39b8792c072366c72836fce3a932 (patch)
treeeeac30038c3ced09a127415424c36658d51f3de1
parentea9d3dea257b4f1c753b3a6d6c3bb1f20efc0401 (diff)
downloadmetabase-utils-c7815088622d39b8792c072366c72836fce3a932.tar.gz
metabase-utils-c7815088622d39b8792c072366c72836fce3a932.zip
make load script handle the whole database
-rwxr-xr-xbin/load26
-rw-r--r--data/investments-sheet-schema.sql (renamed from data/schema.sql)2
-rw-r--r--src/bin/investments-sheet-export.rs (renamed from src/main.rs)3
3 files changed, 21 insertions, 10 deletions
diff --git a/bin/load b/bin/load
index 1f9fa72..6fa7777 100755
--- a/bin/load
+++ b/bin/load
@@ -1,14 +1,24 @@
#!/bin/sh
set -eu
-cd "$(dirname "$0")/.." || exit 1
+/home/doy/.cargo/bin/ynab-export
+/home/doy/.cargo/bin/ynab-export schema | psql -U metabase money
-cargo build
-cd data || exit 1
+seq 1000000 | psql -U metabase money -c 'COPY ints FROM STDIN'
-rm -f ./*.tsv || true
-../target/debug/investments-sheet-export "$@"
+psql -U metabase money -c 'COPY accounts FROM STDIN' < accounts.tsv
+psql -U metabase money -c 'COPY category_groups FROM STDIN' < category_groups.tsv
+psql -U metabase money -c 'COPY categories FROM STDIN' < categories.tsv
+psql -U metabase money -c 'COPY months FROM STDIN' < months.tsv
+psql -U metabase money -c 'COPY categories_by_month FROM STDIN' < categories_by_month.tsv
+psql -U metabase money -c 'COPY payees FROM STDIN' < payees.tsv
+psql -U metabase money -c 'COPY transactions FROM STDIN' < transactions.tsv
+psql -U metabase money -c 'COPY subtransactions FROM STDIN' < subtransactions.tsv
+psql -U metabase money -c 'COPY scheduled_transactions FROM STDIN' < scheduled_transactions.tsv
+psql -U metabase money -c 'COPY scheduled_subtransactions FROM STDIN' < scheduled_subtransactions.tsv
-psql -U metabase investments < schema.sql
-psql -U metabase investments -c 'COPY categories FROM STDIN' < categories.tsv
-psql -U metabase investments -c 'COPY holdings FROM STDIN' < holdings.tsv
+cargo run --manifest-path "$(dirname "$0")/../Cargo.toml" --bin investments-sheet-export "$@"
+psql -U metabase money < "$(dirname "$0")/../data/investments-sheet-schema.sql"
+
+psql -U metabase money -c 'COPY investment_categories FROM STDIN' < investment_categories.tsv
+psql -U metabase money -c 'COPY holdings FROM STDIN' < holdings.tsv
diff --git a/data/schema.sql b/data/investments-sheet-schema.sql
index 2c859ef..d538ec6 100644
--- a/data/schema.sql
+++ b/data/investments-sheet-schema.sql
@@ -1,7 +1,7 @@
DROP TABLE IF EXISTS holdings;
DROP TABLE IF EXISTS categories;
-CREATE TABLE categories (
+CREATE TABLE investment_categories (
name text PRIMARY KEY,
target_allocation integer
);
diff --git a/src/main.rs b/src/bin/investments-sheet-export.rs
index d594413..0444934 100644
--- a/src/main.rs
+++ b/src/bin/investments-sheet-export.rs
@@ -38,7 +38,8 @@ fn main() {
.map(|u| Sheet::new(&reqwest::get(&u).unwrap().text().unwrap()))
.collect();
- let mut file = std::fs::File::create("categories.tsv").unwrap();
+ let mut file =
+ std::fs::File::create("investment_categories.tsv").unwrap();
for row in sheets[0].rows().skip(1) {
if row[0] == "" {
break;