The PostgreSQL-based project is designed for a charity organization that manages orphans, projects (wells, mosques), and various campaigns (summer, winter, zakat). The project uses advanced PostgreSQL features including views, functions, JSONB, audit logging, MVCC version tracking, and disaster recovery mechanisms.
- orphans: Stores orphan details.
- donors: Stores donor information.
- projects: Includes project details such as wells and mosques.
- campaigns: Handles seasonal campaigns like Summer, Winter, and Zakat.
- donations: Tracks donations linked to donors, orphans, projects, or campaigns.
- Metadata and extended information is stored in JSONB format for flexible querying and storage.
-
Comprehensive SQL views for:
- Orphan sponsorship details
- Donation statistics
- Campaign donation summary
- Project progress reports
- Get top N donors in a date range
- Return projects nearing completion
- Auto-calculate sponsorship duration
- Summarize monthly donations
- Generate campaign donation reports
- Audit tables track changes in orphans, donations, and projects.
- Each insert, update, and delete is logged with a timestamp.
-
Custom MVCC Implementation to track historical changes without overwriting existing data.
-
Tables store multiple versions of each record using
valid_from
andvalid_to
timestamps. -
Triggers automatically insert a new row version on updates.
-
Functions to:
- Retrieve the current active version of a record
- Retrieve all historical versions
- Restore older versions if needed
-
Demonstrates how PostgreSQL’s concurrency model can be implemented and extended at the schema level.
- Backup (shadow) tables with triggers to maintain real-time backups.
- Procedures to restore tables from backup.
- Detection mechanisms for tampering or unauthorized deletions.
schema.sql
— Table definitionsdata.sql
— Sample data insertionviews.sql
— SQL viewsfunctions.sql
— Functions for analytics and business logicstoredProcedures.sql
— Stored procedures for complex operationstriggers_auditing.sql
— Triggers and audit logsmvcc_demo_schema.sql
— MVCC-enabled table, triggers, and functionsdisaster_recovery.sql
— Recovery and backup scriptsdiagram.png
— ERD diagram for understanding schema
This project is structured to easily incorporate real-time external data (e.g. exchange rates or donor validation APIs) through extensions or application layers.
Thanks to Waqar Ali for his valuable guidance and ideas throughout this project.
- Clone the repository:
git clone https://github.com/Imran-imtiaz48/CharityProject_PostgreSQL.git
cd CharityProject_PostgreSQL
- Run scripts in PostgreSQL:
\i schema.sql
\i data.sql
\i views.sql
\i functions.sql
\i storedProcedures.sql
\i triggers_auditing.sql
\i mvcc_demo_schema.sql
\i disaster_recovery.sql
- Explore and expand!
This project demonstrates real-world database architecture, maintainability, and data protection best practices, including version control for data changes through MVCC.