1// Script to create missing Cloudflare DNS records for all tenants
3require('dotenv').config();
4const { createSubdomain } = require('../services/cloudflare');
5const pool = require('../services/db');
10async function seedCloudflareDNS() {
11 const target = 'demo.everydaytech.au';
12 const zoneName = process.env.ZONE_NAME || 'everydaytech.au';
13 const tenants = await pool.query('SELECT subdomain FROM tenants WHERE status = $1', ['active']);
15 for (const row of tenants.rows) {
16 const subdomain = row.subdomain;
17 const fqdn = `${subdomain}.${zoneName}`;
19 console.log(`Creating DNS for: ${fqdn}`);
20 await createSubdomain(subdomain, target);
21 console.log(`✅ DNS created for ${fqdn}`);
23 if (err.code === 'SUBDOMAIN_EXISTS') {
24 console.log(`🔁 DNS already exists for ${fqdn}`);
26 console.error(`❌ Failed for ${fqdn}:`, err.message);