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
parent 300f0462c2
commit 0eec01aca2
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
const query = sql`
SELECT
id, domain_id, name, type, content, ttl,
is_active, auto_update, notes, last_updated, created_at
id, domain_id, name, type, content, ttl, priority,
provider_record_id, is_active, auto_update, notes, last_updated, created_at
FROM dns_records
WHERE id = ${id}
`;
@@ -412,13 +412,14 @@ export class DatabaseStorage implements IStorage {
type: record.type,
content: record.content,
ttl: record.ttl,
priority: record.priority,
providerRecordId: record.provider_record_id,
isActive: record.is_active,
isAutoIP: record.auto_update, // Map auto_update to isAutoIP
notes: record.notes,
lastUpdated: record.last_updated,
createdAt: record.created_at,
proxied: null, // Add missing fields with null values
providerId: null
proxied: null // Field for frontend compatibility
};
} catch (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
const queryText = sql`
INSERT INTO dns_records (
domain_id, name, type, content, ttl,
is_active, auto_update, notes, last_updated
domain_id, name, type, content, ttl, priority,
is_active, auto_update, notes, last_updated, provider_record_id
) VALUES (
${validFields.domainId},
${validFields.name},
${validFields.type},
${validFields.content},
${validFields.ttl || 3600},
${validFields.priority || 0},
${validFields.isActive !== undefined ? validFields.isActive : true},
${isAutoIP !== undefined ? isAutoIP : false},
${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,
is_active, auto_update, notes, last_updated, created_at
RETURNING id, domain_id, name, type, content, ttl, priority,
is_active, auto_update, notes, last_updated, created_at, provider_record_id
`;
// Execute the query directly with SQL template literal
@@ -508,11 +511,13 @@ export class DatabaseStorage implements IStorage {
type: newRecord.type,
content: newRecord.content,
ttl: newRecord.ttl,
priority: newRecord.priority,
isActive: newRecord.is_active,
isAutoIP: newRecord.auto_update, // Map auto_update to isAutoIP
notes: newRecord.notes,
lastUpdated: newRecord.last_updated,
createdAt: newRecord.created_at,
providerRecordId: newRecord.provider_record_id,
proxied: null, // Add missing fields with null values
providerId: null
};
+13 -12
View File
@@ -58,11 +58,11 @@ export const dnsRecords = pgTable("dns_records", {
type: text("type").notNull(),
content: text("content").notNull(),
ttl: integer("ttl").default(3600),
proxied: boolean("proxied").default(false),
isActive: boolean("is_active").default(true).notNull(),
isAutoIP: boolean("is_auto_ip").default(false).notNull(),
priority: integer("priority"),
providerRecordId: text("provider_record_id"),
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"),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
@@ -211,15 +211,19 @@ export const insertDnsRecordSchema = createInsertSchema(dnsRecords)
type: true,
content: true,
ttl: true,
proxied: true,
isActive: true,
isAutoIP: true,
notes: true,
providerId: true,
priority: true,
providerRecordId: true,
})
.extend({
// Override providerId to make it optional
providerId: z.string().uuid().nullable().optional(),
// Add proxied field for backward compatibility with frontend
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({
@@ -382,10 +386,7 @@ export const dnsRecordsRelations = relations(dnsRecords, ({ one, many }) => ({
fields: [dnsRecords.domainId],
references: [domains.id],
}),
provider: one(providers, {
fields: [dnsRecords.providerId],
references: [providers.id],
}),
// Provider is now referenced through the domain, not directly
history: many(dnsHistory),
}));