1 Commits
7 changed files with 39 additions and 38 deletions
-1
View File
@@ -1,6 +1,5 @@
# -include: silently skip if .env doesn't exist (e.g. fresh clone before 'cp .env.example .env') # -include: silently skip if .env doesn't exist (e.g. fresh clone before 'cp .env.example .env')
-include .env -include .env
-include backend/.env
export export
.PHONY: dev-db migrate-up migrate-down run-backend run-frontend test fmt .PHONY: dev-db migrate-up migrate-down run-backend run-frontend test fmt
+1 -31
View File
@@ -17,43 +17,13 @@ A full-stack fruit-variety database (Go + Vue 3).
cp .env.example .env # set credentials cp .env.example .env # set credentials
cp backend/.env.example backend/.env # set JWT_SECRET and USERS_FILE cp backend/.env.example backend/.env # set JWT_SECRET and USERS_FILE
cp users.env.example users.env # create user file (see below) cp users.env.example users.env # create user file (see below)
./scripts/create_user.sh admin secret >> users.env # add a user (restart backend to reload) ./scripts/create_user.sh admin secret >> users.env # add a user
make dev-db # start Postgres (waits until healthy) make dev-db # start Postgres (waits until healthy)
make migrate-up # apply schema migrations make migrate-up # apply schema migrations
make run-backend # Echo API on :3000 make run-backend # Echo API on :3000
make run-frontend # Vite dev server on :5000 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 <username> <password> >> users.env
```
## Testing ## Testing
```bash ```bash
+1 -1
View File
@@ -1,4 +1,4 @@
DATABASE_URL=postgres://osdb:osdb@localhost:5432/osdb?sslmode=disable DATABASE_URL=postgres://osdb:osdb@localhost:5432/osdb
PORT=3000 PORT=3000
JWT_SECRET=change-me-use-a-long-random-string JWT_SECRET=change-me-use-a-long-random-string
USERS_FILE=../users.env USERS_FILE=../users.env
@@ -1 +0,0 @@
ALTER TABLE fruits ALTER COLUMN osdb_number TYPE VARCHAR(50);
@@ -1 +0,0 @@
ALTER TABLE fruits ALTER COLUMN osdb_number TYPE VARCHAR(100);
+37
View File
@@ -0,0 +1,37 @@
# 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 `<obj>` elements with `<osw>=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.
-3
View File
@@ -51,10 +51,7 @@ TYP_MAP = {
IMAGE_DIRS = [ IMAGE_DIRS = [
("einzelfruechte", "fruit"), ("einzelfruechte", "fruit"),
("osdb/fru", "fruit"),
("osdb/frucht", "fruit"),
("blueten", "flower"), ("blueten", "flower"),
("osdb/blu", "flower"),
("baume", "tree"), ("baume", "tree"),
] ]