You've already forked directdnsonly
CoreDNS MySQL (cybercinch fork) expects '@' for zone-apex references in record RDATA. Storing the full FQDN (e.g. 'ithome.net.nz.') caused CoreDNS to strip the zone suffix and serve 'MX 0 .' / 'CNAME .' instead of the correct apex target. - Add _relativize_name(): converts zone FQDN → '@', in-zone subdomains → relative label, external FQDNs left unchanged. Handles both already- relativized output from dnspython ($ORIGIN present) and absolute FQDNs when $ORIGIN is absent from the zone file. - Replace _normalize_cname_data() with _relativize_name(); add _normalize_mx_data(), _normalize_ns_data(), _normalize_srv_data() using the same helper. - _parse_zone_to_record_set() now normalizes MX, NS, SRV alongside CNAME. - _ensure_zone_exists() sets managed_by='directadmin' on create and back-fills NULL rows from pre-migration installs. - Zone.managed_by changed to nullable=True to match ALTER TABLE migration where existing rows have no value. - schema/coredns_mysql.sql updated to reflect actual two-table schema with managed_by column and migration comment. - 11 new tests (130 total, all passing).
34 lines
1.3 KiB
SQL
34 lines
1.3 KiB
SQL
-- DirectDNSOnly — CoreDNS MySQL schema
|
|
-- Compatible with cybercinch/coredns_mysql_extend
|
|
--
|
|
-- managed_by values:
|
|
-- 'directadmin' zone is managed via directdnsonly / DirectAdmin push
|
|
-- 'direct' zone was created directly (not via DA)
|
|
-- NULL legacy row created before this column was added
|
|
|
|
CREATE TABLE IF NOT EXISTS `zones` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`zone_name` varchar(255) NOT NULL,
|
|
`managed_by` varchar(255) DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uq_zone_name` (`zone_name`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE IF NOT EXISTS `records` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`zone_id` int(11) NOT NULL,
|
|
`hostname` varchar(255) NOT NULL,
|
|
`type` varchar(10) NOT NULL,
|
|
`data` text NOT NULL,
|
|
`ttl` int(11) DEFAULT NULL,
|
|
`online` tinyint(1) NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_zone_id` (`zone_id`),
|
|
KEY `idx_hostname` (`hostname`),
|
|
CONSTRAINT `fk_records_zone` FOREIGN KEY (`zone_id`) REFERENCES `zones` (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
-- Migration: add managed_by to an existing installation
|
|
-- ALTER TABLE `zones` ADD COLUMN `managed_by` varchar(255) DEFAULT NULL;
|
|
-- UPDATE `zones` SET `managed_by` = 'directadmin' WHERE `managed_by` IS NULL;
|