schema.sql

This commit is contained in:
xenia 2023-08-09 22:41:11 +02:00
parent 27b8036ff6
commit f1a25c6d3f
2 changed files with 20 additions and 30 deletions

View File

@ -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" "!"

11
schema.sql Normal file
View File

@ -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
);