diff --git a/Makefile b/Makefile index b3d8e38..78543bf 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ # -include: silently skip if .env doesn't exist (e.g. fresh clone before 'cp .env.example .env') -include .env +-include backend/.env export .PHONY: dev-db migrate-up migrate-down run-backend run-frontend test fmt diff --git a/README.md b/README.md index 875782c..f5220b9 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,43 @@ A full-stack fruit-variety database (Go + Vue 3). cp .env.example .env # set credentials cp backend/.env.example backend/.env # set JWT_SECRET and USERS_FILE cp users.env.example users.env # create user file (see below) -./scripts/create_user.sh admin secret >> users.env # add a user +./scripts/create_user.sh admin secret >> users.env # add a user (restart backend to reload) make dev-db # start Postgres (waits until healthy) make migrate-up # apply schema migrations make run-backend # Echo API on :3000 make run-frontend # Vite dev server on :5000 ``` +## Importing Legacy Data + +Prerequisites: Postgres running and migrated, `psycopg2` installed (`pip install psycopg2-binary`), `03-data/` present at repo root. + +Scripts must be run in order — publications depend on fruits being present. + +### 1. Import fruits + +```bash +DATABASE_URL=postgres://osdb:osdb@localhost:5432/osdb?sslmode=disable python3 scripts/import_fruits.py +``` + +Imports fruits, synonyms, and fruit images from `03-data/obstsorten.xml`. Idempotent: upserts by `osdb_number`. + +### 2. Import publications + +```bash +DATABASE_URL=postgres://osdb:osdb@localhost:5432/osdb?sslmode=disable python3 scripts/import_publications.py +``` + +Imports publications from `03-data/osws.xml`. For each publication: upserts the row, loads cover image, links fruits, and imports PDFs and fruit images. Idempotent: clears and re-inserts linked data on re-run. + +## Managing Users + +Add a user and restart the backend to reload: + +```bash +./scripts/create_user.sh >> users.env +``` + ## Testing ```bash diff --git a/backend/.env.example b/backend/.env.example index 196a9f7..a3dbcd4 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1,4 +1,4 @@ -DATABASE_URL=postgres://osdb:osdb@localhost:5432/osdb +DATABASE_URL=postgres://osdb:osdb@localhost:5432/osdb?sslmode=disable PORT=3000 JWT_SECRET=change-me-use-a-long-random-string USERS_FILE=../users.env diff --git a/scripts/README_import.md b/scripts/README_import.md deleted file mode 100644 index e780aaf..0000000 --- a/scripts/README_import.md +++ /dev/null @@ -1,37 +0,0 @@ -# Import Scripts - -## Prerequisites - -- Postgres running and migrated (`make migrate-up`) -- `DATABASE_URL` set, e.g.: - ``` - export DATABASE_URL=postgres://user:pass@localhost:5432/osdb - ``` -- `03-data/` directory present at repo root -- `psycopg2` installed (`pip install psycopg2-binary`) - ---- - -## Run Order - -Scripts must be run in order — publications import depends on fruits being present. - -### 1. Import fruits - -```bash -DATABASE_URL=... python3 scripts/import_fruits.py -``` - -Imports fruits, synonyms, and fruit images from `03-data/obstsorten.xml`. -Idempotent: upserts fruits by `osdb_number`. - -### 2. Import publications - -```bash -DATABASE_URL=... python3 scripts/import_publications.py -``` - -Imports publications from `03-data/osws.xml` (only `` elements with `=1`). -For each publication: upserts the row, loads cover image, links fruits found by -filesystem scan of `03-data/osdb/{pubId}/`, and imports PDFs and fruit images. -Idempotent: clears and re-inserts linked data on re-run. diff --git a/scripts/import_fruits.py b/scripts/import_fruits.py index 5ae7b81..0ef1932 100644 --- a/scripts/import_fruits.py +++ b/scripts/import_fruits.py @@ -51,7 +51,10 @@ TYP_MAP = { IMAGE_DIRS = [ ("einzelfruechte", "fruit"), + ("osdb/fru", "fruit"), + ("osdb/frucht", "fruit"), ("blueten", "flower"), + ("osdb/blu", "flower"), ("baume", "tree"), ]