This commit is contained in:
2025-11-08 17:19:48 +08:00
parent 0d93cfd874
commit f9f05a6dbf
2 changed files with 10 additions and 18 deletions

View File

@@ -6,23 +6,20 @@ DELETE FROM dns_records WHERE record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT');
-- ALTER TABLE dns_records DROP CONSTRAINT dns_records_record_type_check; -- ALTER TABLE dns_records DROP CONSTRAINT dns_records_record_type_check;
-- MySQL doesn't support table-level CHECK constraints, using trigger instead -- MySQL doesn't support table-level CHECK constraints, using trigger instead
DELIMITER // -- Remove DELIMITER commands for compatibility with migration tools
-- Create trigger for insert without DELIMITER
CREATE TRIGGER check_record_type_before_insert CREATE TRIGGER check_record_type_before_insert
BEFORE INSERT ON dns_records BEFORE INSERT ON dns_records
FOR EACH ROW FOR EACH ROW
BEGIN
IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type'; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type';
END IF; END IF;
END;
// -- Create trigger for update without DELIMITER
CREATE TRIGGER check_record_type_before_update CREATE TRIGGER check_record_type_before_update
BEFORE UPDATE ON dns_records BEFORE UPDATE ON dns_records
FOR EACH ROW FOR EACH ROW
BEGIN
IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN IF NEW.record_type NOT IN ('A', 'AAAA', 'CNAME', 'TXT') THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type'; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Invalid record type';
END IF; END IF;
END;
//
DELIMITER ;

View File

@@ -14,13 +14,8 @@ CREATE INDEX idx_domain_crawl_status_next_crawl ON domain_crawl_status(next_craw
CREATE INDEX idx_domain_crawl_status_status ON domain_crawl_status(crawl_status); CREATE INDEX idx_domain_crawl_status_status ON domain_crawl_status(crawl_status);
-- Function to update the updated_at column -- Function to update the updated_at column
-- MySQL trigger to update updated_at column -- MySQL trigger to update updated_at column - simplified without DELIMITER
DELIMITER //
CREATE TRIGGER update_domain_crawl_status_updated_at CREATE TRIGGER update_domain_crawl_status_updated_at
BEFORE UPDATE ON domain_crawl_status BEFORE UPDATE ON domain_crawl_status
FOR EACH ROW FOR EACH ROW
BEGIN SET NEW.updated_at = CURRENT_TIMESTAMP;
SET NEW.updated_at = CURRENT_TIMESTAMP;
END;
//
DELIMITER ;