From 0b79850cc38b0afd0ebbf9d40ace38e081eddaa0 Mon Sep 17 00:00:00 2001 From: Renato Dinhani <101204870+dinhani-cw@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:07:52 -0300 Subject: [PATCH] feat: justfile command to load all csv files in local database (#383) --- justfile | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/justfile b/justfile index c3e1bd7fd..7c045bd5f 100644 --- a/justfile +++ b/justfile @@ -70,10 +70,6 @@ lint: lint-check nightly-version="": @just _lint "{{nightly-version}}" --check "-D warnings" -# Stratus: Compile SQLx queries -sqlx: - SQLX_OFFLINE=true cargo sqlx prepare --database-url postgres://postgres:123@localhost/stratus -- --all-targets - # Stratus: Check for outdated crates outdated: @just _outdated @@ -82,6 +78,24 @@ outdated: update: cargo update stratus +# ------------------------------------------------------------------------------ +# Database tasks +# ------------------------------------------------------------------------------ + +# Database: Compile SQLx queries +db-compile: + SQLX_OFFLINE=true cargo sqlx prepare --database-url postgres://postgres:123@localhost/stratus -- --all-targets +alias sqlx := db-compile + +# Database: Load CSV data produced by importer-offline +db-load-csv: + echo "" > data/psql.txt + echo "truncate transactions;" >> data/psql.txt + echo "truncate logs;" >> data/psql.txt + ls -tr1 data/transactions-*.csv | xargs -I{} printf "\\\\copy transactions from '$(pwd)/%s' delimiter E'\\\\t' csv header;\n" "{}" >> data/psql.txt + ls -tr1 data/logs-*.csv | xargs -I{} printf "\\\\copy logs from '$(pwd)/%s' delimiter E'\\\\t' csv header;\n" "{}" >> data/psql.txt + cat data/psql.txt | pgcli -h localhost -u postgres -d stratus --less-chatty + # ------------------------------------------------------------------------------ # Additional binaries # ------------------------------------------------------------------------------