A PostgreSQL database schema for tracking courses, finances, habits, tasks, trips, and users in one structured personal data system.
This project focuses on database design, data integrity, and repeatable validation. It includes a schema-only SQL file, an optional full dump with seed data, pgTAP tests, Docker setup for PostgreSQL, and CI checks for schema validation.
| Area | Purpose | Main Tables |
|---|---|---|
course |
Courses, topics, statuses, and progress | courses, course_topics, course_statuses |
finance |
Income and expense tracking | finances, finance_categories, finance_types |
habits |
Habit definitions and logs | habits, habit_categories, habit_logs |
todo |
Tasks, priorities, and statuses | todos, todo_categories, task_statuses, task_priorities |
trips |
Trips, routes, and trip expenses | trips, trip_routes, trip_expenses |
user |
Users and roles | users, user_roles |
- PostgreSQL schemas grouped by domain
- Primary keys, foreign keys, checks, indexes, functions, triggers, and views
- Trigger logic for course status updates, task completion dates, amount validation, and
updated_attimestamps - Analytics views for course progress, financial summaries, grades, and trip costs
- Schema-only setup file for clean installs
- Optional full dump with seed data for local exploration
PersonalBase.sgl/
schema.sql Clean schema DDL, no seed data
Personal base.sql Full dump with seed data
tests/pgtap/ pgTAP structure tests
scripts/ Validation and schema generation scripts
docker/pgtap/ PostgreSQL image setup for pgTAP
docs/ Architecture and validation notes
ER.png ER diagram reference
- PostgreSQL 16 or higher
psql- Docker, optional but recommended for local validation
- Bash or PowerShell, depending on your OS
Create a database and import the schema:
psql -U your_user -d your_db -f schema.sqlImport the optional full dump with seed data:
psql -U your_user -d your_db -f "Personal base.sql"Run all checks on Windows:
powershell -ExecutionPolicy Bypass -File scripts/validate_all.ps1Run all checks on macOS or Linux:
bash scripts/validate_all.shThe validation flow checks:
schema.sqlis in sync withPersonal base.sql- The schema imports into PostgreSQL with
ON_ERROR_STOP=on - Smoke tests pass
- pgTAP structure tests pass
schema.sql is generated from Personal base.sql by removing data sections and sequence resets while keeping DDL, constraints, functions, triggers, indexes, views, and comments.
Windows:
powershell -ExecutionPolicy Bypass -File scripts/generate_schema.ps1macOS or Linux:
bash scripts/generate_schema.shCheck whether schema.sql is current:
bash scripts/check_schema_up_to_date.shThe pgTAP tests verify schema structure:
- Schemas exist
- Main tables exist
- Important columns use expected data types
- Primary keys and foreign keys exist
- Indexes exist on key tables
- Trigger functions and triggers are installed
- Analytics views are present and queryable
Run pgTAP tests directly:
bash scripts/run_pgtap.shWindows:
powershell -ExecutionPolicy Bypass -File scripts/run_pgtap.ps1Start PostgreSQL with pgTAP support:
docker-compose up -d postgresStop it after testing:
docker-compose downGitHub Actions runs validation on pushes and pull requests:
- Schema drift check
- PostgreSQL import
- Smoke tests
- pgTAP tests
ER.png is included as a visual reference.
The SQL files and pgTAP tests are the source of truth if the diagram ever differs from the schema.
schema.sqlis the recommended starting point for a clean database.Personal base.sqlis useful for local demos because it includes seed data.- The project is focused on database design and validation, not on an application UI.
