@alpha.consultings/eloquent-orm.js 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/README.md +215 -0
- package/dist/Model.d.ts +2 -0
- package/dist/Model.d.ts.map +1 -0
- package/dist/Model.js +7 -0
- package/dist/Model.js.map +1 -0
- package/dist/cli/commands/cacheClear.d.ts +2 -0
- package/dist/cli/commands/cacheClear.d.ts.map +1 -0
- package/dist/cli/commands/cacheClear.js +69 -0
- package/dist/cli/commands/cacheClear.js.map +1 -0
- package/dist/cli/commands/cacheStats.d.ts +2 -0
- package/dist/cli/commands/cacheStats.d.ts.map +1 -0
- package/dist/cli/commands/cacheStats.js +55 -0
- package/dist/cli/commands/cacheStats.js.map +1 -0
- package/dist/cli/commands/dbSeed.d.ts +16 -0
- package/dist/cli/commands/dbSeed.d.ts.map +1 -0
- package/dist/cli/commands/dbSeed.js +201 -0
- package/dist/cli/commands/dbSeed.js.map +1 -0
- package/dist/cli/commands/dbSeedBootstrapPrecheck.d.ts +3 -0
- package/dist/cli/commands/dbSeedBootstrapPrecheck.d.ts.map +1 -0
- package/dist/cli/commands/dbSeedBootstrapPrecheck.js +8 -0
- package/dist/cli/commands/dbSeedBootstrapPrecheck.js.map +1 -0
- package/dist/cli/commands/dbSeedFresh.d.ts +14 -0
- package/dist/cli/commands/dbSeedFresh.d.ts.map +1 -0
- package/dist/cli/commands/dbSeedFresh.js +81 -0
- package/dist/cli/commands/dbSeedFresh.js.map +1 -0
- package/dist/cli/commands/demoScenario.d.ts +9 -0
- package/dist/cli/commands/demoScenario.d.ts.map +1 -0
- package/dist/cli/commands/demoScenario.js +185 -0
- package/dist/cli/commands/demoScenario.js.map +1 -0
- package/dist/cli/commands/factoryStatus.d.ts +9 -0
- package/dist/cli/commands/factoryStatus.d.ts.map +1 -0
- package/dist/cli/commands/factoryStatus.js +103 -0
- package/dist/cli/commands/factoryStatus.js.map +1 -0
- package/dist/cli/commands/makeController.d.ts +11 -0
- package/dist/cli/commands/makeController.d.ts.map +1 -0
- package/dist/cli/commands/makeController.js +61 -0
- package/dist/cli/commands/makeController.js.map +1 -0
- package/dist/cli/commands/makeFactory.d.ts +14 -0
- package/dist/cli/commands/makeFactory.d.ts.map +1 -0
- package/dist/cli/commands/makeFactory.js +183 -0
- package/dist/cli/commands/makeFactory.js.map +1 -0
- package/dist/cli/commands/makeMigration.d.ts +18 -0
- package/dist/cli/commands/makeMigration.d.ts.map +1 -0
- package/dist/cli/commands/makeMigration.js +496 -0
- package/dist/cli/commands/makeMigration.js.map +1 -0
- package/dist/cli/commands/makeModel.d.ts +20 -0
- package/dist/cli/commands/makeModel.d.ts.map +1 -0
- package/dist/cli/commands/makeModel.js +360 -0
- package/dist/cli/commands/makeModel.js.map +1 -0
- package/dist/cli/commands/makeRegistry.d.ts +7 -0
- package/dist/cli/commands/makeRegistry.d.ts.map +1 -0
- package/dist/cli/commands/makeRegistry.js +88 -0
- package/dist/cli/commands/makeRegistry.js.map +1 -0
- package/dist/cli/commands/makeScenario.d.ts +12 -0
- package/dist/cli/commands/makeScenario.d.ts.map +1 -0
- package/dist/cli/commands/makeScenario.js +639 -0
- package/dist/cli/commands/makeScenario.js.map +1 -0
- package/dist/cli/commands/makeSeed.d.ts +11 -0
- package/dist/cli/commands/makeSeed.d.ts.map +1 -0
- package/dist/cli/commands/makeSeed.js +47 -0
- package/dist/cli/commands/makeSeed.js.map +1 -0
- package/dist/cli/commands/makeService.d.ts +5 -0
- package/dist/cli/commands/makeService.d.ts.map +1 -0
- package/dist/cli/commands/makeService.js +31 -0
- package/dist/cli/commands/makeService.js.map +1 -0
- package/dist/cli/commands/migrateFresh.d.ts +14 -0
- package/dist/cli/commands/migrateFresh.d.ts.map +1 -0
- package/dist/cli/commands/migrateFresh.js +150 -0
- package/dist/cli/commands/migrateFresh.js.map +1 -0
- package/dist/cli/commands/migrateReset.d.ts +12 -0
- package/dist/cli/commands/migrateReset.d.ts.map +1 -0
- package/dist/cli/commands/migrateReset.js +28 -0
- package/dist/cli/commands/migrateReset.js.map +1 -0
- package/dist/cli/commands/migrateRollback.d.ts +10 -0
- package/dist/cli/commands/migrateRollback.d.ts.map +1 -0
- package/dist/cli/commands/migrateRollback.js +303 -0
- package/dist/cli/commands/migrateRollback.js.map +1 -0
- package/dist/cli/commands/migrateRun.d.ts +10 -0
- package/dist/cli/commands/migrateRun.d.ts.map +1 -0
- package/dist/cli/commands/migrateRun.js +301 -0
- package/dist/cli/commands/migrateRun.js.map +1 -0
- package/dist/cli/commands/migrateStatus.d.ts +8 -0
- package/dist/cli/commands/migrateStatus.d.ts.map +1 -0
- package/dist/cli/commands/migrateStatus.js +118 -0
- package/dist/cli/commands/migrateStatus.js.map +1 -0
- package/dist/cli/eloquent.d.ts +18 -0
- package/dist/cli/eloquent.d.ts.map +1 -0
- package/dist/cli/eloquent.js +187 -0
- package/dist/cli/eloquent.js.map +1 -0
- package/dist/cli/utils/ArtifactCompatibility.d.ts +10 -0
- package/dist/cli/utils/ArtifactCompatibility.d.ts.map +1 -0
- package/dist/cli/utils/ArtifactCompatibility.js +60 -0
- package/dist/cli/utils/ArtifactCompatibility.js.map +1 -0
- package/dist/cli/utils/ArtifactRoutingReport.d.ts +10 -0
- package/dist/cli/utils/ArtifactRoutingReport.d.ts.map +1 -0
- package/dist/cli/utils/ArtifactRoutingReport.js +25 -0
- package/dist/cli/utils/ArtifactRoutingReport.js.map +1 -0
- package/dist/cli/utils/ArtifactStorage.d.ts +10 -0
- package/dist/cli/utils/ArtifactStorage.d.ts.map +1 -0
- package/dist/cli/utils/ArtifactStorage.js +193 -0
- package/dist/cli/utils/ArtifactStorage.js.map +1 -0
- package/dist/cli/utils/AuditTrail.d.ts +25 -0
- package/dist/cli/utils/AuditTrail.d.ts.map +1 -0
- package/dist/cli/utils/AuditTrail.js +74 -0
- package/dist/cli/utils/AuditTrail.js.map +1 -0
- package/dist/cli/utils/CliActionRuntime.d.ts +5 -0
- package/dist/cli/utils/CliActionRuntime.d.ts.map +1 -0
- package/dist/cli/utils/CliActionRuntime.js +22 -0
- package/dist/cli/utils/CliActionRuntime.js.map +1 -0
- package/dist/cli/utils/CliBootstrapSupport.d.ts +13 -0
- package/dist/cli/utils/CliBootstrapSupport.d.ts.map +1 -0
- package/dist/cli/utils/CliBootstrapSupport.js +55 -0
- package/dist/cli/utils/CliBootstrapSupport.js.map +1 -0
- package/dist/cli/utils/CliCommandCatalog.d.ts +6 -0
- package/dist/cli/utils/CliCommandCatalog.d.ts.map +1 -0
- package/dist/cli/utils/CliCommandCatalog.js +78 -0
- package/dist/cli/utils/CliCommandCatalog.js.map +1 -0
- package/dist/cli/utils/CliCommandTargets.d.ts +8 -0
- package/dist/cli/utils/CliCommandTargets.d.ts.map +1 -0
- package/dist/cli/utils/CliCommandTargets.js +19 -0
- package/dist/cli/utils/CliCommandTargets.js.map +1 -0
- package/dist/cli/utils/CliMakeArtifactCommandRegistration.d.ts +3 -0
- package/dist/cli/utils/CliMakeArtifactCommandRegistration.d.ts.map +1 -0
- package/dist/cli/utils/CliMakeArtifactCommandRegistration.js +94 -0
- package/dist/cli/utils/CliMakeArtifactCommandRegistration.js.map +1 -0
- package/dist/cli/utils/CliMigrationCommandRegistration.d.ts +3 -0
- package/dist/cli/utils/CliMigrationCommandRegistration.d.ts.map +1 -0
- package/dist/cli/utils/CliMigrationCommandRegistration.js +195 -0
- package/dist/cli/utils/CliMigrationCommandRegistration.js.map +1 -0
- package/dist/cli/utils/CliPresentation.d.ts +2 -0
- package/dist/cli/utils/CliPresentation.d.ts.map +1 -0
- package/dist/cli/utils/CliPresentation.js +13 -0
- package/dist/cli/utils/CliPresentation.js.map +1 -0
- package/dist/cli/utils/CliProductionGuards.d.ts +11 -0
- package/dist/cli/utils/CliProductionGuards.d.ts.map +1 -0
- package/dist/cli/utils/CliProductionGuards.js +34 -0
- package/dist/cli/utils/CliProductionGuards.js.map +1 -0
- package/dist/cli/utils/CliScaffoldCommandRegistration.d.ts +3 -0
- package/dist/cli/utils/CliScaffoldCommandRegistration.d.ts.map +1 -0
- package/dist/cli/utils/CliScaffoldCommandRegistration.js +89 -0
- package/dist/cli/utils/CliScaffoldCommandRegistration.js.map +1 -0
- package/dist/cli/utils/CliSeedScenarioCommandRegistration.d.ts +3 -0
- package/dist/cli/utils/CliSeedScenarioCommandRegistration.d.ts.map +1 -0
- package/dist/cli/utils/CliSeedScenarioCommandRegistration.js +123 -0
- package/dist/cli/utils/CliSeedScenarioCommandRegistration.js.map +1 -0
- package/dist/cli/utils/CliSupportCommandRegistration.d.ts +3 -0
- package/dist/cli/utils/CliSupportCommandRegistration.d.ts.map +1 -0
- package/dist/cli/utils/CliSupportCommandRegistration.js +44 -0
- package/dist/cli/utils/CliSupportCommandRegistration.js.map +1 -0
- package/dist/cli/utils/ConsoleSilencer.d.ts +6 -0
- package/dist/cli/utils/ConsoleSilencer.d.ts.map +1 -0
- package/dist/cli/utils/ConsoleSilencer.js +25 -0
- package/dist/cli/utils/ConsoleSilencer.js.map +1 -0
- package/dist/cli/utils/ImportResolver.d.ts +16 -0
- package/dist/cli/utils/ImportResolver.d.ts.map +1 -0
- package/dist/cli/utils/ImportResolver.js +57 -0
- package/dist/cli/utils/ImportResolver.js.map +1 -0
- package/dist/cli/utils/ModelIntrospector.d.ts +33 -0
- package/dist/cli/utils/ModelIntrospector.d.ts.map +1 -0
- package/dist/cli/utils/ModelIntrospector.js +76 -0
- package/dist/cli/utils/ModelIntrospector.js.map +1 -0
- package/dist/cli/utils/PathMap.d.ts +58 -0
- package/dist/cli/utils/PathMap.d.ts.map +1 -0
- package/dist/cli/utils/PathMap.js +132 -0
- package/dist/cli/utils/PathMap.js.map +1 -0
- package/dist/cli/utils/ProductionSafety.d.ts +25 -0
- package/dist/cli/utils/ProductionSafety.d.ts.map +1 -0
- package/dist/cli/utils/ProductionSafety.js +61 -0
- package/dist/cli/utils/ProductionSafety.js.map +1 -0
- package/dist/cli/utils/ScaffoldGeneratorSupport.d.ts +16 -0
- package/dist/cli/utils/ScaffoldGeneratorSupport.d.ts.map +1 -0
- package/dist/cli/utils/ScaffoldGeneratorSupport.js +66 -0
- package/dist/cli/utils/ScaffoldGeneratorSupport.js.map +1 -0
- package/dist/cli/utils/ScenarioMorphAliasRouting.d.ts +14 -0
- package/dist/cli/utils/ScenarioMorphAliasRouting.d.ts.map +1 -0
- package/dist/cli/utils/ScenarioMorphAliasRouting.js +62 -0
- package/dist/cli/utils/ScenarioMorphAliasRouting.js.map +1 -0
- package/dist/cli/utils/SeedBootstrapPrecheck.d.ts +20 -0
- package/dist/cli/utils/SeedBootstrapPrecheck.d.ts.map +1 -0
- package/dist/cli/utils/SeedBootstrapPrecheck.js +133 -0
- package/dist/cli/utils/SeedBootstrapPrecheck.js.map +1 -0
- package/dist/cli/utils/StructuredLogger.d.ts +11 -0
- package/dist/cli/utils/StructuredLogger.d.ts.map +1 -0
- package/dist/cli/utils/StructuredLogger.js +53 -0
- package/dist/cli/utils/StructuredLogger.js.map +1 -0
- package/dist/cli/utils/TemplateEngine.d.ts +30 -0
- package/dist/cli/utils/TemplateEngine.d.ts.map +1 -0
- package/dist/cli/utils/TemplateEngine.js +165 -0
- package/dist/cli/utils/TemplateEngine.js.map +1 -0
- package/dist/cli/utils/factories/Factory.d.ts +61 -0
- package/dist/cli/utils/factories/Factory.d.ts.map +1 -0
- package/dist/cli/utils/factories/Factory.js +140 -0
- package/dist/cli/utils/factories/Factory.js.map +1 -0
- package/dist/cli/utils/factories/FactoryDisplay.d.ts +6 -0
- package/dist/cli/utils/factories/FactoryDisplay.d.ts.map +1 -0
- package/dist/cli/utils/factories/FactoryDisplay.js +26 -0
- package/dist/cli/utils/factories/FactoryDisplay.js.map +1 -0
- package/dist/cli/utils/factories/FactoryGraph.d.ts +6 -0
- package/dist/cli/utils/factories/FactoryGraph.d.ts.map +1 -0
- package/dist/cli/utils/factories/FactoryGraph.js +72 -0
- package/dist/cli/utils/factories/FactoryGraph.js.map +1 -0
- package/dist/cli/utils/factories/FactoryLoader.d.ts +16 -0
- package/dist/cli/utils/factories/FactoryLoader.d.ts.map +1 -0
- package/dist/cli/utils/factories/FactoryLoader.js +35 -0
- package/dist/cli/utils/factories/FactoryLoader.js.map +1 -0
- package/dist/cli/utils/factories/FactoryRegistry.d.ts +16 -0
- package/dist/cli/utils/factories/FactoryRegistry.d.ts.map +1 -0
- package/dist/cli/utils/factories/FactoryRegistry.js +87 -0
- package/dist/cli/utils/factories/FactoryRegistry.js.map +1 -0
- package/dist/cli/utils/fileWriter.d.ts +7 -0
- package/dist/cli/utils/fileWriter.d.ts.map +1 -0
- package/dist/cli/utils/fileWriter.js +61 -0
- package/dist/cli/utils/fileWriter.js.map +1 -0
- package/dist/cli/utils/migrations/MigrationLockStrategy.d.ts +21 -0
- package/dist/cli/utils/migrations/MigrationLockStrategy.d.ts.map +1 -0
- package/dist/cli/utils/migrations/MigrationLockStrategy.js +129 -0
- package/dist/cli/utils/migrations/MigrationLockStrategy.js.map +1 -0
- package/dist/cli/utils/migrations/MigrationTracker.d.ts +25 -0
- package/dist/cli/utils/migrations/MigrationTracker.d.ts.map +1 -0
- package/dist/cli/utils/migrations/MigrationTracker.js +279 -0
- package/dist/cli/utils/migrations/MigrationTracker.js.map +1 -0
- package/dist/cli/utils/migrations/MongoMigrationTracker.d.ts +18 -0
- package/dist/cli/utils/migrations/MongoMigrationTracker.d.ts.map +1 -0
- package/dist/cli/utils/migrations/MongoMigrationTracker.js +276 -0
- package/dist/cli/utils/migrations/MongoMigrationTracker.js.map +1 -0
- package/dist/cli/utils/resolveConnectionFlags.d.ts +14 -0
- package/dist/cli/utils/resolveConnectionFlags.d.ts.map +1 -0
- package/dist/cli/utils/resolveConnectionFlags.js +42 -0
- package/dist/cli/utils/resolveConnectionFlags.js.map +1 -0
- package/dist/cli/utils/resolveSqlConnectionFlags.d.ts +9 -0
- package/dist/cli/utils/resolveSqlConnectionFlags.d.ts.map +1 -0
- package/dist/cli/utils/resolveSqlConnectionFlags.js +23 -0
- package/dist/cli/utils/resolveSqlConnectionFlags.js.map +1 -0
- package/dist/cli/utils/typescript/BaseCommand.d.ts +15 -0
- package/dist/cli/utils/typescript/BaseCommand.d.ts.map +1 -0
- package/dist/cli/utils/typescript/BaseCommand.js +36 -0
- package/dist/cli/utils/typescript/BaseCommand.js.map +1 -0
- package/dist/cli/utils/typescript/RuntimeDetector.d.ts +16 -0
- package/dist/cli/utils/typescript/RuntimeDetector.d.ts.map +1 -0
- package/dist/cli/utils/typescript/RuntimeDetector.js +45 -0
- package/dist/cli/utils/typescript/RuntimeDetector.js.map +1 -0
- package/dist/cli/utils/typescript/TypeScriptCompiler.d.ts +25 -0
- package/dist/cli/utils/typescript/TypeScriptCompiler.d.ts.map +1 -0
- package/dist/cli/utils/typescript/TypeScriptCompiler.js +109 -0
- package/dist/cli/utils/typescript/TypeScriptCompiler.js.map +1 -0
- package/dist/cli/utils/typescript/tsRuntime.d.ts +12 -0
- package/dist/cli/utils/typescript/tsRuntime.d.ts.map +1 -0
- package/dist/cli/utils/typescript/tsRuntime.js +189 -0
- package/dist/cli/utils/typescript/tsRuntime.js.map +1 -0
- package/dist/config/database.d.ts +58 -0
- package/dist/config/database.d.ts.map +1 -0
- package/dist/config/database.js +106 -0
- package/dist/config/database.js.map +1 -0
- package/dist/config/dbRoleEnv.d.ts +31 -0
- package/dist/config/dbRoleEnv.d.ts.map +1 -0
- package/dist/config/dbRoleEnv.js +171 -0
- package/dist/config/dbRoleEnv.js.map +1 -0
- package/dist/core/cache/CacheAnalytics.d.ts +47 -0
- package/dist/core/cache/CacheAnalytics.d.ts.map +1 -0
- package/dist/core/cache/CacheAnalytics.js +113 -0
- package/dist/core/cache/CacheAnalytics.js.map +1 -0
- package/dist/core/cache/CacheDriver.d.ts +19 -0
- package/dist/core/cache/CacheDriver.d.ts.map +1 -0
- package/dist/core/cache/CacheDriver.js +8 -0
- package/dist/core/cache/CacheDriver.js.map +1 -0
- package/dist/core/cache/CacheFallbackManager.d.ts +35 -0
- package/dist/core/cache/CacheFallbackManager.d.ts.map +1 -0
- package/dist/core/cache/CacheFallbackManager.js +118 -0
- package/dist/core/cache/CacheFallbackManager.js.map +1 -0
- package/dist/core/cache/CacheManager.d.ts +11 -0
- package/dist/core/cache/CacheManager.d.ts.map +1 -0
- package/dist/core/cache/CacheManager.js +27 -0
- package/dist/core/cache/CacheManager.js.map +1 -0
- package/dist/core/cache/CacheRegistry.d.ts +49 -0
- package/dist/core/cache/CacheRegistry.d.ts.map +1 -0
- package/dist/core/cache/CacheRegistry.js +117 -0
- package/dist/core/cache/CacheRegistry.js.map +1 -0
- package/dist/core/cache/drivers/FileCacheDriver.d.ts +11 -0
- package/dist/core/cache/drivers/FileCacheDriver.d.ts.map +1 -0
- package/dist/core/cache/drivers/FileCacheDriver.js +54 -0
- package/dist/core/cache/drivers/FileCacheDriver.js.map +1 -0
- package/dist/core/cache/drivers/MemcachedCacheDriver.d.ts +15 -0
- package/dist/core/cache/drivers/MemcachedCacheDriver.d.ts.map +1 -0
- package/dist/core/cache/drivers/MemcachedCacheDriver.js +60 -0
- package/dist/core/cache/drivers/MemcachedCacheDriver.js.map +1 -0
- package/dist/core/cache/drivers/MemoryCacheDriver.d.ts +9 -0
- package/dist/core/cache/drivers/MemoryCacheDriver.d.ts.map +1 -0
- package/dist/core/cache/drivers/MemoryCacheDriver.js +33 -0
- package/dist/core/cache/drivers/MemoryCacheDriver.js.map +1 -0
- package/dist/core/cache/setupCache.d.ts +2 -0
- package/dist/core/cache/setupCache.d.ts.map +1 -0
- package/dist/core/cache/setupCache.js +38 -0
- package/dist/core/cache/setupCache.js.map +1 -0
- package/dist/core/connection/BetterSqliteConnection.d.ts +23 -0
- package/dist/core/connection/BetterSqliteConnection.d.ts.map +1 -0
- package/dist/core/connection/BetterSqliteConnection.js +33 -0
- package/dist/core/connection/BetterSqliteConnection.js.map +1 -0
- package/dist/core/connection/ConnectionFactory.d.ts +18 -0
- package/dist/core/connection/ConnectionFactory.d.ts.map +1 -0
- package/dist/core/connection/ConnectionFactory.js +111 -0
- package/dist/core/connection/ConnectionFactory.js.map +1 -0
- package/dist/core/connection/DatabaseConnection.d.ts +49 -0
- package/dist/core/connection/DatabaseConnection.d.ts.map +1 -0
- package/dist/core/connection/DatabaseConnection.js +120 -0
- package/dist/core/connection/DatabaseConnection.js.map +1 -0
- package/dist/core/connection/DriverAdapter.d.ts +23 -0
- package/dist/core/connection/DriverAdapter.d.ts.map +1 -0
- package/dist/core/connection/DriverAdapter.js +145 -0
- package/dist/core/connection/DriverAdapter.js.map +1 -0
- package/dist/core/connection/resolveConnectionName.d.ts +17 -0
- package/dist/core/connection/resolveConnectionName.d.ts.map +1 -0
- package/dist/core/connection/resolveConnectionName.js +47 -0
- package/dist/core/connection/resolveConnectionName.js.map +1 -0
- package/dist/core/model/BaseModel.d.ts +247 -0
- package/dist/core/model/BaseModel.d.ts.map +1 -0
- package/dist/core/model/BaseModel.js +165 -0
- package/dist/core/model/BaseModel.js.map +1 -0
- package/dist/core/model/BaseModelSafeFinderStatics.d.ts +33 -0
- package/dist/core/model/BaseModelSafeFinderStatics.d.ts.map +1 -0
- package/dist/core/model/BaseModelSafeFinderStatics.js +87 -0
- package/dist/core/model/BaseModelSafeFinderStatics.js.map +1 -0
- package/dist/core/model/CoreModel.d.ts +134 -0
- package/dist/core/model/CoreModel.d.ts.map +1 -0
- package/dist/core/model/CoreModel.js +541 -0
- package/dist/core/model/CoreModel.js.map +1 -0
- package/dist/core/model/CoreModelPersistenceState.d.ts +36 -0
- package/dist/core/model/CoreModelPersistenceState.d.ts.map +1 -0
- package/dist/core/model/CoreModelPersistenceState.js +141 -0
- package/dist/core/model/CoreModelPersistenceState.js.map +1 -0
- package/dist/core/model/CoreModelSafeFinderSupport.d.ts +5 -0
- package/dist/core/model/CoreModelSafeFinderSupport.d.ts.map +1 -0
- package/dist/core/model/CoreModelSafeFinderSupport.js +15 -0
- package/dist/core/model/CoreModelSafeFinderSupport.js.map +1 -0
- package/dist/core/model/CoreModelValidationEvents.d.ts +24 -0
- package/dist/core/model/CoreModelValidationEvents.d.ts.map +1 -0
- package/dist/core/model/CoreModelValidationEvents.js +45 -0
- package/dist/core/model/CoreModelValidationEvents.js.map +1 -0
- package/dist/core/model/SafeFinder.d.ts +46 -0
- package/dist/core/model/SafeFinder.d.ts.map +1 -0
- package/dist/core/model/SafeFinder.js +223 -0
- package/dist/core/model/SafeFinder.js.map +1 -0
- package/dist/core/orm/Relation.d.ts +47 -0
- package/dist/core/orm/Relation.d.ts.map +1 -0
- package/dist/core/orm/Relation.js +62 -0
- package/dist/core/orm/Relation.js.map +1 -0
- package/dist/core/orm/mixins/CastsMixin.d.ts +18 -0
- package/dist/core/orm/mixins/CastsMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/CastsMixin.js +125 -0
- package/dist/core/orm/mixins/CastsMixin.js.map +1 -0
- package/dist/core/orm/mixins/EagerLoadingMixin.d.ts +19 -0
- package/dist/core/orm/mixins/EagerLoadingMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/EagerLoadingMixin.js +137 -0
- package/dist/core/orm/mixins/EagerLoadingMixin.js.map +1 -0
- package/dist/core/orm/mixins/HooksMixin.d.ts +16 -0
- package/dist/core/orm/mixins/HooksMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/HooksMixin.js +95 -0
- package/dist/core/orm/mixins/HooksMixin.js.map +1 -0
- package/dist/core/orm/mixins/MorphRegistry.d.ts +47 -0
- package/dist/core/orm/mixins/MorphRegistry.d.ts.map +1 -0
- package/dist/core/orm/mixins/MorphRegistry.js +67 -0
- package/dist/core/orm/mixins/MorphRegistry.js.map +1 -0
- package/dist/core/orm/mixins/MorphableMixin.d.ts +29 -0
- package/dist/core/orm/mixins/MorphableMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/MorphableMixin.js +93 -0
- package/dist/core/orm/mixins/MorphableMixin.js.map +1 -0
- package/dist/core/orm/mixins/PivotHelperMixin.d.ts +26 -0
- package/dist/core/orm/mixins/PivotHelperMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/PivotHelperMixin.js +102 -0
- package/dist/core/orm/mixins/PivotHelperMixin.js.map +1 -0
- package/dist/core/orm/mixins/QueryCacheMixin.d.ts +23 -0
- package/dist/core/orm/mixins/QueryCacheMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/QueryCacheMixin.js +172 -0
- package/dist/core/orm/mixins/QueryCacheMixin.js.map +1 -0
- package/dist/core/orm/mixins/ScopeMixin.d.ts +20 -0
- package/dist/core/orm/mixins/ScopeMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/ScopeMixin.js +72 -0
- package/dist/core/orm/mixins/ScopeMixin.js.map +1 -0
- package/dist/core/orm/mixins/SerializeMixin.d.ts +44 -0
- package/dist/core/orm/mixins/SerializeMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/SerializeMixin.js +80 -0
- package/dist/core/orm/mixins/SerializeMixin.js.map +1 -0
- package/dist/core/orm/mixins/SoftDeletesMixin.d.ts +22 -0
- package/dist/core/orm/mixins/SoftDeletesMixin.d.ts.map +1 -0
- package/dist/core/orm/mixins/SoftDeletesMixin.js +146 -0
- package/dist/core/orm/mixins/SoftDeletesMixin.js.map +1 -0
- package/dist/core/orm/mixins/utils/BaseMethodResolver.d.ts +8 -0
- package/dist/core/orm/mixins/utils/BaseMethodResolver.d.ts.map +1 -0
- package/dist/core/orm/mixins/utils/BaseMethodResolver.js +26 -0
- package/dist/core/orm/mixins/utils/BaseMethodResolver.js.map +1 -0
- package/dist/core/orm/mixins/utils/HookStore.d.ts +26 -0
- package/dist/core/orm/mixins/utils/HookStore.d.ts.map +1 -0
- package/dist/core/orm/mixins/utils/HookStore.js +78 -0
- package/dist/core/orm/mixins/utils/HookStore.js.map +1 -0
- package/dist/core/orm/mixins/utils/ModelRegistry.d.ts +33 -0
- package/dist/core/orm/mixins/utils/ModelRegistry.d.ts.map +1 -0
- package/dist/core/orm/mixins/utils/ModelRegistry.js +87 -0
- package/dist/core/orm/mixins/utils/ModelRegistry.js.map +1 -0
- package/dist/core/orm/mixins/utils/modelRegistration.d.ts +9 -0
- package/dist/core/orm/mixins/utils/modelRegistration.d.ts.map +1 -0
- package/dist/core/orm/mixins/utils/modelRegistration.js +26 -0
- package/dist/core/orm/mixins/utils/modelRegistration.js.map +1 -0
- package/dist/core/orm/relations/BelongsTo.d.ts +6 -0
- package/dist/core/orm/relations/BelongsTo.d.ts.map +1 -0
- package/dist/core/orm/relations/BelongsTo.js +70 -0
- package/dist/core/orm/relations/BelongsTo.js.map +1 -0
- package/dist/core/orm/relations/BelongsToMany.d.ts +14 -0
- package/dist/core/orm/relations/BelongsToMany.d.ts.map +1 -0
- package/dist/core/orm/relations/BelongsToMany.js +245 -0
- package/dist/core/orm/relations/BelongsToMany.js.map +1 -0
- package/dist/core/orm/relations/HasMany.d.ts +6 -0
- package/dist/core/orm/relations/HasMany.d.ts.map +1 -0
- package/dist/core/orm/relations/HasMany.js +75 -0
- package/dist/core/orm/relations/HasMany.js.map +1 -0
- package/dist/core/orm/relations/HasOne.d.ts +6 -0
- package/dist/core/orm/relations/HasOne.d.ts.map +1 -0
- package/dist/core/orm/relations/HasOne.js +71 -0
- package/dist/core/orm/relations/HasOne.js.map +1 -0
- package/dist/core/orm/relations/MorphMany.d.ts +9 -0
- package/dist/core/orm/relations/MorphMany.d.ts.map +1 -0
- package/dist/core/orm/relations/MorphMany.js +107 -0
- package/dist/core/orm/relations/MorphMany.js.map +1 -0
- package/dist/core/orm/relations/MorphOne.d.ts +9 -0
- package/dist/core/orm/relations/MorphOne.d.ts.map +1 -0
- package/dist/core/orm/relations/MorphOne.js +101 -0
- package/dist/core/orm/relations/MorphOne.js.map +1 -0
- package/dist/core/orm/relations/MorphTo.d.ts +9 -0
- package/dist/core/orm/relations/MorphTo.d.ts.map +1 -0
- package/dist/core/orm/relations/MorphTo.js +85 -0
- package/dist/core/orm/relations/MorphTo.js.map +1 -0
- package/dist/core/schema/SQLDialect.d.ts +22 -0
- package/dist/core/schema/SQLDialect.d.ts.map +1 -0
- package/dist/core/schema/SQLDialect.js +38 -0
- package/dist/core/schema/SQLDialect.js.map +1 -0
- package/dist/core/schema/SchemaBlueprint.d.ts +61 -0
- package/dist/core/schema/SchemaBlueprint.d.ts.map +1 -0
- package/dist/core/schema/SchemaBlueprint.js +62 -0
- package/dist/core/schema/SchemaBlueprint.js.map +1 -0
- package/dist/core/schema/SchemaBuilder.d.ts +29 -0
- package/dist/core/schema/SchemaBuilder.d.ts.map +1 -0
- package/dist/core/schema/SchemaBuilder.js +661 -0
- package/dist/core/schema/SchemaBuilder.js.map +1 -0
- package/dist/core/schema/SchemaValidator.d.ts +23 -0
- package/dist/core/schema/SchemaValidator.d.ts.map +1 -0
- package/dist/core/schema/SchemaValidator.js +75 -0
- package/dist/core/schema/SchemaValidator.js.map +1 -0
- package/dist/core/security/AbstractSecurity.d.ts +24 -0
- package/dist/core/security/AbstractSecurity.d.ts.map +1 -0
- package/dist/core/security/AbstractSecurity.js +58 -0
- package/dist/core/security/AbstractSecurity.js.map +1 -0
- package/dist/core/security/EnvKeySecurity.d.ts +11 -0
- package/dist/core/security/EnvKeySecurity.d.ts.map +1 -0
- package/dist/core/security/EnvKeySecurity.js +46 -0
- package/dist/core/security/EnvKeySecurity.js.map +1 -0
- package/dist/core/security/NoSecurity.d.ts +10 -0
- package/dist/core/security/NoSecurity.d.ts.map +1 -0
- package/dist/core/security/NoSecurity.js +18 -0
- package/dist/core/security/NoSecurity.js.map +1 -0
- package/dist/core/security/SecretRedactor.d.ts +4 -0
- package/dist/core/security/SecretRedactor.d.ts.map +1 -0
- package/dist/core/security/SecretRedactor.js +60 -0
- package/dist/core/security/SecretRedactor.js.map +1 -0
- package/dist/core/security/SecurityContract.d.ts +13 -0
- package/dist/core/security/SecurityContract.d.ts.map +1 -0
- package/dist/core/security/SecurityContract.js +3 -0
- package/dist/core/security/SecurityContract.js.map +1 -0
- package/dist/core/security/SecurityFactory.d.ts +9 -0
- package/dist/core/security/SecurityFactory.d.ts.map +1 -0
- package/dist/core/security/SecurityFactory.js +29 -0
- package/dist/core/security/SecurityFactory.js.map +1 -0
- package/dist/core/security/index.d.ts +6 -0
- package/dist/core/security/index.d.ts.map +1 -0
- package/dist/core/security/index.js +22 -0
- package/dist/core/security/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/package.json +104 -0
- package/src/cli/templates/controller.tpl +80 -0
- package/src/cli/templates/factory.tpl +14 -0
- package/src/cli/templates/migration.tpl +36 -0
- package/src/cli/templates/model-registry.tpl +16 -0
- package/src/cli/templates/model.tpl +95 -0
- package/src/cli/templates/pivot-factory.tpl +85 -0
- package/src/cli/templates/seed.tpl +20 -0
- package/src/cli/templates/service.tpl +40 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SchemaBuilder = void 0;
|
|
37
|
+
/* ============================================================
|
|
38
|
+
* SchemaBuilder v4.0
|
|
39
|
+
* Auto-detects CREATE / ALTER / DROP COLUMN schema differences
|
|
40
|
+
* ============================================================ */
|
|
41
|
+
const SchemaBlueprint_1 = require("./SchemaBlueprint");
|
|
42
|
+
const SQLDialect_1 = require("./SQLDialect");
|
|
43
|
+
const database_1 = require("../../config/database");
|
|
44
|
+
class SchemaBuilder {
|
|
45
|
+
static async toCreateSQL(tableName, schema, explicitDialect, smartUpdate = false, connectionNameOverride, forceCreate = false) {
|
|
46
|
+
const supportedDialects = ["mysql", "pg", "sqlite"];
|
|
47
|
+
let dialectName = supportedDialects.includes(explicitDialect)
|
|
48
|
+
? explicitDialect
|
|
49
|
+
: (database_1.dbConfig.default || "mysql");
|
|
50
|
+
if (!supportedDialects.includes(dialectName)) {
|
|
51
|
+
const maybe = explicitDialect ? database_1.dbConfig.connections[explicitDialect] : undefined;
|
|
52
|
+
const driver = maybe?.driver;
|
|
53
|
+
if (driver && supportedDialects.includes(driver)) {
|
|
54
|
+
dialectName = driver;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!supportedDialects.includes(dialectName)) {
|
|
58
|
+
throw new Error(`ERROR: Unsupported dialect: ${explicitDialect}`);
|
|
59
|
+
}
|
|
60
|
+
const dialect = new SQLDialect_1.SQLDialect(dialectName);
|
|
61
|
+
const errors = (0, SchemaBlueprint_1.validateSchema)(schema);
|
|
62
|
+
if (errors.length > 0)
|
|
63
|
+
throw new Error(`ERROR: Schema validation failed for ${tableName}:\n${errors.join("\n")}`);
|
|
64
|
+
const columns = [];
|
|
65
|
+
const primaryColumns = [];
|
|
66
|
+
const extraTables = [];
|
|
67
|
+
const rollbackExtraTables = [];
|
|
68
|
+
const columnSqlByName = new Map();
|
|
69
|
+
const desiredConstraintsByKey = new Map();
|
|
70
|
+
const desiredPivotTables = new Map();
|
|
71
|
+
for (const [name, field] of Object.entries(schema)) {
|
|
72
|
+
switch (field.kind) {
|
|
73
|
+
case "column": {
|
|
74
|
+
if (field.options?.primary)
|
|
75
|
+
primaryColumns.push(name);
|
|
76
|
+
const sql = this.columnSQL(name, field, dialectName, dialect);
|
|
77
|
+
columns.push(sql);
|
|
78
|
+
columnSqlByName.set(name, sql);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case "relation": {
|
|
82
|
+
const rel = this.relationSQL(tableName, name, field, dialect, dialectName);
|
|
83
|
+
if (rel) {
|
|
84
|
+
if (rel.type === "inline") {
|
|
85
|
+
for (const col of rel.columns) {
|
|
86
|
+
if (!columnSqlByName.has(col.name)) {
|
|
87
|
+
columns.push(col.sql);
|
|
88
|
+
columnSqlByName.set(col.name, col.sql);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
columns.push(...rel.constraints.map((constraint) => constraint.createSql));
|
|
92
|
+
for (const constraint of rel.constraints) {
|
|
93
|
+
desiredConstraintsByKey.set(constraint.key, constraint);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (rel.type === "pivot") {
|
|
97
|
+
desiredPivotTables.set(rel.tableName, {
|
|
98
|
+
createSql: rel.sql,
|
|
99
|
+
dropSql: dialect.formatDropSQL(rel.tableName),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (rel.type === "morph") {
|
|
103
|
+
for (const col of rel.columns) {
|
|
104
|
+
if (!columnSqlByName.has(col.name)) {
|
|
105
|
+
columns.push(col.sql);
|
|
106
|
+
columnSqlByName.set(col.name, col.sql);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "mixin": {
|
|
114
|
+
const mixinCols = this.mixinSQL(field, dialectName, dialect);
|
|
115
|
+
columns.push(...mixinCols);
|
|
116
|
+
if (field.name === "SoftDeletes") {
|
|
117
|
+
const name = "deleted_at";
|
|
118
|
+
const sql = mixinCols.find((c) => c.includes(dialect.wrap(name)));
|
|
119
|
+
if (sql)
|
|
120
|
+
columnSqlByName.set(name, sql);
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (primaryColumns.length > 1) {
|
|
127
|
+
const pkCols = primaryColumns.map((c) => dialect.wrap(c)).join(", ");
|
|
128
|
+
columns.push(`PRIMARY KEY (${pkCols})`);
|
|
129
|
+
}
|
|
130
|
+
/* ============================================================
|
|
131
|
+
* Smart Diff Logic (Add + Drop)
|
|
132
|
+
* ============================================================ */
|
|
133
|
+
let tableExists = false;
|
|
134
|
+
let existingColumns = [];
|
|
135
|
+
const existingColumnSqlByName = new Map();
|
|
136
|
+
const existingConstraintsByKey = new Map();
|
|
137
|
+
let introspectionAdapter = null;
|
|
138
|
+
if (!forceCreate) {
|
|
139
|
+
try {
|
|
140
|
+
const { getAdapter } = await Promise.resolve().then(() => __importStar(require("../connection/ConnectionFactory")));
|
|
141
|
+
const adapter = await getAdapter((connectionNameOverride || dialectName));
|
|
142
|
+
introspectionAdapter = adapter;
|
|
143
|
+
if (dialectName === "mysql") {
|
|
144
|
+
const rows = await adapter.query(`SHOW TABLES LIKE ${adapter.placeholder(1)}`, [tableName]);
|
|
145
|
+
tableExists = rows.length > 0;
|
|
146
|
+
if (tableExists) {
|
|
147
|
+
const cols = await adapter.query(`SHOW COLUMNS FROM ${dialect.wrap(tableName)};`);
|
|
148
|
+
existingColumns = cols.map((c) => c.Field);
|
|
149
|
+
for (const c of cols) {
|
|
150
|
+
existingColumnSqlByName.set(c.Field, this.mysqlColumnSQL(c, dialect));
|
|
151
|
+
}
|
|
152
|
+
const constraints = await this.mysqlForeignKeys(adapter, tableName, dialect);
|
|
153
|
+
for (const constraint of constraints) {
|
|
154
|
+
existingConstraintsByKey.set(constraint.key, constraint);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (dialectName === "pg") {
|
|
159
|
+
const rows = await adapter.query(`SELECT
|
|
160
|
+
column_name,
|
|
161
|
+
data_type,
|
|
162
|
+
udt_name,
|
|
163
|
+
is_nullable,
|
|
164
|
+
column_default,
|
|
165
|
+
character_maximum_length,
|
|
166
|
+
numeric_precision,
|
|
167
|
+
numeric_scale
|
|
168
|
+
FROM information_schema.columns
|
|
169
|
+
WHERE table_name = ${adapter.placeholder(1)}
|
|
170
|
+
AND table_schema = current_schema();`, [tableName]);
|
|
171
|
+
tableExists = rows.length > 0;
|
|
172
|
+
existingColumns = rows.map((r) => r.column_name);
|
|
173
|
+
for (const r of rows) {
|
|
174
|
+
existingColumnSqlByName.set(r.column_name, this.pgColumnSQL(r, dialect));
|
|
175
|
+
}
|
|
176
|
+
const constraints = await this.pgForeignKeys(adapter, tableName, dialect);
|
|
177
|
+
for (const constraint of constraints) {
|
|
178
|
+
existingConstraintsByKey.set(constraint.key, constraint);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// mysql/pg were handled above; with validated dialects, the remaining branch is sqlite.
|
|
183
|
+
const rows = await adapter.query(`PRAGMA table_info(${dialect.wrap(tableName)});`);
|
|
184
|
+
tableExists = rows.length > 0;
|
|
185
|
+
existingColumns = rows.map((r) => r.name);
|
|
186
|
+
for (const r of rows) {
|
|
187
|
+
existingColumnSqlByName.set(r.name, this.sqliteColumnSQL(r, dialect));
|
|
188
|
+
}
|
|
189
|
+
const constraints = await this.sqliteForeignKeys(adapter, tableName, dialect);
|
|
190
|
+
for (const constraint of constraints) {
|
|
191
|
+
existingConstraintsByKey.set(constraint.key, constraint);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
console.warn(`WARN: Could not verify structure for '${tableName}'.`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (desiredPivotTables.size > 0) {
|
|
200
|
+
if (!tableExists || !smartUpdate) {
|
|
201
|
+
for (const pivotTable of desiredPivotTables.values()) {
|
|
202
|
+
extraTables.push(pivotTable.createSql);
|
|
203
|
+
rollbackExtraTables.push(pivotTable.dropSql);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
for (const [pivotName, pivotTable] of desiredPivotTables.entries()) {
|
|
208
|
+
const exists = introspectionAdapter &&
|
|
209
|
+
(await this.pivotTableExists(introspectionAdapter, dialectName, dialect, pivotName));
|
|
210
|
+
if (exists)
|
|
211
|
+
continue;
|
|
212
|
+
extraTables.push(pivotTable.createSql);
|
|
213
|
+
rollbackExtraTables.push(pivotTable.dropSql);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
let mainSQL = "";
|
|
218
|
+
let rollbackMainSQL = "";
|
|
219
|
+
if (!tableExists) {
|
|
220
|
+
mainSQL = dialect.formatCreateSQL(tableName, columns);
|
|
221
|
+
rollbackMainSQL = dialect.formatDropSQL(tableName);
|
|
222
|
+
}
|
|
223
|
+
else if (smartUpdate) {
|
|
224
|
+
const schemaColumns = Array.from(columnSqlByName.keys());
|
|
225
|
+
const missingColumns = [];
|
|
226
|
+
const missingColumnNames = [];
|
|
227
|
+
const dropColumns = [];
|
|
228
|
+
const addConstraints = [];
|
|
229
|
+
const dropConstraints = [];
|
|
230
|
+
// Detect new columns
|
|
231
|
+
for (const colName of schemaColumns) {
|
|
232
|
+
if (!existingColumns.includes(colName)) {
|
|
233
|
+
const sql = columnSqlByName.get(colName);
|
|
234
|
+
if (sql) {
|
|
235
|
+
missingColumns.push(sql);
|
|
236
|
+
missingColumnNames.push(colName);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Detect removed columns
|
|
241
|
+
for (const existing of existingColumns) {
|
|
242
|
+
if (!schemaColumns.includes(existing) &&
|
|
243
|
+
!["id", "created_at", "updated_at"].includes(existing)) {
|
|
244
|
+
dropColumns.push(existing);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const [key, constraint] of desiredConstraintsByKey.entries()) {
|
|
248
|
+
if (!existingConstraintsByKey.has(key) && constraint.addClause.trim().length > 0) {
|
|
249
|
+
addConstraints.push(constraint);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (const [key, constraint] of existingConstraintsByKey.entries()) {
|
|
253
|
+
if (!desiredConstraintsByKey.has(key) && constraint.dropClause.trim().length > 0) {
|
|
254
|
+
dropConstraints.push(constraint);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Nothing to change
|
|
258
|
+
if (missingColumns.length === 0 &&
|
|
259
|
+
dropColumns.length === 0 &&
|
|
260
|
+
addConstraints.length === 0 &&
|
|
261
|
+
dropConstraints.length === 0) {
|
|
262
|
+
console.log(`INFO: No schema differences for '${tableName}'.`);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
// Order timestamps last
|
|
266
|
+
const createdAtToken = dialect.wrap("created_at");
|
|
267
|
+
const updatedAtToken = dialect.wrap("updated_at");
|
|
268
|
+
const lastCols = missingColumns.filter((c) => c.includes(createdAtToken) || c.includes(updatedAtToken));
|
|
269
|
+
const normalCols = missingColumns.filter((c) => !c.includes(createdAtToken) && !c.includes(updatedAtToken));
|
|
270
|
+
const addColumnSQL = [...normalCols, ...lastCols]
|
|
271
|
+
.map((c) => `ADD COLUMN ${c}`)
|
|
272
|
+
.join(",\n ");
|
|
273
|
+
const addConstraintSQL = addConstraints
|
|
274
|
+
.map((constraint) => constraint.addClause)
|
|
275
|
+
.join(",\n ");
|
|
276
|
+
const dropConstraintSQL = dropConstraints
|
|
277
|
+
.map((constraint) => constraint.dropClause)
|
|
278
|
+
.join(",\n ");
|
|
279
|
+
const dropColumnSQL = dropColumns
|
|
280
|
+
.map((name) => `DROP COLUMN ${dialect.wrap(name)}`)
|
|
281
|
+
.join(",\n ");
|
|
282
|
+
const combined = [
|
|
283
|
+
dropConstraintSQL,
|
|
284
|
+
dropColumnSQL,
|
|
285
|
+
addColumnSQL,
|
|
286
|
+
addConstraintSQL,
|
|
287
|
+
]
|
|
288
|
+
.filter(Boolean)
|
|
289
|
+
.join(",\n ");
|
|
290
|
+
mainSQL = `ALTER TABLE ${dialect.wrap(tableName)}\n ${combined};`;
|
|
291
|
+
const restoreDroppedSQL = dropColumns
|
|
292
|
+
.map((name) => existingColumnSqlByName.get(name))
|
|
293
|
+
.filter((sql) => !!sql)
|
|
294
|
+
.map((sql) => `ADD COLUMN ${sql}`);
|
|
295
|
+
const dropAddedSQL = missingColumnNames.map((name) => `DROP COLUMN ${dialect.wrap(name)}`);
|
|
296
|
+
const rollbackDropConstraints = addConstraints
|
|
297
|
+
.map((constraint) => constraint.dropClause)
|
|
298
|
+
.filter(Boolean);
|
|
299
|
+
const rollbackAddConstraints = dropConstraints
|
|
300
|
+
.map((constraint) => constraint.addClause)
|
|
301
|
+
.filter(Boolean);
|
|
302
|
+
const rollbackCombined = [
|
|
303
|
+
...rollbackDropConstraints,
|
|
304
|
+
...dropAddedSQL,
|
|
305
|
+
...restoreDroppedSQL,
|
|
306
|
+
...rollbackAddConstraints,
|
|
307
|
+
]
|
|
308
|
+
.filter(Boolean)
|
|
309
|
+
.join(",\n ");
|
|
310
|
+
if (rollbackCombined.length > 0) {
|
|
311
|
+
rollbackMainSQL = `ALTER TABLE ${dialect.wrap(tableName)}\n ${rollbackCombined};`;
|
|
312
|
+
}
|
|
313
|
+
console.log(`Schema diff -> +[${missingColumnNames.join(", ") || "-"}], -[${dropColumns.join(", ") || "-"}], +fk[${addConstraints.map((constraint) => constraint.key).join(", ") || "-"}], -fk[${dropConstraints.map((constraint) => constraint.key).join(", ") || "-"}]`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return { mainSQL, extraTables, rollbackMainSQL, rollbackExtraTables };
|
|
317
|
+
}
|
|
318
|
+
/* ============================================================
|
|
319
|
+
* DROP TABLE
|
|
320
|
+
* ============================================================ */
|
|
321
|
+
static toDropSQL(tableName, schema, dialectName = "mysql") {
|
|
322
|
+
const dropSQL = [];
|
|
323
|
+
const pivotTables = [];
|
|
324
|
+
const dialect = new SQLDialect_1.SQLDialect(dialectName);
|
|
325
|
+
for (const [, field] of Object.entries(schema)) {
|
|
326
|
+
if (field.kind === "relation" && field.relation === "belongsToMany" && field.model) {
|
|
327
|
+
const modelA = tableName.toLowerCase();
|
|
328
|
+
const modelB = field.model.toLowerCase();
|
|
329
|
+
const pivot = [modelA, modelB].sort().join("_") + "_pivot";
|
|
330
|
+
pivotTables.push(pivot);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
dropSQL.push(dialect.formatDropSQL(tableName));
|
|
334
|
+
for (const pivot of pivotTables)
|
|
335
|
+
dropSQL.push(dialect.formatDropSQL(pivot));
|
|
336
|
+
return dropSQL;
|
|
337
|
+
}
|
|
338
|
+
/* ============================================================
|
|
339
|
+
* COLUMN BUILDER
|
|
340
|
+
* ============================================================ */
|
|
341
|
+
static columnSQL(name, c, dialectName, dialect) {
|
|
342
|
+
const { type, options } = c;
|
|
343
|
+
const col = dialect.wrap(name);
|
|
344
|
+
const parts = [];
|
|
345
|
+
const typeMap = {
|
|
346
|
+
increments: {
|
|
347
|
+
mysql: "INT AUTO_INCREMENT PRIMARY KEY",
|
|
348
|
+
pg: "SERIAL PRIMARY KEY",
|
|
349
|
+
sqlite: "INTEGER PRIMARY KEY AUTOINCREMENT",
|
|
350
|
+
},
|
|
351
|
+
uuid: { mysql: "CHAR(36)", pg: "UUID", sqlite: "TEXT" },
|
|
352
|
+
string: { mysql: "VARCHAR", pg: "VARCHAR", sqlite: "TEXT" },
|
|
353
|
+
int: { mysql: "INT", pg: "INTEGER", sqlite: "INTEGER" },
|
|
354
|
+
boolean: { mysql: "BOOLEAN", pg: "BOOLEAN", sqlite: "INTEGER" },
|
|
355
|
+
text: { mysql: "TEXT", pg: "TEXT", sqlite: "TEXT" },
|
|
356
|
+
decimal: { mysql: "DECIMAL(10,2)", pg: "NUMERIC(10,2)", sqlite: "REAL" },
|
|
357
|
+
json: { mysql: "JSON", pg: "JSONB", sqlite: "TEXT" },
|
|
358
|
+
timestamp: {
|
|
359
|
+
mysql: "TIMESTAMP DEFAULT CURRENT_TIMESTAMP",
|
|
360
|
+
pg: "TIMESTAMP DEFAULT NOW()",
|
|
361
|
+
sqlite: "DATETIME DEFAULT CURRENT_TIMESTAMP",
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
if (type === "increments")
|
|
365
|
+
return `${col} ${typeMap.increments[dialectName]}`;
|
|
366
|
+
if (typeMap[type]) {
|
|
367
|
+
let sqlType = typeMap[type][dialectName];
|
|
368
|
+
if (type === "string" && options.length)
|
|
369
|
+
sqlType += `(${options.length})`;
|
|
370
|
+
parts.push(`${col} ${sqlType}`);
|
|
371
|
+
}
|
|
372
|
+
else if (type === "softDeletes") {
|
|
373
|
+
return `${dialect.wrap("deleted_at")} ${typeMap.timestamp[dialectName]} NULL`;
|
|
374
|
+
}
|
|
375
|
+
else if (type === "timestamps") {
|
|
376
|
+
const createdAt = `${dialect.wrap("created_at")} ${typeMap.timestamp[dialectName]}`;
|
|
377
|
+
const updatedAt = `${dialect.wrap("updated_at")} ${typeMap.timestamp[dialectName]}`;
|
|
378
|
+
return `${createdAt}, ${updatedAt}`;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
parts.push(`${col} TEXT`);
|
|
382
|
+
}
|
|
383
|
+
if (options.notNull)
|
|
384
|
+
parts.push("NOT NULL");
|
|
385
|
+
if (options.unique)
|
|
386
|
+
parts.push("UNIQUE");
|
|
387
|
+
if (options.primary && type !== "increments")
|
|
388
|
+
parts.push("PRIMARY KEY");
|
|
389
|
+
if (options.default !== undefined) {
|
|
390
|
+
parts.push(`DEFAULT ${this.formatDefaultLiteral(options.default)}`);
|
|
391
|
+
}
|
|
392
|
+
return parts.join(" ");
|
|
393
|
+
}
|
|
394
|
+
/* ============================================================
|
|
395
|
+
* RELATIONS
|
|
396
|
+
* ============================================================ */
|
|
397
|
+
static relationSQL(currentTable, _name, r, dialect, dialectName) {
|
|
398
|
+
const wrap = (v) => dialect.wrap(v);
|
|
399
|
+
const integerType = dialectName === "mysql" ? "INT" : "INTEGER";
|
|
400
|
+
const stringType = dialectName === "sqlite" ? "TEXT" : "VARCHAR(255)";
|
|
401
|
+
if (r.relation === "belongsTo" && r.options.foreignKey && r.model) {
|
|
402
|
+
const fk = r.options.foreignKey;
|
|
403
|
+
const referencedTable = this.referencedTableName(r.model);
|
|
404
|
+
const referencedColumn = r.options.localKey ?? "id";
|
|
405
|
+
const colSql = `${wrap(fk)} ${integerType}`;
|
|
406
|
+
const fkSql = this.foreignKeyConstraintDefinition(currentTable, fk, referencedTable, referencedColumn, dialect, dialectName);
|
|
407
|
+
return {
|
|
408
|
+
type: "inline",
|
|
409
|
+
columns: [{ name: fk, sql: colSql }],
|
|
410
|
+
constraints: [fkSql],
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
if (r.relation === "belongsToMany" && r.model) {
|
|
414
|
+
const tableA = currentTable.toLowerCase();
|
|
415
|
+
const tableB = r.model.toLowerCase().endsWith("s")
|
|
416
|
+
? r.model.toLowerCase()
|
|
417
|
+
: `${r.model.toLowerCase()}s`;
|
|
418
|
+
const keyA = tableA.endsWith("s") ? tableA.slice(0, -1) : tableA;
|
|
419
|
+
// tableB is normalized above to always end with "s".
|
|
420
|
+
const keyB = tableB.slice(0, -1);
|
|
421
|
+
const pivotTable = [keyA, keyB].sort().join("_") + "_pivot";
|
|
422
|
+
const pivotSides = [
|
|
423
|
+
{ key: keyA, table: tableA },
|
|
424
|
+
{ key: keyB, table: tableB },
|
|
425
|
+
].sort((left, right) => left.key.localeCompare(right.key));
|
|
426
|
+
const pivotSQL = dialect.formatCreateSQL(pivotTable, [
|
|
427
|
+
`${wrap(pivotSides[0].key + "_id")} ${integerType} NOT NULL`,
|
|
428
|
+
`${wrap(pivotSides[1].key + "_id")} ${integerType} NOT NULL`,
|
|
429
|
+
`PRIMARY KEY (${wrap(pivotSides[0].key + "_id")}, ${wrap(pivotSides[1].key + "_id")})`,
|
|
430
|
+
`FOREIGN KEY (${wrap(pivotSides[0].key + "_id")}) REFERENCES ${wrap(pivotSides[0].table)}(${wrap("id")})`,
|
|
431
|
+
`FOREIGN KEY (${wrap(pivotSides[1].key + "_id")}) REFERENCES ${wrap(pivotSides[1].table)}(${wrap("id")})`,
|
|
432
|
+
]);
|
|
433
|
+
return { type: "pivot", sql: pivotSQL, tableName: pivotTable };
|
|
434
|
+
}
|
|
435
|
+
if (r.relation === "morphTo") {
|
|
436
|
+
const morphName = r.options.morphName ?? "morphable";
|
|
437
|
+
const idName = morphName + "_id";
|
|
438
|
+
const typeName = morphName + "_type";
|
|
439
|
+
const idSql = `${wrap(idName)} ${integerType}`;
|
|
440
|
+
const typeSql = `${wrap(typeName)} ${stringType}`;
|
|
441
|
+
return {
|
|
442
|
+
type: "morph",
|
|
443
|
+
sqls: [idSql, typeSql],
|
|
444
|
+
columns: [
|
|
445
|
+
{ name: idName, sql: idSql },
|
|
446
|
+
{ name: typeName, sql: typeSql },
|
|
447
|
+
],
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
// Inverse-side relations do not own columns on the current table.
|
|
451
|
+
// Their schema effects are represented by belongsTo / morphTo on the related model.
|
|
452
|
+
if (r.relation === "hasOne" ||
|
|
453
|
+
r.relation === "hasMany" ||
|
|
454
|
+
r.relation === "morphOne" ||
|
|
455
|
+
r.relation === "morphMany") {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
/* ============================================================
|
|
461
|
+
* MIXINS
|
|
462
|
+
* ============================================================ */
|
|
463
|
+
static formatDefaultLiteral(value) {
|
|
464
|
+
if (value === null || value === undefined)
|
|
465
|
+
return "NULL";
|
|
466
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
467
|
+
return String(value);
|
|
468
|
+
if (typeof value === "boolean")
|
|
469
|
+
return value ? "1" : "0";
|
|
470
|
+
const raw = String(value);
|
|
471
|
+
const upper = raw.toUpperCase();
|
|
472
|
+
if (upper.includes("CURRENT_TIMESTAMP") ||
|
|
473
|
+
upper === "NOW()" ||
|
|
474
|
+
upper.endsWith("()")) {
|
|
475
|
+
return raw;
|
|
476
|
+
}
|
|
477
|
+
if ((raw.startsWith("'") && raw.endsWith("'")) ||
|
|
478
|
+
(raw.startsWith('"') && raw.endsWith('"'))) {
|
|
479
|
+
return raw;
|
|
480
|
+
}
|
|
481
|
+
return `'${raw.replace(/'/g, "''")}'`;
|
|
482
|
+
}
|
|
483
|
+
static mysqlColumnSQL(column, dialect) {
|
|
484
|
+
const parts = [`${dialect.wrap(column.Field)} ${column.Type.toUpperCase()}`];
|
|
485
|
+
if (column.Null === "NO")
|
|
486
|
+
parts.push("NOT NULL");
|
|
487
|
+
if (column.Default !== null && column.Default !== undefined) {
|
|
488
|
+
parts.push(`DEFAULT ${this.formatDefaultLiteral(column.Default)}`);
|
|
489
|
+
}
|
|
490
|
+
if (typeof column.Extra === "string" && column.Extra.toLowerCase().includes("auto_increment")) {
|
|
491
|
+
parts.push("AUTO_INCREMENT");
|
|
492
|
+
}
|
|
493
|
+
if (column.Key === "UNI")
|
|
494
|
+
parts.push("UNIQUE");
|
|
495
|
+
return parts.join(" ");
|
|
496
|
+
}
|
|
497
|
+
static pgTypeSQL(column) {
|
|
498
|
+
const dataType = column.data_type;
|
|
499
|
+
if (dataType === "character varying") {
|
|
500
|
+
return column.character_maximum_length
|
|
501
|
+
? `VARCHAR(${column.character_maximum_length})`
|
|
502
|
+
: "VARCHAR";
|
|
503
|
+
}
|
|
504
|
+
if (dataType === "character") {
|
|
505
|
+
return column.character_maximum_length
|
|
506
|
+
? `CHAR(${column.character_maximum_length})`
|
|
507
|
+
: "CHAR";
|
|
508
|
+
}
|
|
509
|
+
if (dataType === "numeric") {
|
|
510
|
+
if (column.numeric_precision != null && column.numeric_scale != null) {
|
|
511
|
+
return `NUMERIC(${column.numeric_precision},${column.numeric_scale})`;
|
|
512
|
+
}
|
|
513
|
+
if (column.numeric_precision != null) {
|
|
514
|
+
return `NUMERIC(${column.numeric_precision})`;
|
|
515
|
+
}
|
|
516
|
+
return "NUMERIC";
|
|
517
|
+
}
|
|
518
|
+
if (dataType === "timestamp without time zone")
|
|
519
|
+
return "TIMESTAMP";
|
|
520
|
+
if (dataType === "timestamp with time zone")
|
|
521
|
+
return "TIMESTAMPTZ";
|
|
522
|
+
if (dataType === "USER-DEFINED" && column.udt_name)
|
|
523
|
+
return column.udt_name;
|
|
524
|
+
return dataType.toUpperCase();
|
|
525
|
+
}
|
|
526
|
+
static pgColumnSQL(column, dialect) {
|
|
527
|
+
const parts = [`${dialect.wrap(column.column_name)} ${this.pgTypeSQL(column)}`];
|
|
528
|
+
if (column.is_nullable === "NO")
|
|
529
|
+
parts.push("NOT NULL");
|
|
530
|
+
if (column.column_default !== null && column.column_default !== undefined) {
|
|
531
|
+
parts.push(`DEFAULT ${column.column_default}`);
|
|
532
|
+
}
|
|
533
|
+
return parts.join(" ");
|
|
534
|
+
}
|
|
535
|
+
static sqliteColumnSQL(column, dialect) {
|
|
536
|
+
const type = column.type?.trim() ? column.type : "TEXT";
|
|
537
|
+
const parts = [`${dialect.wrap(column.name)} ${type}`];
|
|
538
|
+
if (column.notnull === 1)
|
|
539
|
+
parts.push("NOT NULL");
|
|
540
|
+
if (column.dflt_value !== null && column.dflt_value !== undefined) {
|
|
541
|
+
parts.push(`DEFAULT ${column.dflt_value}`);
|
|
542
|
+
}
|
|
543
|
+
if (column.pk === 1)
|
|
544
|
+
parts.push("PRIMARY KEY");
|
|
545
|
+
return parts.join(" ");
|
|
546
|
+
}
|
|
547
|
+
static referencedTableName(model) {
|
|
548
|
+
return model.toLowerCase().endsWith("s") ? model.toLowerCase() : `${model.toLowerCase()}s`;
|
|
549
|
+
}
|
|
550
|
+
static foreignKeyConstraintName(tableName, foreignKey) {
|
|
551
|
+
return `${tableName}_${foreignKey}_foreign`;
|
|
552
|
+
}
|
|
553
|
+
static foreignKeyConstraintKey(foreignKey, referencedTable, referencedColumn) {
|
|
554
|
+
return `fk:${foreignKey}:${referencedTable}:${referencedColumn}`;
|
|
555
|
+
}
|
|
556
|
+
static foreignKeyConstraintDefinition(tableName, foreignKey, referencedTable, referencedColumn, dialect, dialectName, existingName) {
|
|
557
|
+
const wrap = (value) => dialect.wrap(value);
|
|
558
|
+
const constraintName = existingName ?? this.foreignKeyConstraintName(tableName, foreignKey);
|
|
559
|
+
const key = this.foreignKeyConstraintKey(foreignKey, referencedTable, referencedColumn);
|
|
560
|
+
const createSql = `FOREIGN KEY (${wrap(foreignKey)}) REFERENCES ${wrap(referencedTable)}(${wrap(referencedColumn)})`;
|
|
561
|
+
const addClause = dialectName === "sqlite"
|
|
562
|
+
? ""
|
|
563
|
+
: `ADD CONSTRAINT ${wrap(constraintName)} ${createSql}`;
|
|
564
|
+
const dropClause = dialectName === "mysql"
|
|
565
|
+
? `DROP FOREIGN KEY ${wrap(constraintName)}`
|
|
566
|
+
: dialectName === "pg"
|
|
567
|
+
? `DROP CONSTRAINT ${wrap(constraintName)}`
|
|
568
|
+
: "";
|
|
569
|
+
return {
|
|
570
|
+
key,
|
|
571
|
+
createSql,
|
|
572
|
+
addClause,
|
|
573
|
+
dropClause,
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
static async mysqlForeignKeys(adapter, tableName, dialect) {
|
|
577
|
+
const rows = await adapter.query(`SELECT
|
|
578
|
+
CONSTRAINT_NAME AS constraint_name,
|
|
579
|
+
COLUMN_NAME AS column_name,
|
|
580
|
+
REFERENCED_TABLE_NAME AS referenced_table_name,
|
|
581
|
+
REFERENCED_COLUMN_NAME AS referenced_column_name
|
|
582
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
583
|
+
WHERE TABLE_SCHEMA = DATABASE()
|
|
584
|
+
AND TABLE_NAME = ${adapter.placeholder(1)}
|
|
585
|
+
AND REFERENCED_TABLE_NAME IS NOT NULL`, [tableName]);
|
|
586
|
+
return rows.map((row) => {
|
|
587
|
+
const definition = this.foreignKeyConstraintDefinition(tableName, row.column_name, row.referenced_table_name, row.referenced_column_name, dialect, "mysql", row.constraint_name);
|
|
588
|
+
return {
|
|
589
|
+
key: definition.key,
|
|
590
|
+
addClause: definition.addClause,
|
|
591
|
+
dropClause: definition.dropClause,
|
|
592
|
+
};
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
static async pgForeignKeys(adapter, tableName, dialect) {
|
|
596
|
+
const rows = await adapter.query(`SELECT
|
|
597
|
+
tc.constraint_name,
|
|
598
|
+
kcu.column_name,
|
|
599
|
+
ccu.table_name AS referenced_table_name,
|
|
600
|
+
ccu.column_name AS referenced_column_name
|
|
601
|
+
FROM information_schema.table_constraints tc
|
|
602
|
+
JOIN information_schema.key_column_usage kcu
|
|
603
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
604
|
+
AND tc.table_schema = kcu.table_schema
|
|
605
|
+
JOIN information_schema.constraint_column_usage ccu
|
|
606
|
+
ON ccu.constraint_name = tc.constraint_name
|
|
607
|
+
AND ccu.table_schema = tc.table_schema
|
|
608
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
609
|
+
AND tc.table_schema = current_schema()
|
|
610
|
+
AND tc.table_name = ${adapter.placeholder(1)}`, [tableName]);
|
|
611
|
+
return rows.map((row) => {
|
|
612
|
+
const definition = this.foreignKeyConstraintDefinition(tableName, row.column_name, row.referenced_table_name, row.referenced_column_name, dialect, "pg", row.constraint_name);
|
|
613
|
+
return {
|
|
614
|
+
key: definition.key,
|
|
615
|
+
addClause: definition.addClause,
|
|
616
|
+
dropClause: definition.dropClause,
|
|
617
|
+
};
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
static async sqliteForeignKeys(adapter, tableName, dialect) {
|
|
621
|
+
const rows = await adapter.query(`PRAGMA foreign_key_list(${dialect.wrap(tableName)});`);
|
|
622
|
+
return rows.map((row) => {
|
|
623
|
+
const definition = this.foreignKeyConstraintDefinition(tableName, row.from, row.table, row.to || "id", dialect, "sqlite");
|
|
624
|
+
return {
|
|
625
|
+
key: definition.key,
|
|
626
|
+
addClause: definition.addClause,
|
|
627
|
+
dropClause: definition.dropClause,
|
|
628
|
+
};
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
static async pivotTableExists(adapter, dialectName, dialect, pivotTable) {
|
|
632
|
+
if (dialectName === "mysql") {
|
|
633
|
+
const rows = await adapter.query(`SHOW TABLES LIKE ${adapter.placeholder(1)}`, [pivotTable]);
|
|
634
|
+
return rows.length > 0;
|
|
635
|
+
}
|
|
636
|
+
if (dialectName === "pg") {
|
|
637
|
+
const rows = await adapter.query(`SELECT table_name
|
|
638
|
+
FROM information_schema.tables
|
|
639
|
+
WHERE table_schema = current_schema()
|
|
640
|
+
AND table_name = ${adapter.placeholder(1)}`, [pivotTable]);
|
|
641
|
+
return rows.length > 0;
|
|
642
|
+
}
|
|
643
|
+
const rows = await adapter.query(`SELECT name
|
|
644
|
+
FROM sqlite_master
|
|
645
|
+
WHERE type = 'table'
|
|
646
|
+
AND name = ${adapter.placeholder(1)}`, [pivotTable]);
|
|
647
|
+
return rows.length > 0;
|
|
648
|
+
}
|
|
649
|
+
static mixinSQL(m, dialectName, dialect) {
|
|
650
|
+
switch (m.name) {
|
|
651
|
+
case "SoftDeletes":
|
|
652
|
+
return [
|
|
653
|
+
`${dialect.wrap("deleted_at")} ${dialectName === "sqlite" ? "DATETIME" : "TIMESTAMP"} NULL DEFAULT NULL`,
|
|
654
|
+
];
|
|
655
|
+
default:
|
|
656
|
+
return [];
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
exports.SchemaBuilder = SchemaBuilder;
|
|
661
|
+
//# sourceMappingURL=SchemaBuilder.js.map
|