# 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.