refactor(migration): simplify logging by removing specialized migrationLog
- Remove isDevelopment environment checks and migrationLog variable - Replace conditional logging with consistent logger.debug() calls - Remove development-only validation restrictions - Maintain all error handling and warning messages - Let existing logger handle development mode behavior automatically This simplifies the migration service logging while preserving all functionality. The existing logger already handles development vs production mode appropriately.
This commit is contained in:
@@ -599,16 +599,8 @@ export async function runMigrations<T>(
|
||||
sqlQuery: (sql: string, params?: unknown[]) => Promise<T>,
|
||||
extractMigrationNames: (result: T) => Set<string>,
|
||||
): Promise<void> {
|
||||
const isDevelopment = process.env.VITE_PLATFORM === "development";
|
||||
|
||||
// Use debug level for routine migration messages in development
|
||||
const migrationLog = isDevelopment ? logger.debug : logger.log;
|
||||
|
||||
try {
|
||||
// Only log essential migration start in production
|
||||
if (isDevelopment) {
|
||||
migrationLog("📋 [Migration] Starting migration process...");
|
||||
}
|
||||
logger.debug("📋 [Migration] Starting migration process...");
|
||||
|
||||
// Create migrations table if it doesn't exist
|
||||
// Note: We use IF NOT EXISTS here because this is infrastructure, not a business migration
|
||||
@@ -635,11 +627,9 @@ export async function runMigrations<T>(
|
||||
}
|
||||
|
||||
// Only log migration counts in development
|
||||
if (isDevelopment) {
|
||||
migrationLog(
|
||||
`📊 [Migration] Found ${migrations.length} total migrations, ${appliedMigrations.size} already applied`,
|
||||
);
|
||||
}
|
||||
logger.debug(
|
||||
`📊 [Migration] Found ${migrations.length} total migrations, ${appliedMigrations.size} already applied`,
|
||||
);
|
||||
|
||||
let appliedCount = 0;
|
||||
let skippedCount = 0;
|
||||
@@ -664,12 +654,9 @@ export async function runMigrations<T>(
|
||||
await sqlExec("INSERT INTO migrations (name) VALUES (?)", [
|
||||
migration.name,
|
||||
]);
|
||||
// Only log schema marking in development
|
||||
if (isDevelopment) {
|
||||
migrationLog(
|
||||
`✅ [Migration] Marked existing schema as applied: ${migration.name}`,
|
||||
);
|
||||
}
|
||||
logger.debug(
|
||||
`✅ [Migration] Marked existing schema as applied: ${migration.name}`,
|
||||
);
|
||||
skippedCount++;
|
||||
continue;
|
||||
} catch (insertError) {
|
||||
@@ -681,40 +668,32 @@ export async function runMigrations<T>(
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the migration - only log in development
|
||||
if (isDevelopment) {
|
||||
migrationLog(`🔄 [Migration] Applying migration: ${migration.name}`);
|
||||
}
|
||||
// Apply the migration
|
||||
logger.debug(`🔄 [Migration] Applying migration: ${migration.name}`);
|
||||
|
||||
try {
|
||||
// Execute the migration SQL as single atomic operation
|
||||
if (isDevelopment) {
|
||||
migrationLog(`🔧 [Migration] Executing SQL for: ${migration.name}`);
|
||||
migrationLog(`🔧 [Migration] SQL content: ${migration.sql}`);
|
||||
}
|
||||
logger.debug(`🔧 [Migration] Executing SQL for: ${migration.name}`);
|
||||
logger.debug(`🔧 [Migration] SQL content: ${migration.sql}`);
|
||||
|
||||
// Execute the migration SQL directly - it should be atomic
|
||||
// The SQL itself should handle any necessary transactions
|
||||
const execResult = await sqlExec(migration.sql);
|
||||
|
||||
if (isDevelopment) {
|
||||
migrationLog(
|
||||
`🔧 [Migration] SQL execution result: ${JSON.stringify(execResult)}`,
|
||||
);
|
||||
}
|
||||
logger.debug(
|
||||
`🔧 [Migration] SQL execution result: ${JSON.stringify(execResult)}`,
|
||||
);
|
||||
|
||||
// Validate the migration was applied correctly (only in development)
|
||||
if (isDevelopment) {
|
||||
const validation = await validateMigrationApplication(
|
||||
migration,
|
||||
sqlQuery,
|
||||
// Validate the migration was applied correctly
|
||||
const validation = await validateMigrationApplication(
|
||||
migration,
|
||||
sqlQuery,
|
||||
);
|
||||
if (!validation.isValid) {
|
||||
logger.warn(
|
||||
`⚠️ [Migration] Validation failed for ${migration.name}:`,
|
||||
validation.errors,
|
||||
);
|
||||
if (!validation.isValid) {
|
||||
logger.warn(
|
||||
`⚠️ [Migration] Validation failed for ${migration.name}:`,
|
||||
validation.errors,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Record that the migration was applied
|
||||
@@ -722,12 +701,7 @@ export async function runMigrations<T>(
|
||||
migration.name,
|
||||
]);
|
||||
|
||||
// Only log success in development
|
||||
if (isDevelopment) {
|
||||
migrationLog(
|
||||
`🎉 [Migration] Successfully applied: ${migration.name}`,
|
||||
);
|
||||
}
|
||||
logger.debug(`🎉 [Migration] Successfully applied: ${migration.name}`);
|
||||
appliedCount++;
|
||||
} catch (error) {
|
||||
logger.error(`❌ [Migration] Error applying ${migration.name}:`, error);
|
||||
@@ -765,7 +739,7 @@ export async function runMigrations<T>(
|
||||
(errorMessage.includes("table") &&
|
||||
errorMessage.includes("already exists"))
|
||||
) {
|
||||
migrationLog(
|
||||
logger.debug(
|
||||
`⚠️ [Migration] ${migration.name} appears already applied (${errorMessage}). Validating and marking as complete.`,
|
||||
);
|
||||
|
||||
@@ -788,7 +762,7 @@ export async function runMigrations<T>(
|
||||
await sqlExec("INSERT INTO migrations (name) VALUES (?)", [
|
||||
migration.name,
|
||||
]);
|
||||
migrationLog(`✅ [Migration] Marked as applied: ${migration.name}`);
|
||||
logger.debug(`✅ [Migration] Marked as applied: ${migration.name}`);
|
||||
appliedCount++;
|
||||
} catch (insertError) {
|
||||
// If we can't insert the migration record, log it but don't fail
|
||||
@@ -825,11 +799,9 @@ export async function runMigrations<T>(
|
||||
}
|
||||
|
||||
// Only show completion message in development
|
||||
if (isDevelopment) {
|
||||
logger.log(
|
||||
`🎉 [Migration] Migration process complete! Summary: ${appliedCount} applied, ${skippedCount} skipped`,
|
||||
);
|
||||
}
|
||||
logger.debug(
|
||||
`🎉 [Migration] Migration process complete! Summary: ${appliedCount} applied, ${skippedCount} skipped`,
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error("\n💥 [Migration] Migration process failed:", error);
|
||||
logger.error("[MigrationService] Migration process failed:", error);
|
||||
|
||||
Reference in New Issue
Block a user