UNPKG

supa-seed

Version:

A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support

219 lines 6.36 kB
/** * Configuration Migration System * Migrates existing configs from hardcoded framework assumptions to schema-first format * Ensures backward compatibility while encouraging adoption of new architecture */ import type { createClient } from '@supabase/supabase-js'; type SupabaseClient = ReturnType<typeof createClient>; export interface LegacyConfig { supabaseUrl: string; supabaseServiceKey: string; environment: string; userCount: number; setupsPerUser: number; imagesPerSetup: number; enableRealImages: boolean; seed: string; emailDomain: string; domain?: string; createStandardTestEmails?: boolean; createTeamAccounts?: boolean; testUserPassword?: string; schema?: { framework?: string; primaryUserTable?: string; userTable?: { name: string; emailField?: string; nameField?: string; pictureField?: string; bioField?: string; usernameField?: string; }; setupTable?: { name: string; userField?: string; titleField?: string; descriptionField?: string; categoryField?: string; publicField?: string; }; baseTemplateTable?: { name: string; typeField?: string; makeField?: string; modelField?: string; yearField?: string; descriptionField?: string; }; optionalTables?: Record<string, any>; }; storage?: { buckets?: Record<string, string>; autoCreate?: boolean; }; seeders?: { enabled?: string[]; skip?: string[]; }; } export interface ModernConfig { version: '2.1.0'; supabaseUrl: string; supabaseServiceKey: string; environment: string; seeding: { userCount: number; setupsPerUser: number; imagesPerSetup: number; enableRealImages: boolean; seed: string; emailDomain: string; domain: string; testUserPassword: string; enableSchemaIntrospection: boolean; enableConstraintValidation: boolean; enableAutoFixes: boolean; enableProgressiveEnhancement: boolean; enableGracefulDegradation: boolean; }; schema: { autoDetectFramework: boolean; frameworkOverride?: string; versionOverride?: string; primaryUserTable?: string; columnMapping: { enableDynamicMapping: boolean; enableFuzzyMatching: boolean; enablePatternMatching: boolean; minimumConfidence: number; customMappings: Record<string, Record<string, string>>; }; constraints: { enableValidation: boolean; enableAutoFixes: boolean; skipOptionalConstraints: boolean; createDependenciesOnDemand: boolean; }; relationships: { enableDiscovery: boolean; respectForeignKeys: boolean; handleCircularDependencies: boolean; enableParallelSeeding: boolean; }; }; execution: { enableRollback: boolean; maxRetries: number; timeoutMs: number; continueOnError: boolean; enableCaching: boolean; cacheTimeout: number; }; compatibility: { enableLegacyMode: boolean; legacyFallbacks: string[]; maintainOldBehavior: boolean; }; migration: { migratedFrom: string; migrationDate: string; originalConfigHash: string; migrationWarnings: string[]; }; } export interface MigrationResult { success: boolean; modernConfig: ModernConfig; warnings: string[]; errors: string[]; changes: ConfigChange[]; backupPath: string; recommendedActions: string[]; } export interface ConfigChange { type: 'added' | 'modified' | 'removed' | 'restructured'; path: string; oldValue?: any; newValue?: any; reason: string; } export interface MigrationOptions { inputPath?: string; outputPath?: string; createBackup: boolean; enableSchemaAnalysis: boolean; preserveLegacyBehavior: boolean; enableModernFeatures: boolean; validateAfterMigration: boolean; dryRun: boolean; customMappings?: Record<string, Record<string, string>>; frameworkHint?: string; } export declare class ConfigMigrator { private client; private adapter; private columnMapper; constructor(client: SupabaseClient); /** * Migrate a legacy configuration to the new schema-first format */ migrateConfig(legacyConfig: LegacyConfig, options?: Partial<MigrationOptions>): Promise<MigrationResult>; /** * Migrate configuration file from disk */ migrateConfigFile(inputPath: string, outputPath?: string, options?: Partial<MigrationOptions>): Promise<MigrationResult>; /** * Check if a configuration needs migration */ checkMigrationNeeded(configPath: string): Promise<{ needsMigration: boolean; currentVersion: string; targetVersion: string; reasons: string[]; }>; /** * Create a backup of the original configuration */ private createBackup; /** * Analyze current schema to inform migration */ private analyzeCurrentSchema; /** * Build modern configuration from legacy configuration */ private buildModernConfig; /** * Migrate legacy column mappings to new format */ private migrateLegacyMappings; /** * Track configuration changes for reporting */ private trackConfigurationChanges; /** * Apply schema analysis results to configuration */ private applySchemaAnalysisToConfig; /** * Validate the migrated modern configuration */ private validateModernConfig; /** * Generate recommendations based on migration */ private generateRecommendations; /** * Utility methods */ private readLegacyConfig; private readConfigFile; private isModernConfig; private generateConfigHash; private saveModernConfig; private createFallbackConfig; private logMigrationResult; } export {}; //# sourceMappingURL=config-migrator.d.ts.map