summaryrefslogtreecommitdiffstats
path: root/modules/tozt/files/metabase
blob: 96dee54ddeb431394ccd3978735588dbfd00be3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
set -eu

tmp="$(mktemp --tmpdir -d metabase-cron.XXXXXXXXXX)"

cleanup() {
    if perl -e'exit 1 unless $ARGV[0] =~ m{^/tmp/metabase-cron.*$}' "$tmp"; then
        rm -rf "$tmp"
    fi
}
trap cleanup EXIT

chown doy:doy "$tmp"
cd "$tmp"
su doy -c /home/doy/.cargo/bin/ynab-export

ynab-export schema | psql -U metabase ynab

psql -U metabase ynab -c 'COPY accounts FROM STDIN' < accounts.tsv
psql -U metabase ynab -c 'COPY category_groups FROM STDIN' < category_groups.tsv
psql -U metabase ynab -c 'COPY categories FROM STDIN' < categories.tsv
psql -U metabase ynab -c 'COPY months FROM STDIN' < months.tsv
psql -U metabase ynab -c 'COPY categories_by_month FROM STDIN' < categories_by_month.tsv
psql -U metabase ynab -c 'COPY payees FROM STDIN' < payees.tsv
psql -U metabase ynab -c 'COPY transactions FROM STDIN' < transactions.tsv
psql -U metabase ynab -c 'COPY subtransactions FROM STDIN' < subtransactions.tsv
psql -U metabase ynab -c 'COPY scheduled_transactions FROM STDIN' < scheduled_transactions.tsv
psql -U metabase ynab -c 'COPY scheduled_subtransactions FROM STDIN' < scheduled_subtransactions.tsv

seq 1000000 | psql -U metabase ynab -c 'COPY ints FROM STDIN'

# shellcheck disable=SC2046
su doy /home/doy/coding/investments-sheet-export/bin/load $(cat /home/doy/.config/google/investments-sheet) > /dev/null