This provides a data import tool for historical Bills of Mortality data, allowing you to load and process CSV files into a PostgreSQL database.
- Go (1.16+)
- PostgreSQL
golang-migratefor database migrations- Make
- Go: Download and install from golang.org
- PostgreSQL: Install from postgresql.org
- golang-migrate:
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
-
Create a
.envfile in the project root based on the.env.example:cp .env.example .env
-
Edit the
.envfile to set:DB_CONN_STR: PostgreSQL connection string- Format:
postgresql://username:password@host:port/dbname
- Format:
DATA_DIR: Directory containing your CSV files
Before importing data, ensure your database is prepared:
# Run database migrations
make db-up-
Dry Run (Test Import):
make dry-run
This will simulate the import process without making any database changes.
-
Full Data Import:
make db-update
This will import data from the CSV files specified in
DATA_DIR.
make build: Compile the applicationmake fmt: Format Go codemake vet: Run Go code analysismake deps: Download project dependencies
make db-up: Apply database migrationsmake db-down: Revert database migrationsmake db-test: Test database connection
The importer populates the following tables in the bom schema:
- Years: Historical year records
- Weeks: Weekly records with identifiers
- Parishes: Location information
- Christenings: Baptism records
- Causes of Death: Mortality cause details
- Bills of Mortality: Comprehensive mortality records
- The importer uses transactions to ensure data integrity
- Duplicate records are handled with "upsert" logic
- Detailed logging is provided for each import operation
Import operations are logged in a custom bom.log_operation table, tracking:
- Operation type
- Table affected
- Rows processed
- Timestamp
- Execution time
- The importer uses PostgreSQL's
COPYprotocol for efficient data loading ANALYZEis run after import to update table statistics
- Ensure CSV files match the expected format
- Check database connection string
- Verify data directory path
- Review import logs for specific errors
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request