| Idx | Column Name | Data Type |
|---|---|---|
| * | Artist_ID | INT AUTO_INCREMENT |
| * | Real_Name | VARCHAR(100) |
| Stage_Name | VARCHAR(100) | |
| Birthdate | DATE | |
| Website | VARCHAR(255) | |
| Instagram_Profile | VARCHAR(255) | |
| Image | TEXT | |
| Image_Description | TEXT | |
| Indexes | ||
| pk_artist | Primary Key ON Artist_ID | |
| Referring Foreign Key | ||
| ArtistGenre_ibfk_1 | Artist_ID ↙ ❏ ArtistGenre | |
| Band_Member_ibfk_2 | Artist_ID ↙ ❏ Band_Member | |
| Performance_ibfk_2 | Artist_ID ↙ ❏ Performance | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Artist_ID | INT |
| * | Genre_ID | INT |
| Indexes | ||
| pk_artistgenre | Primary Key ON Artist_ID, Genre_ID | |
| Genre_ID | Index ON Genre_ID | |
| Foreign Key | ||
| ArtistGenre_ibfk_1 | Artist_ID ↗ ❏ Artist | |
| ArtistGenre_ibfk_2 | Genre_ID ↗ ❏ MusicGenre | |
| Options | ||
| ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Band_ID | INT AUTO_INCREMENT |
| * | Name | VARCHAR(100) |
| Formation_Date | DATE | |
| Website | VARCHAR(255) | |
| Instagram_Profile | VARCHAR(255) | |
| Indexes | ||
| pk_band | Primary Key ON Band_ID | |
| Referring Foreign Key | ||
| Band_Member_ibfk_1 | Band_ID ↙ ❏ Band_Member | |
| Performance_ibfk_3 | Band_ID ↙ ❏ Performance | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Band_ID | INT |
| * | Artist_ID | INT |
| Indexes | ||
| pk_band_member | Primary Key ON Band_ID, Artist_ID | |
| Artist_ID | Index ON Artist_ID | |
| Foreign Key | ||
| Band_Member_ibfk_1 | Band_ID ↗ ❏ Band | |
| Band_Member_ibfk_2 | Artist_ID ↗ ❏ Artist | |
| Options | ||
| ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Image_ID | INT AUTO_INCREMENT |
| * | Entity_Type | ENUM('Festival','Artist','Band','Stage','Equipment') |
| * | Entity_ID | INT |
| Image_Description | VARCHAR(255) | |
| * | Image_Data | LONGBLOB |
| Indexes | ||
| pk_entityimage | Primary Key ON Image_ID | |
| Options | ||
| ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Evaluation_ID | INT AUTO_INCREMENT |
| * | Visitor_ID | INT |
| * | Performance_ID | INT |
| * | Evaluation_Date | DATETIME DEFAULT current_timestamp() |
| * | Artist_Performance | TINYINT |
| * | Sound_Lighting | TINYINT |
| * | Stage_Presence | TINYINT |
| * | Organization | TINYINT |
| * | Overall_Impression | TINYINT |
| Indexes | ||
| pk_evaluation | Primary Key ON Evaluation_ID | |
| Visitor_ID | Unique Key ON Visitor_ID, Performance_ID | |
| idx_evaluation_visitor | Index ON Visitor_ID | |
| idx_evaluation_performance | Index ON Performance_ID | |
| Foreign Key | ||
| Evaluation_ibfk_1 | Visitor_ID ↗ ❏ Visitor | |
| Evaluation_ibfk_2 | Performance_ID ↗ ❏ Performance | |
| Constraints | ||
| cns_evaluation_artist_performance | `Artist_Performance` between 1 and 3 | |
| cns_evaluation_sound_lighting | `Sound_Lighting` between 1 and 3 | |
| cns_evaluation_stage_presence | `Stage_Presence` between 1 and 3 | |
| cns_evaluation_organization | `Organization` between 1 and 3 | |
| cns_evaluation_overall_impression | `Overall_Impression` between 1 and 3 | |
| Triggers | ||
| check_evaluation_ticket_activation | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Evaluation FOR EACH ROW BEGIN
DECLARE ticket_count INT;
SELECT COUNT(*) INTO ticket_count
FROM Ticket t
JOIN Performance p ON t.Performance_ID = p.Performance_ID
WHERE t.Visitor_ID = NEW.Visitor_ID
AND t.Performance_ID = NEW.Performance_ID
AND t.Activated = 1;
IF ticket_count = 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Evaluation not allowed: visitor must have an activated ticket for the performance.';
END IF;
END | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Event_ID | INT AUTO_INCREMENT |
| * | Festival_ID | INT |
| * | Stage_ID | INT |
| * | Start_Time | DATETIME |
| * | End_Time | DATETIME |
| * | Status | ENUM('Scheduled','Ongoing','Completed') DEFAULT 'Scheduled' |
| Indexes | ||
| pk_event | Primary Key ON Event_ID | |
| Stage_ID | Unique Key ON Stage_ID, Start_Time | |
| idx_event_festival | Index ON Festival_ID | |
| idx_event_stage | Index ON Stage_ID | |
| Foreign Key | ||
| Event_ibfk_1 | Festival_ID ↗ ❏ Festival | |
| Event_ibfk_2 | Stage_ID ↗ ❏ Stage | |
| Referring Foreign Key | ||
| Performance_ibfk_1 | Event_ID ↙ ❏ Performance | |
| StaffAssignment_ibfk_2 | Event_ID ↙ ❏ StaffAssignment | |
| Constraints | ||
| CONSTRAINT_1 | `End_Time` > `Start_Time` | |
| CONSTRAINT_2 | `Status` <> 'Canceled' | |
| Triggers | ||
| prevent_event_overlap | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Event FOR EACH ROW BEGIN
DECLARE overlap_count INT;
SELECT COUNT(*) INTO overlap_count
FROM Event
WHERE Stage_ID = NEW.Stage_ID
AND Festival_ID = NEW.Festival_ID
AND DATE(Start_Time) = DATE(NEW.Start_Time)
AND (
NEW.Start_Time < End_Time AND
NEW.End_Time > Start_Time
);
IF overlap_count > 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Error: Overlapping event detected on the same stage.';
END IF;
END | |
| prevent_event_overlap_update | CREATE TRIGGER ${nameWithSchemaName} BEFORE UPDATE ON Event FOR EACH ROW BEGIN
DECLARE overlap_count INT;
SELECT COUNT(*) INTO overlap_count
FROM Event
WHERE Stage_ID = NEW.Stage_ID
AND Festival_ID = NEW.Festival_ID
AND Event_ID != NEW.Event_ID
AND (
NEW.Start_Time < End_Time AND
NEW.End_Time > Start_Time
);
IF overlap_count > 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Error: Overlapping event detected on the same stage.';
END IF;
END | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Festival_ID | INT AUTO_INCREMENT |
| * | Year | YEAR(4) |
| * | Start_Date | DATE |
| * | End_Date | DATE |
| Image | TEXT | |
| Image_Description | TEXT | |
| * | Location_ID | INT |
| * | Status | ENUM('Scheduled','Ongoing','Completed') DEFAULT 'Scheduled' |
| Indexes | ||
| pk_festival | Primary Key ON Festival_ID | |
| Location_ID | Index ON Location_ID | |
| Foreign Key | ||
| Festival_ibfk_1 | Location_ID ↗ ❏ Location | |
| Referring Foreign Key | ||
| Event_ibfk_1 | Festival_ID ↙ ❏ Event | |
| Constraints | ||
| CONSTRAINT_1 | `End_Date` > `Start_Date` | |
| CONSTRAINT_2 | `Status` <> 'Canceled' | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Location_ID | INT AUTO_INCREMENT |
| * | Address | VARCHAR(255) |
| Coordinates | VARCHAR(100) | |
| * | City | VARCHAR(100) |
| * | Country | VARCHAR(100) |
| Continent | VARCHAR(100) | |
| Image | TEXT | |
| Image_Description | TEXT | |
| Indexes | ||
| pk_location | Primary Key ON Location_ID | |
| Referring Foreign Key | ||
| Festival_ibfk_1 | Location_ID ↙ ❏ Festival | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Genre_ID | INT |
| Name | TEXT | |
| Subgenre | TEXT | |
| Indexes | ||
| pk_musicgenre | Primary Key ON Genre_ID | |
| Referring Foreign Key | ||
| ArtistGenre_ibfk_2 | Genre_ID ↙ ❏ ArtistGenre | |
| Options | ||
| ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Performance_ID | INT AUTO_INCREMENT |
| * | Event_ID | INT |
| Artist_ID | INT | |
| Band_ID | INT | |
| * | Type | ENUM('Warm Up','Headline','Special Guest') |
| * | Start_Time | DATETIME |
| * | Duration | INT |
| Indexes | ||
| pk_performance | Primary Key ON Performance_ID | |
| idx_performance_artist | Index ON Artist_ID | |
| idx_performance_band | Index ON Band_ID | |
| idx_performance_event | Index ON Event_ID | |
| Foreign Key | ||
| Performance_ibfk_1 | Event_ID ↗ ❏ Event | |
| Performance_ibfk_2 | Artist_ID ↗ ❏ Artist | |
| Performance_ibfk_3 | Band_ID ↗ ❏ Band | |
| Referring Foreign Key | ||
| Evaluation_ibfk_2 | Performance_ID ↙ ❏ Evaluation | |
| ResaleBuyerQueue_ibfk_2 | Performance_ID ↙ ❏ ResaleBuyerQueue | |
| Ticket_ibfk_1 | Performance_ID ↙ ❏ Ticket | |
| Constraints | ||
| cns_performance_duration | `Duration` > 0 and `Duration` <= 180 | |
| CONSTRAINT_1 | `Artist_ID` is not null and `Band_ID` is null or `Artist_ID` is null and `Band_ID` is not null | |
| Triggers | ||
| check_artist_consecutive_years | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Performance FOR EACH ROW BEGIN
DECLARE year INT;
DECLARE consecutive_years INT;
IF NEW.Artist_ID IS NOT NULL THEN
SELECT f.Year INTO year
FROM Event e
JOIN Festival f ON e.Festival_ID = f.Festival_ID
WHERE e.Event_ID = NEW.Event_ID;
SELECT COUNT(DISTINCT f.Year) INTO consecutive_years
FROM Performance p
JOIN Event e ON p.Event_ID = e.Event_ID
JOIN Festival f ON e.Festival_ID = f.Festival_ID
WHERE p.Artist_ID = NEW.Artist_ID
AND f.Year BETWEEN year - 2 AND year;
IF consecutive_years > 3 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Artist cannot perform more than 3 consecutive years.';
END IF;
END IF;
END | |
| check_band_consecutive_years | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Performance FOR EACH ROW BEGIN
DECLARE current_year INT;
DECLARE consecutive_years INT;
IF NEW.Band_ID IS NOT NULL THEN
SELECT f.Year INTO current_year
FROM Event e
JOIN Festival f ON e.Festival_ID = f.Festival_ID
WHERE e.Event_ID = NEW.Event_ID;
SELECT COUNT(DISTINCT f.Year) INTO consecutive_years
FROM Performance p
JOIN Event e ON p.Event_ID = e.Event_ID
JOIN Festival f ON e.Festival_ID = f.Festival_ID
WHERE p.Band_ID = NEW.Band_ID
AND f.Year BETWEEN current_year - 2 AND current_year;
IF consecutive_years >= 3 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Band cannot perform more than 3 consecutive years.';
END IF;
END IF;
END | |
| check_performance_break | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Performance FOR EACH ROW BEGIN
DECLARE previous_end_time DATETIME;
DECLARE break_duration INT;
DECLARE conflicting_count INT;
SELECT COUNT(*) INTO conflicting_count
FROM Performance
WHERE Event_ID = NEW.Event_ID
AND DATE(Start_Time) = DATE(NEW.Start_Time)
AND (
(NEW.Start_Time BETWEEN Start_Time AND (Start_Time + INTERVAL Duration MINUTE - INTERVAL 1 SECOND))
OR ((NEW.Start_Time + INTERVAL NEW.Duration MINUTE - INTERVAL 1 SECOND) BETWEEN Start_Time AND (Start_Time + INTERVAL Duration MINUTE - INTERVAL 1 SECOND))
OR (Start_Time BETWEEN NEW.Start_Time AND (NEW.Start_Time + INTERVAL NEW.Duration MINUTE - INTERVAL 1 SECOND))
);
IF conflicting_count > 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Performance time overlaps with an existing performance.';
END IF;
SELECT MAX(Start_Time + INTERVAL Duration MINUTE) INTO previous_end_time
FROM Performance
WHERE Event_ID = NEW.Event_ID
AND Start_Time < NEW.Start_Time
AND DATE(Start_Time) = DATE(NEW.Start_Time);
IF previous_end_time IS NOT NULL THEN
SET break_duration = TIMESTAMPDIFF(MINUTE, previous_end_time, NEW.Start_Time);
IF break_duration < 5 OR break_duration > 30 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Break between performances must be between 5 and 30 minutes.';
END IF;
END IF;
END | |
| prevent_artist_overlap | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Performance FOR EACH ROW BEGIN
DECLARE overlap_count INT;
DECLARE festival_id INT;
IF NEW.Artist_ID IS NOT NULL THEN
SELECT e.Festival_ID INTO festival_id
FROM Event e
WHERE e.Event_ID = NEW.Event_ID;
SELECT COUNT(*) INTO overlap_count
FROM Performance p
JOIN Event e ON p.Event_ID = e.Event_ID
WHERE p.Artist_ID = NEW.Artist_ID
AND e.Festival_ID = festival_id
AND (
NEW.Start_Time < ADDTIME(p.Start_Time, SEC_TO_TIME(p.Duration * 60)) AND
ADDTIME(NEW.Start_Time, SEC_TO_TIME(NEW.Duration * 60)) > p.Start_Time
);
IF overlap_count > 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Artist has overlapping performance in the same festival.';
END IF;
END IF;
END | |
| prevent_band_overlap | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Performance FOR EACH ROW BEGIN
DECLARE overlap_count INT;
DECLARE festival_id INT;
IF NEW.Band_ID IS NOT NULL THEN
SELECT e.Festival_ID INTO festival_id
FROM Event e
WHERE e.Event_ID = NEW.Event_ID;
SELECT COUNT(*) INTO overlap_count
FROM Performance p
JOIN Event e ON p.Event_ID = e.Event_ID
WHERE p.Band_ID = NEW.Band_ID
AND e.Festival_ID = festival_id
AND (
NEW.Start_Time < ADDTIME(p.Start_Time, SEC_TO_TIME(p.Duration * 60)) AND
ADDTIME(NEW.Start_Time, SEC_TO_TIME(NEW.Duration * 60)) > p.Start_Time
);
IF overlap_count > 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Band has overlapping performance in the same festival.';
END IF;
END IF;
END | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Queue_ID | INT AUTO_INCREMENT |
| * | Buyer_ID | INT |
| * | Performance_ID | INT |
| * | Category | ENUM('General','VIP','Backstage') |
| * | Requested_At | DATETIME DEFAULT current_timestamp() |
| * | Status | ENUM('Waiting','Matched','Cancelled') DEFAULT 'Waiting' |
| Indexes | ||
| pk_resalebuyerqueue | Primary Key ON Queue_ID | |
| idx_resalebuyerqueue_buyer | Index ON Buyer_ID | |
| idx_resalebuyerqueue_performance | Index ON Performance_ID | |
| Foreign Key | ||
| ResaleBuyerQueue_ibfk_1 | Buyer_ID ↗ ❏ Visitor(Visitor_ID) | |
| ResaleBuyerQueue_ibfk_2 | Performance_ID ↗ ❏ Performance | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | ResaleTicket_ID | INT AUTO_INCREMENT |
| * | Ticket_ID | INT |
| * | Seller_ID | INT |
| * | Listed_At | DATETIME DEFAULT current_timestamp() |
| * | Status | ENUM('Available','Sold','Withdrawn') DEFAULT 'Available' |
| Indexes | ||
| pk_resaleticket | Primary Key ON ResaleTicket_ID | |
| idx_resaleticket_ticket | Index ON Ticket_ID | |
| idx_resaleticket_seller | Index ON Seller_ID | |
| Foreign Key | ||
| ResaleTicket_ibfk_1 | Ticket_ID ↗ ❏ Ticket | |
| ResaleTicket_ibfk_2 | Seller_ID ↗ ❏ Visitor(Visitor_ID) | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Staff_ID | INT AUTO_INCREMENT |
| * | Name | VARCHAR(100) |
| * | Age | INT |
| * | Role | ENUM('Technical','Security','Auxiliary') |
| * | Experience_Level | ENUM('Intern','Beginner','Intermediate','Experienced','Expert') |
| Indexes | ||
| pk_staff | Primary Key ON Staff_ID | |
| Referring Foreign Key | ||
| StaffAssignment_ibfk_1 | Staff_ID ↙ ❏ StaffAssignment | |
| Constraints | ||
| cns_staff_age | `Age` >= 18 | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=301 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Staff_ID | INT |
| * | Event_ID | INT |
| Indexes | ||
| pk_staffassignment | Primary Key ON Staff_ID, Event_ID | |
| idx_staffassignment_staff | Index ON Staff_ID | |
| idx_staffassignment_event | Index ON Event_ID | |
| Foreign Key | ||
| StaffAssignment_ibfk_1 | Staff_ID ↗ ❏ Staff | |
| StaffAssignment_ibfk_2 | Event_ID ↗ ❏ Event | |
| Options | ||
| ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Stage_ID | INT AUTO_INCREMENT |
| * | Name | VARCHAR(100) |
| Description | TEXT | |
| * | Max_Capacity | INT |
| Technical_Equipment | TEXT | |
| Image | TEXT | |
| Image_Description | TEXT | |
| Indexes | ||
| pk_stage | Primary Key ON Stage_ID | |
| Referring Foreign Key | ||
| Event_ibfk_2 | Stage_ID ↙ ❏ Event | |
| Constraints | ||
| cns_stage_max_capacity | `Max_Capacity` > 0 | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Ticket_ID | INT AUTO_INCREMENT |
| * | Performance_ID | INT |
| * | Visitor_ID | INT |
| * | Category | ENUM('General','VIP','Backstage') |
| * | Purchase_Date | DATE |
| * | Cost | DECIMAL(10,2) |
| * | Payment_Method | ENUM('Credit Card','Debit Card','Bank Transfer') |
| * | EAN131_Code | BIGINT |
| Activated | BOOLEAN DEFAULT false | |
| Indexes | ||
| pk_ticket | Primary Key ON Ticket_ID | |
| EAN131_Code | Unique Key ON EAN131_Code | |
| Visitor_ID | Unique Key ON Visitor_ID, Performance_ID, Purchase_Date | |
| idx_ticket_performance | Index ON Performance_ID | |
| idx_ticket_visitor | Index ON Visitor_ID | |
| Foreign Key | ||
| Ticket_ibfk_1 | Performance_ID ↗ ❏ Performance | |
| Ticket_ibfk_2 | Visitor_ID ↗ ❏ Visitor | |
| Referring Foreign Key | ||
| ResaleTicket_ibfk_1 | Ticket_ID ↙ ❏ ResaleTicket | |
| TicketResaleQueue_ibfk_1 | Ticket_ID ↙ ❏ TicketResaleQueue | |
| Triggers | ||
| check_stage_capacity | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Ticket FOR EACH ROW BEGIN
DECLARE total_tickets INT;
DECLARE stage_capacity INT;
SELECT COUNT(*) INTO total_tickets
FROM Ticket
WHERE Performance_ID = NEW.Performance_ID;
SELECT s.Max_Capacity INTO stage_capacity
FROM Performance p
JOIN Event e ON p.Event_ID = e.Event_ID
JOIN Stage s ON e.Stage_ID = s.Stage_ID
WHERE p.Performance_ID = NEW.Performance_ID;
IF total_tickets >= stage_capacity THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Cannot sell ticket: stage capacity exceeded.';
END IF;
END | |
| check_vip_limit | CREATE TRIGGER ${nameWithSchemaName} BEFORE INSERT ON Ticket FOR EACH ROW BEGIN
DECLARE vip_tickets INT;
DECLARE stage_capacity INT;
DECLARE max_vip_tickets INT;
IF NEW.Category = 'VIP' THEN
SELECT COUNT(*) INTO vip_tickets
FROM Ticket
WHERE Performance_ID = NEW.Performance_ID
AND Category = 'VIP';
SELECT s.Max_Capacity INTO stage_capacity
FROM Performance p
JOIN Event e ON p.Event_ID = e.Event_ID
JOIN Stage s ON e.Stage_ID = s.Stage_ID
WHERE p.Performance_ID = NEW.Performance_ID;
SET max_vip_tickets = FLOOR(stage_capacity * 0.10);
IF vip_tickets >= max_vip_tickets THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Cannot sell VIP ticket: VIP limit exceeded.';
END IF;
END IF;
END | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=401 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Queue_ID | INT |
| Ticket_ID | INT | |
| Queue_Type | TEXT | |
| Queue_Timestamp | DATETIME | |
| Indexes | ||
| pk_ticketresalequeue | Primary Key ON Queue_ID | |
| Ticket_ID | Index ON Ticket_ID | |
| Foreign Key | ||
| TicketResaleQueue_ibfk_1 | Ticket_ID ↗ ❏ Ticket | |
| Options | ||
| ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| Idx | Column Name | Data Type |
|---|---|---|
| * | Visitor_ID | INT AUTO_INCREMENT |
| * | First_Name | VARCHAR(100) |
| * | Last_Name | VARCHAR(100) |
| * | Contact_Info | VARCHAR(255) |
| * | Age | INT |
| Indexes | ||
| pk_visitor | Primary Key ON Visitor_ID | |
| Referring Foreign Key | ||
| Evaluation_ibfk_1 | Visitor_ID ↙ ❏ Evaluation | |
| ResaleBuyerQueue_ibfk_1 | Visitor_ID ↙ ❏ ResaleBuyerQueue(Buyer_ID) | |
| ResaleTicket_ibfk_2 | Visitor_ID ↙ ❏ ResaleTicket(Seller_ID) | |
| Ticket_ibfk_2 | Visitor_ID ↙ ❏ Ticket | |
| Constraints | ||
| cns_visitor_age | `Age` >= 0 | |
| Options | ||
| ENGINE=InnoDB AUTO_INCREMENT=401 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | ||
| kosni_db.`ProcessResaleQueue` | |
CREATE PROCEDURE ${nameWithSchemaName}()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE resale_ticket_id INT;
DECLARE ticket_id INT;
DECLARE performance_id INT;
DECLARE category ENUM('General', 'VIP', 'Backstage');
DECLARE buyer_id INT;
DECLARE buyer_queue_id INT;
DECLARE resale_cursor CURSOR FOR
SELECT rt.ResaleTicket_ID, t.Ticket_ID, p.Performance_ID, t.Category
FROM ResaleTicket rt
JOIN Ticket t ON rt.Ticket_ID = t.Ticket_ID
JOIN Performance p ON t.Performance_ID = p.Performance_ID
WHERE rt.Status = 'Available'
ORDER BY rt.Listed_At ASC;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN resale_cursor;
read_loop: LOOP
FETCH resale_cursor INTO resale_ticket_id, ticket_id, performance_id, category;
IF done THEN
LEAVE read_loop;
END IF;
SELECT rbq.Queue_ID, rbq.Buyer_ID
INTO buyer_queue_id, buyer_id
FROM ResaleBuyerQueue rbq
WHERE rbq.Status = 'Waiting'
AND rbq.Performance_ID = performance_id
AND rbq.Category = category
ORDER BY rbq.Requested_At ASC
LIMIT 1;
IF buyer_id IS NOT NULL THEN
UPDATE Ticket
SET Visitor_ID = buyer_id
WHERE Ticket_ID = ticket_id;
UPDATE ResaleTicket
SET Status = 'Sold'
WHERE ResaleTicket_ID = resale_ticket_id;
UPDATE ResaleBuyerQueue
SET Status = 'Matched'
WHERE Queue_ID = buyer_queue_id;
SET buyer_id = NULL;
END IF;
END LOOP;
CLOSE resale_cursor;
END |