Overview
EventPalour’s ticketing system supports multiple ticket types per event with flexible pricing, availability controls, and comprehensive status tracking. The system handles both ticket definitions and purchased ticket instances.Ticket Architecture
The ticketing system consists of three main components:- Ticket Types: Reusable ticket type definitions (e.g., “VIP”, “Early Bird”)
- Tickets: Event-specific ticket configurations with pricing and availability
- Purchased Tickets: Individual ticket instances owned by users
Ticket Types
Ticket types are workspace-level templates defined intickets_types table:
Ticket types are reusable across all events in a workspace. Create types once and apply them to multiple events.
Common Ticket Types
VIP
Premium access with exclusive benefits
Early Bird
Discounted tickets for early registrations
Standard
Regular admission tickets
Student
Discounted tickets for students
Tickets Schema
Thetickets table defines event-specific ticket configurations:
| Field | Type | Description |
|---|---|---|
id | varchar(16) | Unique ticket ID |
event_id | varchar(16) | Associated event (foreign key) |
ticket_type_id | varchar(16) | Ticket type (foreign key) |
price | numeric(10, 2) | Ticket price |
availability_quantity | integer | Max tickets (NULL = unlimited) |
currency | currency_enum | Price currency (default: “KES”) |
valid_from | timestamp | Sales start time (with timezone) |
valid_until | timestamp | Sales end time (with timezone) |
created_at | timestamp | Creation timestamp |
updated_at | timestamp | Last update timestamp |
Tickets connect event-specific configurations (price, availability) with workspace-level ticket types (name, category).
Currency Support
Currently supported currencies:Availability Management
Unlimited Tickets
Setavailability_quantity to NULL for unlimited ticket sales:
Limited Tickets
Set a specific number for capacity-limited events:Time-based Availability
Control when tickets can be purchased usingvalid_from and valid_until:
Purchased Tickets
When users buy tickets, instances are created inpurchased_tickets:
| Field | Type | Description |
|---|---|---|
id | varchar(16) | Purchased ticket ID |
user_id | varchar(16) | Ticket owner |
ticket_id | varchar(16) | Reference to ticket definition |
status | ticket_status_enum | Current status (default: “sold”) |
price | numeric(10, 2) | Actual purchase price |
quantity | integer | Number of tickets purchased |
used | boolean | Whether ticket was scanned (default: false) |
used_at | timestamp | Scan/redemption timestamp |
created_at | timestamp | Purchase timestamp |
updated_at | timestamp | Last update timestamp |
Ticket Status Lifecycle
Purchased tickets transition through various statuses:Status Definitions
- Available
- Reserved
- Sold
- Cancelled
- Refunded
- Transferred
- Used
- Expired
- On Hold
Ticket is ready for purchase. Default state for ticket inventory.
Ticket Reservations
Theticket_reservations table manages temporary holds during checkout:
Ticket Relationships
Ticket Transfers
Users can transfer tickets to others viaticket_transfers:
When a transfer completes, update the
purchased_tickets.user_id to the new owner and set status to TRANSFERRED.Ticket Scanning
Track ticket redemption at event entrances usingticket_scans:
The table has a unique constraint on
purchased_ticket_id to prevent double-scanning. Each ticket can only be scanned once.Pricing Strategies
Tiered Pricing
Create multiple tickets for the same event with different prices:Dynamic Pricing
Adjust prices based on demand by creating new ticket records:- Set
valid_untilon current tickets to end availability - Create new tickets with updated prices
- Set
valid_fromto when new pricing takes effect
Best Practices
Inventory Management
Inventory Management
- Use database transactions when decrementing
availability_quantity - Implement optimistic locking to prevent overselling
- Monitor inventory levels and alert when running low
Reservation Expiry
Reservation Expiry
- Set reasonable expiration times (10-15 minutes)
- Run cleanup jobs every 1-2 minutes to release expired reservations
- Notify users before their reservation expires
Status Transitions
Status Transitions
Validate status changes:
RESERVED→SOLD(only if payment succeeds)SOLD→USED(only at event time, with proper authentication)SOLD→REFUNDED(only within refund policy window)
Price History
Price History
Store the actual purchase price in
purchased_tickets.price. Never reference the current ticket price for historical purchases.Currency Handling
Currency Handling
- Always specify currency when displaying prices
- Store all prices as decimal(10, 2) for precision
- Handle currency conversions at application level if needed
Common Queries
Technical Details
Schema Location
Key Relationships
Defined in/lib/db/schema/relations.ts:95-119, 254-265:
- Tickets belong to events and ticket types
- Purchased tickets belong to users and reference tickets
- Reservations temporarily hold tickets for users
- Transfers track ownership changes