adding some docs related to how to develop this

This commit is contained in:
2026-10-13 11:28:48 +01:00
parent d4e45858aa
commit 7852f1cf2a
15 changed files with 92 additions and 1188 deletions
+4 -1
View File
@@ -14,7 +14,10 @@ build_release_alpine:
find $(build) -name "*.ttf" ! -name DejaVuSansMono.ttf -delete find $(build) -name "*.ttf" ! -name DejaVuSansMono.ttf -delete
devdb_start: devdb_start:
podman compose start database podman compose up database --force-recreate
devdb_clear:
podman compose down -v database
devdb_status: devdb_status:
podman compose stats database podman compose stats database
+12 -2
View File
@@ -5,11 +5,21 @@ docker exec -i <container-name> \
``` ```
# Start a local development database # Start a local development database
```bash
# Use to clean the volumens and kill the current running database
podman compose down -v database
# Use to recreate database
podman compose up database --force-recreate
# Alternatively, to down the service and clear it
make devdb_clear
# And to start it
make devdb_start
```
# Upload a database # Upload a database
```bash ```bash
# delete the pgsql-data-dev directory contents # Don't forget to devdb_clear the current existing database
# restart the container
psql -h 127.0.0.1 -p 5431 -U expdbuser -d expenses -f ./data.sql psql -h 127.0.0.1 -p 5431 -U expdbuser -d expenses -f ./data.sql
``` ```
@@ -1 +0,0 @@
SELECT * FROM expenses;
@@ -1 +0,0 @@
SELECT * FROM expenses;
@@ -0,0 +1,7 @@
DROP TABLE IF EXISTS public."expensesShares";
DROP TABLE IF EXISTS public."expensesPayments";
DROP TABLE IF EXISTS public.expenses;
DROP TABLE IF EXISTS public.stores;
DROP TABLE IF EXISTS public."expenseTypes";
DROP TABLE IF EXISTS public.users;
DROP TABLE IF EXISTS public.categories;
@@ -0,0 +1,69 @@
-- Create base lookup/independent tables first
CREATE TABLE public.categories (
"CategoryID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"CategoryName" text NOT NULL,
CONSTRAINT categories_pkey PRIMARY KEY ("CategoryID")
);
CREATE TABLE public.users (
"UserID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"UserName" text NOT NULL,
"UserPass" text NOT NULL,
CONSTRAINT users_pkey PRIMARY KEY ("UserID")
);
CREATE TABLE public."expenseTypes" (
"TypeID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"TypeName" text NOT NULL,
CONSTRAINT "expenseTypes_pkey" PRIMARY KEY ("TypeID")
);
CREATE TABLE public.stores (
"StoreID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"StoreName" text NOT NULL,
"NIF" text DEFAULT ''::text,
CONSTRAINT stores_pkey PRIMARY KEY ("StoreID")
);
-- Create main expenses table including the 'qr' column
CREATE TABLE public.expenses (
"ExpID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Description" text NOT NULL,
"Value" numeric(12,2) DEFAULT 0 NOT NULL,
"StoreID" integer DEFAULT 0 NOT NULL,
"CategoryID" integer DEFAULT 0 NOT NULL,
"OwnerUserID" integer DEFAULT 0 NOT NULL,
"TypeID" integer DEFAULT 0 NOT NULL,
"ExpDate" timestamp without time zone NOT NULL,
"CreationDate" timestamp without time zone NOT NULL,
"PaidOff" boolean DEFAULT false,
"SharesEven" boolean DEFAULT false,
qr text DEFAULT ''::text,
CONSTRAINT expenses_pkey PRIMARY KEY ("ExpID"),
CONSTRAINT "expenses_StoreID_fkey" FOREIGN KEY ("StoreID") REFERENCES public.stores("StoreID") ON DELETE RESTRICT,
CONSTRAINT "expenses_CategoryID_fkey" FOREIGN KEY ("CategoryID") REFERENCES public.categories("CategoryID") ON DELETE RESTRICT,
CONSTRAINT "expenses_OwnerUserID_fkey" FOREIGN KEY ("OwnerUserID") REFERENCES public.users("UserID") ON DELETE RESTRICT,
CONSTRAINT "expenses_TypeID_fkey" FOREIGN KEY ("TypeID") REFERENCES public."expenseTypes"("TypeID") ON DELETE RESTRICT
);
-- Create dependent relationship tables
CREATE TABLE public."expensesPayments" (
"ExpPaymID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"ExpID" integer NOT NULL,
"UserID" integer NOT NULL,
"Payed" numeric(12,2) DEFAULT 0 NOT NULL,
CONSTRAINT "expensesPayments_pkey" PRIMARY KEY ("ExpPaymID"),
CONSTRAINT "expensesPayments_ExpID_fkey" FOREIGN KEY ("ExpID") REFERENCES public.expenses("ExpID") ON DELETE RESTRICT,
CONSTRAINT "expensesPayments_UserID_fkey" FOREIGN KEY ("UserID") REFERENCES public.users("UserID") ON DELETE RESTRICT
);
CREATE TABLE public."expensesShares" (
"ExpShareID" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"ExpID" integer NOT NULL,
"UserID" integer NOT NULL,
"Share" numeric(6,2) DEFAULT 0.5 NOT NULL,
"Calculated" numeric(12,2) DEFAULT 0 NOT NULL,
CONSTRAINT "expensesShares_pkey" PRIMARY KEY ("ExpShareID"),
CONSTRAINT "expensesShares_ExpID_fkey" FOREIGN KEY ("ExpID") REFERENCES public.expenses("ExpID") ON DELETE RESTRICT,
CONSTRAINT "expensesShares_UserID_fkey" FOREIGN KEY ("UserID") REFERENCES public.users("UserID") ON DELETE RESTRICT
);
@@ -1,4 +0,0 @@
--- 0001_qr_feature.down.sql
ALTER TABLE expenses DROP COLUMN "qr";
ALTER TABLE stores DROP COLUMN "NIF";
@@ -1,4 +0,0 @@
--- 0001_qr_feature.up.sql
ALTER TABLE expenses ADD qr TEXT DEFAULT '';
ALTER TABLE stores ADD "NIF" TEXT DEFAULT '';
-4
View File
@@ -1,4 +0,0 @@
schema.sql
.env
pgsql-data-dev/
pgSocket/
-33
View File
@@ -1,33 +0,0 @@
FROM dir.esilva.org/esilva/esilva-alpine:v1.0.0
# Required ENV variables for pg
ENV LANG=en_GB.utf8
# Downloads the required packages for the webserver
RUN apk --no-cache add su-exec zsh \
postgresql16 \
&& rm -rf /tmp/*
# Directory for the pg socket
RUN mkdir -p /run/postgresql && \
chown -R $UNAME:$UNAME /run/postgresql
RUN mkdir -p /var/lib/postgresql/data && \
chown -R $UNAME:$UNAME /var/lib/postgresql
COPY ./schema.sql /schema.sql
# Expose the pgsql port
EXPOSE 5431
# Copies the start script
COPY ./start.sh /start.sh
COPY ./healthcheck.sh /healthcheck.sh
USER $UNAME
STOPSIGNAL SIGTERM
ENTRYPOINT [ "/start.sh" ]
-38
View File
@@ -1,38 +0,0 @@
include ../vars.mk
service = expenses-pgdb
image = $(service)
container = $(image)-container
.PHONY: clean attach-test test
clean:
@docker image inspect $(image) > /dev/null 2>&1 && \
docker image rm $(image) || true
build:
cp ../expenses/repo/pgdb/schema.sql .
docker buildx build \
-t $(registry)/$(repo)/expensesdb:$(tag) .
push_image:
docker push $(registry)/$(repo)/expensesdb:$(tag)
attach:
docker exec -it $(container) zsh
attach-test:
docker exec -it $(container)-dev zsh
remove-dev-container:
docker container rm $(container)-dev --force > /dev/null 2>&1
test: remove-dev-container
docker run -p 5431:5432 \
--name $(container)-dev \
--env-file .env \
-v ./pgsql-data-dev/:/var/lib/postgresql/data/ \
-v ./pgSocket:/run/postgresql \
-it $(registry)/$(repo)/expensesdb:v0.0.91-alpha
build_image:
make -C ./
-9
View File
@@ -1,9 +0,0 @@
# README
Requires a `.env` file with the following fields:
```
PGDATA=<path-to-dir-where-pg-data-lives>
ExpDB_USER=<user-for-expenses-db>
ExpDB_PASS=<pass-for-expenses-db>
ExpDB_NAME=<name-for-expenses-db>
```
File diff suppressed because it is too large Load Diff
-4
View File
@@ -1,4 +0,0 @@
#!/bin/bash
set -e
pg_isready -U "$ExpDB_USER" -d "$ExpDB_NAME"
-44
View File
@@ -1,44 +0,0 @@
#!/bin/sh
set -e
if [ -z "$(ls -A "$PGDATA")" ]; then
echo "Creating database with:"
echo "DIR: $PGDATA"
echo "USER: $ExpDB_USER"
echo "PASS: $ExpDB_PASS"
echo "NAME: $ExpDB_NAME"
# Initiate PG data directory
initdb \
--locale=C.UTF-8 \
--encoding=UTF8 \
-D "$PGDATA" \
--data-checksums \
--username="$UNAME"
# Set PG to listen on all addresses
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# Start PG to add the NC DB
pg_ctl -D "$PGDATA" \
-o "-c listen_addresses=''" \
-w start
# Create the NC database
createUser="CREATE USER $ExpDB_USER WITH PASSWORD '$ExpDB_PASS';"
createDB="CREATE DATABASE $ExpDB_NAME TEMPLATE template0 ENCODING 'UNICODE';"
alterDB="ALTER DATABASE $ExpDB_NAME OWNER TO $ExpDB_USER;"
grantPriv="GRANT ALL PRIVILEGES ON DATABASE $ExpDB_NAME TO $ExpDB_USER;"
psql -d postgres -c "${createUser}"
psql -d postgres -c "${createDB}"
psql -d postgres -c "${alterDB}"
psql -d postgres -c "${grantPriv}"
# Execute the initial schema
psql -U "$ExpDB_USER" -d "$ExpDB_NAME" -a -f /schema.sql
pg_ctl -D "$PGDATA" -m fast -w stop
{ echo; echo "host all all 0.0.0.0/0 md5"; } >> "$PGDATA"/pg_hba.conf
fi
postgres "$@"