Updated query to avoid redundunt SQL calls; Updated Schema design to improve garbage route efficiency
This project defines a PostgreSQL schema for tracking election campaigns, participants, debates, and donations. It includes sample data and example queries that demonstrate how to analyze campaign information.
The schema.ddl file creates the Election schema and its tables:
- ElectionCampaigns – uniquely identified by
campaign_idwith a non‑negativespending_limitconstraint. - Volunteer – references
ElectionCampaignsand uses(volunteer_email, start_time, end_time)as a composite primary key. Each volunteer record must specify acampaign_activityof eitherphone banksordoor-to-door canvassing. - Donor – records donations to campaigns. The primary key combines
donor_email,donor_campaign_id,donate_amount, anddonation_type. Donations must be non‑negative and labeled as eitherIndividualorOrganization. Additional tables capture candidates, staff members, debate moderators, debates, and the participation of candidates in debates.
queries.sql demonstrates typical analyses:
- Totals by donation type – sums organization and individual contributions for each campaign.
- Volunteers in every campaign – identifies volunteers who signed up for all campaigns in the dataset.
- Candidates in every debate – finds candidates who appear in every recorded debate.
instance.sql populates the schema with example campaigns, candidates, volunteers, staff, debates, and donors so the queries can be executed immediately.
- Create the schema:
psql -f schema.ddl
- Load the sample data:
psql -f instance.sql
- Execute the example queries:
psql -f queries.sql
Each script sets the search path to the election schema.
Provided for academic purposes as part of CSC343 (University of Toronto). Please review the original course license terms before reusing this code.