Fix adding DNS records by adding priority and provider record ID fields

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/a4984ce1-f551-4b2e-820f-afb1b97cacf1.jpg
This commit is contained in:
alphaeusmote
2025-04-11 02:05:23 +00:00
2 changed files with 27 additions and 21 deletions
+14 -9
View File
@@ -390,8 +390,8 @@ export class DatabaseStorage implements IStorage {
// Use raw SQL to select only columns that actually exist in the database // Use raw SQL to select only columns that actually exist in the database
const query = sql` const query = sql`
SELECT SELECT
id, domain_id, name, type, content, ttl, id, domain_id, name, type, content, ttl, priority,
is_active, auto_update, notes, last_updated, created_at provider_record_id, is_active, auto_update, notes, last_updated, created_at
FROM dns_records FROM dns_records
WHERE id = ${id} WHERE id = ${id}
`; `;
@@ -412,13 +412,14 @@ export class DatabaseStorage implements IStorage {
type: record.type, type: record.type,
content: record.content, content: record.content,
ttl: record.ttl, ttl: record.ttl,
priority: record.priority,
providerRecordId: record.provider_record_id,
isActive: record.is_active, isActive: record.is_active,
isAutoIP: record.auto_update, // Map auto_update to isAutoIP isAutoIP: record.auto_update, // Map auto_update to isAutoIP
notes: record.notes, notes: record.notes,
lastUpdated: record.last_updated, lastUpdated: record.last_updated,
createdAt: record.created_at, createdAt: record.created_at,
proxied: null, // Add missing fields with null values proxied: null // Field for frontend compatibility
providerId: null
}; };
} catch (error) { } catch (error) {
console.error("Error in getDnsRecord:", error); console.error("Error in getDnsRecord:", error);
@@ -474,21 +475,23 @@ export class DatabaseStorage implements IStorage {
// Create SQL query with proper parameterization using SQL template literals // Create SQL query with proper parameterization using SQL template literals
const queryText = sql` const queryText = sql`
INSERT INTO dns_records ( INSERT INTO dns_records (
domain_id, name, type, content, ttl, domain_id, name, type, content, ttl, priority,
is_active, auto_update, notes, last_updated is_active, auto_update, notes, last_updated, provider_record_id
) VALUES ( ) VALUES (
${validFields.domainId}, ${validFields.domainId},
${validFields.name}, ${validFields.name},
${validFields.type}, ${validFields.type},
${validFields.content}, ${validFields.content},
${validFields.ttl || 3600}, ${validFields.ttl || 3600},
${validFields.priority || 0},
${validFields.isActive !== undefined ? validFields.isActive : true}, ${validFields.isActive !== undefined ? validFields.isActive : true},
${isAutoIP !== undefined ? isAutoIP : false}, ${isAutoIP !== undefined ? isAutoIP : false},
${validFields.notes || null}, ${validFields.notes || null},
${new Date()} ${new Date()},
${null} -- provider_record_id will be populated when syncing with providers
) )
RETURNING id, domain_id, name, type, content, ttl, RETURNING id, domain_id, name, type, content, ttl, priority,
is_active, auto_update, notes, last_updated, created_at is_active, auto_update, notes, last_updated, created_at, provider_record_id
`; `;
// Execute the query directly with SQL template literal // Execute the query directly with SQL template literal
@@ -508,11 +511,13 @@ export class DatabaseStorage implements IStorage {
type: newRecord.type, type: newRecord.type,
content: newRecord.content, content: newRecord.content,
ttl: newRecord.ttl, ttl: newRecord.ttl,
priority: newRecord.priority,
isActive: newRecord.is_active, isActive: newRecord.is_active,
isAutoIP: newRecord.auto_update, // Map auto_update to isAutoIP isAutoIP: newRecord.auto_update, // Map auto_update to isAutoIP
notes: newRecord.notes, notes: newRecord.notes,
lastUpdated: newRecord.last_updated, lastUpdated: newRecord.last_updated,
createdAt: newRecord.created_at, createdAt: newRecord.created_at,
providerRecordId: newRecord.provider_record_id,
proxied: null, // Add missing fields with null values proxied: null, // Add missing fields with null values
providerId: null providerId: null
}; };
+13 -12
View File
@@ -58,11 +58,11 @@ export const dnsRecords = pgTable("dns_records", {
type: text("type").notNull(), type: text("type").notNull(),
content: text("content").notNull(), content: text("content").notNull(),
ttl: integer("ttl").default(3600), ttl: integer("ttl").default(3600),
proxied: boolean("proxied").default(false), priority: integer("priority"),
isActive: boolean("is_active").default(true).notNull(), providerRecordId: text("provider_record_id"),
isAutoIP: boolean("is_auto_ip").default(false).notNull(),
notes: text("notes"), notes: text("notes"),
providerId: uuid("provider_id").references(() => providers.id, { onDelete: "set null" }), isActive: boolean("is_active").default(true).notNull(),
isAutoIP: boolean("auto_update").default(false).notNull(), // renamed to match database column
lastUpdated: timestamp("last_updated"), lastUpdated: timestamp("last_updated"),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp("created_at").defaultNow().notNull(),
}); });
@@ -211,15 +211,19 @@ export const insertDnsRecordSchema = createInsertSchema(dnsRecords)
type: true, type: true,
content: true, content: true,
ttl: true, ttl: true,
proxied: true,
isActive: true, isActive: true,
isAutoIP: true, isAutoIP: true,
notes: true, notes: true,
providerId: true, priority: true,
providerRecordId: true,
}) })
.extend({ .extend({
// Override providerId to make it optional // Add proxied field for backward compatibility with frontend
providerId: z.string().uuid().nullable().optional(), proxied: z.boolean().nullable().optional(),
// Make priority optional with default value
priority: z.number().optional().default(0),
// Make provider record ID optional
providerRecordId: z.string().nullable().optional(),
}); });
export const insertProviderSchema = createInsertSchema(providers).pick({ export const insertProviderSchema = createInsertSchema(providers).pick({
@@ -382,10 +386,7 @@ export const dnsRecordsRelations = relations(dnsRecords, ({ one, many }) => ({
fields: [dnsRecords.domainId], fields: [dnsRecords.domainId],
references: [domains.id], references: [domains.id],
}), }),
provider: one(providers, { // Provider is now referenced through the domain, not directly
fields: [dnsRecords.providerId],
references: [providers.id],
}),
history: many(dnsHistory), history: many(dnsHistory),
})); }));