| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  | import { BaseMigration } from './base-migration.ts'; | 
					
						
							|  |  |  | import { MigrationV1ToV2 } from './migration-v1-to-v2.ts'; | 
					
						
							|  |  |  | import { MigrationV3ToV4 } from './migration-v3-to-v4.ts'; | 
					
						
							| 
									
										
										
										
											2025-10-20 12:17:03 +00:00
										 |  |  | import { MigrationV4_0ToV4_1 } from './migration-v4.0-to-v4.1.ts'; | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  | import { logger } from '../logger.ts'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Migration runner | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Discovers all available migrations, sorts them by order, | 
					
						
							|  |  |  |  * and runs applicable migrations in sequence. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export class MigrationRunner { | 
					
						
							|  |  |  |   private migrations: BaseMigration[]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor() { | 
					
						
							|  |  |  |     // Register all migrations here
 | 
					
						
							|  |  |  |     this.migrations = [ | 
					
						
							|  |  |  |       new MigrationV1ToV2(), | 
					
						
							|  |  |  |       new MigrationV3ToV4(), | 
					
						
							| 
									
										
										
										
											2025-10-20 12:17:03 +00:00
										 |  |  |       new MigrationV4_0ToV4_1(), | 
					
						
							| 
									
										
										
										
											2025-10-20 12:14:02 +00:00
										 |  |  |       // Add future migrations here (v4.3, v4.4, etc.)
 | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-20 12:03:14 +00:00
										 |  |  |     // Sort by version order to ensure they run in sequence
 | 
					
						
							|  |  |  |     this.migrations.sort((a, b) => a.getVersionOrder() - b.getVersionOrder()); | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Run all applicable migrations on the config | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @param config - Raw configuration object to migrate | 
					
						
							|  |  |  |    * @returns Migrated configuration and whether migrations ran | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-10-20 12:27:02 +00:00
										 |  |  |   async run( | 
					
						
							|  |  |  |     config: Record<string, unknown>, | 
					
						
							|  |  |  |   ): Promise<{ config: Record<string, unknown>; migrated: boolean }> { | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |     let currentConfig = config; | 
					
						
							|  |  |  |     let anyMigrationsRan = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const migration of this.migrations) { | 
					
						
							|  |  |  |       const shouldRun = await migration.shouldRun(currentConfig); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (shouldRun) { | 
					
						
							| 
									
										
										
										
											2025-10-20 00:32:06 +00:00
										 |  |  |         // Only show "checking" message when we actually need to migrate
 | 
					
						
							|  |  |  |         if (!anyMigrationsRan) { | 
					
						
							|  |  |  |           logger.dim('Checking for required config migrations...'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |         logger.info(`Running ${migration.getName()}...`); | 
					
						
							|  |  |  |         currentConfig = await migration.migrate(currentConfig); | 
					
						
							|  |  |  |         anyMigrationsRan = true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (anyMigrationsRan) { | 
					
						
							|  |  |  |       logger.success('Configuration migrations complete'); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2025-10-20 00:32:06 +00:00
										 |  |  |       logger.success('config format ok'); | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       config: currentConfig, | 
					
						
							|  |  |  |       migrated: anyMigrationsRan, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Get all registered migrations | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @returns Array of all migrations sorted by order | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   getMigrations(): BaseMigration[] { | 
					
						
							|  |  |  |     return [...this.migrations]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |