diff --git a/src/App.vue b/src/App.vue index df47c4a4..81a5803f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -392,43 +392,33 @@ export default class App extends Vue { async turnOffNotifications( notification: NotificationIface, ): Promise { - logger.log("Starting turnOffNotifications..."); let subscription: PushSubscriptionJSON | null = null; let allGoingOff = false; try { - logger.log("Retrieving settings for the active account..."); const settings: Settings = await databaseUtil.retrieveSettingsForActiveAccount(); - logger.log("Retrieved settings:", settings); const notifyingNewActivity = !!settings?.notifyingNewActivityTime; const notifyingReminder = !!settings?.notifyingReminderTime; if (!notifyingNewActivity || !notifyingReminder) { allGoingOff = true; - logger.log("Both notifications are being turned off."); } - logger.log("Checking service worker readiness..."); await navigator.serviceWorker?.ready .then((registration) => { - logger.log("Service worker is ready. Fetching subscription..."); return registration.pushManager.getSubscription(); }) .then(async (subscript: PushSubscription | null) => { if (subscript) { subscription = subscript.toJSON(); - logger.log("PushSubscription retrieved:", subscription); if (allGoingOff) { - logger.log("Unsubscribing from push notifications..."); await subscript.unsubscribe(); - logger.log("Successfully unsubscribed."); } } else { logConsoleAndDb("Subscription object is not available."); - logger.log("No subscription found."); } }) .catch((error) => { @@ -441,7 +431,6 @@ export default class App extends Vue { }); if (!subscription) { - logger.log("No subscription available. Notifying user..."); this.$notify( { group: "alert", @@ -451,21 +440,14 @@ export default class App extends Vue { }, 5000, ); - logger.log("Exiting as there is no subscription to process."); return true; } const serverSubscription = { - ...subscription, + ...(subscription as PushSubscriptionJSON), + ...(allGoingOff ? {} : { notifyType: notification.title }), }; - if (!allGoingOff) { - serverSubscription["notifyType"] = notification.title; - logger.log( - `Server subscription updated with notifyType: ${notification.title}`, - ); - } - logger.log("Sending unsubscribe request to the server..."); const pushServerSuccess = await fetch("/web-push/unsubscribe", { method: "POST", headers: { @@ -482,7 +464,6 @@ export default class App extends Vue { ); logger.error("Push server error response:", errorBody); } - logger.log(`Server response status: ${response.status}`); return response.ok; }) .catch((error) => { @@ -497,7 +478,6 @@ export default class App extends Vue { const message = pushServerSuccess ? "Notification is off." : "Notification is still on. Try to turn it off again."; - logger.log("Server response processed. Message:", message); this.$notify( { @@ -510,14 +490,9 @@ export default class App extends Vue { ); if (notification.callback) { - logger.log("Executing notification callback..."); notification.callback(pushServerSuccess); } - logger.log( - "Completed turnOffNotifications with success:", - pushServerSuccess, - ); return pushServerSuccess; } catch (error) { logConsoleAndDb( diff --git a/src/services/migrationService.ts b/src/services/migrationService.ts index 821fe186..46853f33 100644 --- a/src/services/migrationService.ts +++ b/src/services/migrationService.ts @@ -253,7 +253,7 @@ async function validateMigrationApplication( await sqlQuery( `SELECT name FROM sqlite_master WHERE type='table' AND name='${tableName}'`, ); - logger.log(`āœ… [Migration-Validation] Table ${tableName} exists`); + // Reduced logging - only log on error } catch (error) { validation.isValid = false; validation.errors.push(`Table ${tableName} missing`); @@ -269,9 +269,7 @@ async function validateMigrationApplication( try { await sqlQuery(`SELECT iViewContent FROM contacts LIMIT 1`); validation.hasExpectedColumns = true; - logger.log( - `āœ… [Migration-Validation] Column iViewContent exists in contacts table`, - ); + // Reduced logging - only log on error } catch (error) { validation.isValid = false; validation.errors.push( @@ -333,18 +331,16 @@ async function isSchemaAlreadyPresent( const hasTable = result?.values?.length > 0 || (Array.isArray(result) && result.length > 0); - logger.log( - `šŸ” [Migration-Schema] Initial migration schema check - accounts table exists: ${hasTable}`, - ); + // Reduced logging - only log on error return hasTable; } else if (migration.name === "002_add_iViewContent_to_contacts") { // Check if iViewContent column exists in contacts table try { await sqlQuery(`SELECT iViewContent FROM contacts LIMIT 1`); - logger.log(`šŸ” [Migration-Schema] iViewContent column already exists`); + // Reduced logging - only log on error return true; } catch (error) { - logger.log(`šŸ” [Migration-Schema] iViewContent column does not exist`); + // Reduced logging - only log on error return false; } } @@ -354,7 +350,7 @@ async function isSchemaAlreadyPresent( // // Check if future migration schema already exists // } } catch (error) { - logger.log( + logger.error( `šŸ” [Migration-Schema] Schema check failed for ${migration.name}, assuming not present:`, error, ); @@ -413,83 +409,55 @@ export async function runMigrations( // Step 1: Create migrations table if it doesn't exist // Note: We use IF NOT EXISTS here because this is infrastructure, not a business migration - logger.log( - "šŸ”§ [Migration] Creating migrations table if it doesn't exist...", - ); await sqlExec(` CREATE TABLE IF NOT EXISTS migrations ( name TEXT PRIMARY KEY, applied_at TEXT DEFAULT CURRENT_TIMESTAMP ); `); - logger.log("āœ… [Migration] Migrations table ready"); // Step 2: Get list of already applied migrations - logger.log("šŸ” [Migration] Querying existing migrations..."); const appliedMigrationsResult = await sqlQuery( "SELECT name FROM migrations", ); - logger.log("šŸ“Š [Migration] Raw query result:", appliedMigrationsResult); const appliedMigrations = extractMigrationNames(appliedMigrationsResult); - logger.log( - "šŸ“‹ [Migration] Extracted applied migrations:", - Array.from(appliedMigrations), - ); // Step 3: Get all registered migrations const migrations = migrationRegistry.getMigrations(); if (migrations.length === 0) { logger.warn("āš ļø [Migration] No migrations registered"); - logger.warn("[MigrationService] No migrations registered"); return; } logger.log( `šŸ“Š [Migration] Found ${migrations.length} total migrations, ${appliedMigrations.size} already applied`, ); - logger.log( - `šŸ“ [Migration] Registered migrations: ${migrations.map((m) => m.name).join(", ")}`, - ); let appliedCount = 0; let skippedCount = 0; // Step 4: Process each migration for (const migration of migrations) { - logger.log(`\nšŸ” [Migration] Processing migration: ${migration.name}`); - // Check 1: Is it recorded as applied in migrations table? const isRecordedAsApplied = appliedMigrations.has(migration.name); // Check 2: Does the schema already exist in the database? const isSchemaPresent = await isSchemaAlreadyPresent(migration, sqlQuery); - logger.log( - `šŸ” [Migration] ${migration.name} - Recorded: ${isRecordedAsApplied}, Schema: ${isSchemaPresent}`, - ); - // Skip if already recorded as applied if (isRecordedAsApplied) { - logger.log( - `ā­ļø [Migration] Skipping already applied: ${migration.name}`, - ); skippedCount++; continue; } // Handle case where schema exists but isn't recorded if (isSchemaPresent) { - logger.log( - `šŸ”„ [Migration] Schema exists but not recorded. Marking ${migration.name} as applied...`, - ); try { - const insertResult = await sqlExec( - "INSERT INTO migrations (name) VALUES (?)", - [migration.name], - ); - logger.log(`āœ… [Migration] Migration record inserted:`, insertResult); + await sqlExec("INSERT INTO migrations (name) VALUES (?)", [ + migration.name, + ]); logger.log( `āœ… [Migration] Marked existing schema as applied: ${migration.name}`, ); @@ -509,11 +477,7 @@ export async function runMigrations( try { // Execute the migration SQL - logger.log(`šŸ”§ [Migration] Executing SQL for ${migration.name}...`); await sqlExec(migration.sql); - logger.log( - `āœ… [Migration] SQL executed successfully for ${migration.name}`, - ); // Validate the migration was applied correctly const validation = await validateMigrationApplication( @@ -525,26 +489,14 @@ export async function runMigrations( `āš ļø [Migration] Validation failed for ${migration.name}:`, validation.errors, ); - } else { - logger.log( - `āœ… [Migration] Schema validation passed for ${migration.name}`, - ); } // Record that the migration was applied - logger.log( - `šŸ“ [Migration] Recording migration ${migration.name} as applied...`, - ); - const insertResult = await sqlExec( - "INSERT INTO migrations (name) VALUES (?)", - [migration.name], - ); - logger.log(`āœ… [Migration] Migration record inserted:`, insertResult); + await sqlExec("INSERT INTO migrations (name) VALUES (?)", [ + migration.name, + ]); logger.log(`šŸŽ‰ [Migration] Successfully applied: ${migration.name}`); - logger.info( - `[MigrationService] Successfully applied migration: ${migration.name}`, - ); appliedCount++; } catch (error) { logger.error(`āŒ [Migration] Error applying ${migration.name}:`, error); @@ -569,11 +521,7 @@ export async function runMigrations( migration, sqlQuery, ); - if (validation.isValid) { - logger.log( - `āœ… [Migration] Schema validation passed for ${migration.name}`, - ); - } else { + if (!validation.isValid) { logger.warn( `āš ļø [Migration] Schema validation failed for ${migration.name}:`, validation.errors, @@ -582,21 +530,10 @@ export async function runMigrations( // Mark the migration as applied since the schema change already exists try { - logger.log( - `šŸ“ [Migration] Attempting to record ${migration.name} as applied despite error...`, - ); - const insertResult = await sqlExec( - "INSERT INTO migrations (name) VALUES (?)", - [migration.name], - ); - logger.log( - `āœ… [Migration] Migration record inserted after error:`, - insertResult, - ); + await sqlExec("INSERT INTO migrations (name) VALUES (?)", [ + migration.name, + ]); logger.log(`āœ… [Migration] Marked as applied: ${migration.name}`); - logger.info( - `[MigrationService] Successfully marked migration as applied: ${migration.name}`, - ); appliedCount++; } catch (insertError) { // If we can't insert the migration record, log it but don't fail @@ -604,10 +541,6 @@ export async function runMigrations( `āš ļø [Migration] Could not record ${migration.name} as applied:`, insertError, ); - logger.warn( - `[MigrationService] Could not record migration ${migration.name} as applied:`, - insertError, - ); } } else { // For other types of errors, still fail the migration @@ -615,25 +548,14 @@ export async function runMigrations( `āŒ [Migration] Failed to apply ${migration.name}:`, error, ); - logger.error( - `[MigrationService] Failed to apply migration ${migration.name}:`, - error, - ); throw new Error(`Migration ${migration.name} failed: ${error}`); } } } // Step 5: Final validation - verify all migrations are properly recorded - logger.log( - "\nšŸ” [Migration] Final validation - checking migrations table...", - ); const finalMigrationsResult = await sqlQuery("SELECT name FROM migrations"); const finalAppliedMigrations = extractMigrationNames(finalMigrationsResult); - logger.log( - "šŸ“‹ [Migration] Final applied migrations:", - Array.from(finalAppliedMigrations), - ); // Check that all expected migrations are recorded const expectedMigrations = new Set(migrations.map((m) => m.name)); @@ -645,17 +567,10 @@ export async function runMigrations( logger.warn( `āš ļø [Migration] Missing migration records: ${missingMigrations.join(", ")}`, ); - logger.warn( - `[MigrationService] Missing migration records: ${missingMigrations.join(", ")}`, - ); } - logger.log(`\nšŸŽ‰ [Migration] Migration process complete!`); logger.log( - `šŸ“Š [Migration] Summary: Applied: ${appliedCount}, Skipped: ${skippedCount}, Total: ${migrations.length}`, - ); - logger.info( - `[MigrationService] Migration process complete. Applied: ${appliedCount}, Skipped: ${skippedCount}`, + `šŸŽ‰ [Migration] Migration process complete! Summary: ${appliedCount} applied, ${skippedCount} skipped`, ); } catch (error) { logger.error("\nšŸ’„ [Migration] Migration process failed:", error);