| 
						
						
							
								
							
						
						
					 | 
					@ -511,7 +511,7 @@ export async function runMigrations<T>( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  try { | 
					 | 
					 | 
					  try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    migrationLog("📋 [Migration] Starting migration process..."); | 
					 | 
					 | 
					    migrationLog("📋 [Migration] Starting migration process..."); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    // Step 1: Create migrations table if it doesn't exist
 | 
					 | 
					 | 
					    // Create migrations table if it doesn't exist
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    // Note: We use IF NOT EXISTS here because this is infrastructure, not a business migration
 | 
					 | 
					 | 
					    // Note: We use IF NOT EXISTS here because this is infrastructure, not a business migration
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    await sqlExec(` | 
					 | 
					 | 
					    await sqlExec(` | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      CREATE TABLE IF NOT EXISTS migrations ( | 
					 | 
					 | 
					      CREATE TABLE IF NOT EXISTS migrations ( | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -520,41 +520,14 @@ export async function runMigrations<T>( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      ); | 
					 | 
					 | 
					      ); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    `);
 | 
					 | 
					 | 
					    `);
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    // Step 2: Handle migration name changes (master branch compatibility)
 | 
					 | 
					 | 
					    // Step 2: Get list of already applied migrations
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					    // Map old migration names to new ones
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    const migrationNameMap = new Map([ | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      // No longer needed - migrations consolidated into single 003
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    ]); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    // Update any old migration names to new ones
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    for (const [oldName, newName] of migrationNameMap) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      try { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        await sqlExec("UPDATE migrations SET name = ? WHERE name = ?", [ | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          newName, | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          oldName, | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        ]); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        if ( | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          await sqlQuery("SELECT 1 FROM migrations WHERE name = ? LIMIT 1", [ | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            newName, | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          ]) | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        ) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          migrationLog( | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            `🔄 [Migration] Renamed migration: ${oldName} → ${newName}`, | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          ); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      } catch (error) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        // Ignore errors - migration might not exist
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    // Step 3: Get list of already applied migrations
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    const appliedMigrationsResult = await sqlQuery( | 
					 | 
					 | 
					    const appliedMigrationsResult = await sqlQuery( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      "SELECT name FROM migrations", | 
					 | 
					 | 
					      "SELECT name FROM migrations", | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    ); | 
					 | 
					 | 
					    ); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    const appliedMigrations = extractMigrationNames(appliedMigrationsResult); | 
					 | 
					 | 
					    const appliedMigrations = extractMigrationNames(appliedMigrationsResult); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    // Step 4: Get all registered migrations
 | 
					 | 
					 | 
					    // Step 3: Get all registered migrations
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    const migrations = migrationRegistry.getMigrations(); | 
					 | 
					 | 
					    const migrations = migrationRegistry.getMigrations(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    if (migrations.length === 0) { | 
					 | 
					 | 
					    if (migrations.length === 0) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -569,7 +542,7 @@ export async function runMigrations<T>( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    let appliedCount = 0; | 
					 | 
					 | 
					    let appliedCount = 0; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    let skippedCount = 0; | 
					 | 
					 | 
					    let skippedCount = 0; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    // Step 5: Process each migration
 | 
					 | 
					 | 
					    // Step 4: Process each migration
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    for (const migration of migrations) { | 
					 | 
					 | 
					    for (const migration of migrations) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      // Check 1: Is it recorded as applied in migrations table?
 | 
					 | 
					 | 
					      // Check 1: Is it recorded as applied in migrations table?
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      const isRecordedAsApplied = appliedMigrations.has(migration.name); | 
					 | 
					 | 
					      const isRecordedAsApplied = appliedMigrations.has(migration.name); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -719,7 +692,7 @@ export async function runMigrations<T>( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      } | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    // Step 5: Final validation - verify all migrations are properly recorded
 | 
					 | 
					 | 
					    // Step 6: Final validation - verify all migrations are properly recorded
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    const finalMigrationsResult = await sqlQuery("SELECT name FROM migrations"); | 
					 | 
					 | 
					    const finalMigrationsResult = await sqlQuery("SELECT name FROM migrations"); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    const finalAppliedMigrations = extractMigrationNames(finalMigrationsResult); | 
					 | 
					 | 
					    const finalAppliedMigrations = extractMigrationNames(finalMigrationsResult); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |