This commit is contained in:
2025-11-08 15:06:30 +08:00
parent 27614f695f
commit e28e885e66
14 changed files with 99 additions and 78 deletions

View File

@@ -2,6 +2,26 @@
DELETE FROM dns_records WHERE record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT');
-- Now apply the constraint
ALTER TABLE dns_records DROP CONSTRAINT IF EXISTS dns_records_record_type_check;
ALTER TABLE dns_records ADD CONSTRAINT dns_records_record_type_check
CHECK (record_type IN ('A', 'AAAA', 'CNAME', 'TXT'));
ALTER TABLE dns_records DROP CONSTRAINT dns_records_record_type_check;
-- MySQL doesn't support table-level CHECK constraints, using trigger instead
DELIMITER //
CREATE TRIGGER check_record_type_before_insert
BEFORE INSERT ON dns_records
FOR EACH ROW
BEGIN
IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type';
END IF;
END;
//
CREATE TRIGGER check_record_type_before_update
BEFORE UPDATE ON dns_records
FOR EACH ROW
BEGIN
IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type';
END IF;
END;
//
DELIMITER ;