Files
leonwww/dns/migrations/007_cleanup_invalid_records.sql

25 lines
1.0 KiB
MySQL
Raw Normal View History

2025-08-22 17:31:54 +03:00
-- Remove invalid record types before applying constraint
DELETE FROM dns_records WHERE record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT');
-- Now apply the constraint
2025-11-08 17:14:40 +08:00
-- MySQL doesn't support DROP CONSTRAINT syntax for CHECK constraints
-- ALTER TABLE dns_records DROP CONSTRAINT dns_records_record_type_check;
2025-11-08 15:06:30 +08:00
-- MySQL doesn't support table-level CHECK constraints, using trigger instead
2025-11-08 17:19:48 +08:00
-- Remove DELIMITER commands for compatibility with migration tools
-- Create trigger for insert without DELIMITER
2025-11-08 15:06:30 +08:00
CREATE TRIGGER check_record_type_before_insert
BEFORE INSERT ON dns_records
FOR EACH ROW
IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type';
END IF;
2025-11-08 17:19:48 +08:00
-- Create trigger for update without DELIMITER
2025-11-08 15:06:30 +08:00
CREATE TRIGGER check_record_type_before_update
BEFORE UPDATE ON dns_records
FOR EACH ROW
IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type';
2025-11-08 17:19:48 +08:00
END IF;