diff --git a/build/devShellHook.sh b/build/devShellHook.sh index e011f4f..96f0042 100644 --- a/build/devShellHook.sh +++ b/build/devShellHook.sh @@ -1,5 +1,9 @@ set -e +export PGPORT=2137 +export PGDATABASE=matabas +export PGUSER=matabasare + log() { printf "\e[1m\e[38;5;87m==>\e[0m\e[1m %s%s\e[0m\n" "$1" "${2:-.}" } @@ -12,7 +16,7 @@ exitHook() { log "Letar efter existerande brevekorresmapp" [ -d ./matabas-db ] || { log "Finns ej, skapar brevekorresmapp (./matabas-db)" - pg_ctl initdb --pgdata=./matabas-db + pg_ctl initdb --pgdata=./matabas-db -o "--username=$PGUSER" } [ -f matabas-db/matabas.log ] && { @@ -22,39 +26,14 @@ log "Letar efter existerande brevekorresmapp" } log "Startar brevekorren" -pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -k /tmp" +pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p $PGPORT -k /tmp" trap exitHook EXIT log "Skapar matabas" -createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över" +createdb -p "$PGPORT" matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över" -log "Försvensknar miljön" -_cargo() { - cuh="$1" - shift - case "$cuh" in - kör|spring) - cargo run "$@" - ;; - ny) - cargo new "$@" - ;; - pröva) - cargo test "$@" - ;; - bygg) - cargo build "$@" - ;; - enna) - cargo init "$@" - ;; - *) - echo "vafan gö du" - ;; - esac -} -alias 'last=_cargo' -alias cargo=exit +log "Ställer in schema.sql" +psql -p "$PGPORT" "$PBDATABASE" < schema.sql log "Redo" "!" diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..6a7feba --- /dev/null +++ b/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS ingredient + ( product_id INTEGER NOT NULL PRIMARY KEY -- https://handlaprivatkund.ica.se/stores/1004247/api/v4/products/bop?retailerProductId=... + ); + +CREATE TABLE IF NOT EXISTS ingredient_data + ( product_id INTEGER REFERENCES ingredient(product_id) + , name TEXT NOT NULL + , cost_per_kg REAL NOT NULL + , cost_per_unit REAL NOT NULL + , image BYTEA NOT NULL + );