refactor(ElectricClient): update debug mode for electricSync to activate only in development environment

This commit is contained in:
Anish Sarkar 2026-01-30 17:20:11 +05:30
parent 6aa3d88f68
commit 8ca1b2b90a

View file

@ -165,8 +165,8 @@ export async function initElectric(userId: string): Promise<ElectricClient> {
dataDir: dbName, dataDir: dbName,
relaxedDurability: true, relaxedDurability: true,
extensions: { extensions: {
// Enable debug mode in electricSync to see detailed sync logs // Enable debug mode in electricSync only in development
electric: electricSync({ debug: true }), electric: electricSync({ debug: process.env.NODE_ENV === "development" }),
live, // Enable live queries for real-time updates live, // Enable live queries for real-time updates
}, },
}); });
@ -341,8 +341,8 @@ export async function initElectric(userId: string): Promise<ElectricClient> {
console.log("[Electric] Where clause:", where, "Validated:", validatedWhere); console.log("[Electric] Where clause:", where, "Validated:", validatedWhere);
try { try {
// Debug: Test Electric SQL connection directly first // Debug: Test Electric SQL connection directly first (DEV ONLY - skipped in production)
// Use validatedWhere to ensure proper URL encoding if (process.env.NODE_ENV === "development") {
const testUrl = `${electricUrl}/v1/shape?table=${table}&offset=-1${validatedWhere ? `&where=${encodeURIComponent(validatedWhere)}` : ""}`; const testUrl = `${electricUrl}/v1/shape?table=${table}&offset=-1${validatedWhere ? `&where=${encodeURIComponent(validatedWhere)}` : ""}`;
console.log("[Electric] Testing Electric SQL directly:", testUrl); console.log("[Electric] Testing Electric SQL directly:", testUrl);
try { try {
@ -362,6 +362,7 @@ export async function initElectric(userId: string): Promise<ElectricClient> {
} catch (testErr) { } catch (testErr) {
console.error("[Electric] Direct Electric SQL test failed:", testErr); console.error("[Electric] Direct Electric SQL test failed:", testErr);
} }
}
// Use PGlite's electric sync plugin to sync the shape // Use PGlite's electric sync plugin to sync the shape
// According to Electric SQL docs, the shape config uses params for table, where, columns // According to Electric SQL docs, the shape config uses params for table, where, columns