Design a PostgreSQL database for an event scheduling application. This database will incorporate advanced data types to manage events, attendees, venues, and more. You are expected to create a schema that includes 8 tables, each with at least 5 records. Additionally, you will write 10 queries to demonstrate how to interact with the database effectively.
- Events
- Attendees
- Venues
- Organizers
- Event_Schedules
- Tickets
- Reviews
- User_Preferences
-
Events
- event_id: UUID
- title: TEXT
- description: JSONB
- venue_id: UUID (FK)
- organizer_id: UUID (FK)
- schedule: tsrange
-
Attendees
- attendee_id: UUID
- name: TEXT
- email: TEXT
- preferences: JSONB
- tickets: UUID[]
-
Venues
- venue_id: UUID
- name: TEXT
- location: JSONB
- capacity: INTEGER
- contact_info: TEXT[]
-
Organizers
- organizer_id: UUID
- name: TEXT
- contact_info: JSONB
-
Event_Schedules
- schedule_id: UUID
- event_id: UUID (FK)
- start_time: TIMESTAMPTZ
- end_time: TIMESTAMPTZ
- description: TEXT
-
Tickets
- ticket_id: UUID
- event_id: UUID (FK)
- attendee_id: UUID (FK)
- price: NUMERIC
- status: ENUM ('available', 'sold', 'reserved')
-
Reviews
- review_id: UUID
- event_id: UUID (FK)
- attendee_id: UUID (FK)
- rating: ENUM ('poor', 'fair', 'good', 'excellent')
- comment: TEXT
-
User_Preferences
- user_id: UUID (FK -> Attendees)
- interests: TEXT[]
- notifications_enabled: BOOLEAN
For each table, insert at least 5 records. Here's an example for the Events table:
INSERT INTO events (event_id, title, description, venue_id, organizer_id, schedule) VALUES
('uuid-1', 'Tech Conference', '{"topics":["AI", "Cloud"]}', 'venue-uuid-1', 'org-uuid-1', '[2023-10-01 09:00, 2023-10-01 17:00]'),
('uuid-2', 'Music Festival', '{"genres":["Rock", "Pop"]}', 'venue-uuid-2', 'org-uuid-2', '[2023-08-05 12:00, 2023-08-05 23:00]');
- Find all events happening in October 2023.
- List attendees who have 'Music' as an interest.
- Retrieve all venues with a capacity greater than 500.
- Get the contact information for organizers of 'Tech Conference'.
- Find all events with tickets still available.
- List all reviews for a specific event, ordered by rating.
- Update the schedule for an event.
- Find attendees who have enabled notifications.
- Retrieve the total number of tickets sold for each event.
- List all events an attendee is going to, based on their ticket purchases.
- Design the database schema: Create the tables as defined above, ensuring proper data types and relationships are used.
- Insert sample data: Populate each table with at least 5 records.
- Write queries: Construct the 10 queries listed above to interact with the database.
- Submit the SQL scripts for creating tables, inserting data, and the queries.
- Include a diagram of the database schema showing tables, columns, and relationships.
- Ensure your queries are well-commented to explain their purpose and functionality.
This assignment will test your ability to design a comprehensive database schema using advanced PostgreSQL features and interact with the database through complex queries.