@warlock.js/cascade 4.0.157 → 4.0.158
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/package.json +4 -4
- package/cjs/context/database-data-source-context.d.ts +0 -29
- package/cjs/context/database-data-source-context.d.ts.map +0 -1
- package/cjs/context/database-data-source-context.js +0 -28
- package/cjs/context/database-data-source-context.js.map +0 -1
- package/cjs/context/database-transaction-context.d.ts +0 -35
- package/cjs/context/database-transaction-context.d.ts.map +0 -1
- package/cjs/context/database-transaction-context.js +0 -40
- package/cjs/context/database-transaction-context.js.map +0 -1
- package/cjs/contracts/database-driver.contract.d.ts +0 -450
- package/cjs/contracts/database-driver.contract.d.ts.map +0 -1
- package/cjs/contracts/database-id-generator.contract.d.ts +0 -109
- package/cjs/contracts/database-id-generator.contract.d.ts.map +0 -1
- package/cjs/contracts/database-remover.contract.d.ts +0 -104
- package/cjs/contracts/database-remover.contract.d.ts.map +0 -1
- package/cjs/contracts/database-restorer.contract.d.ts +0 -143
- package/cjs/contracts/database-restorer.contract.d.ts.map +0 -1
- package/cjs/contracts/database-writer.contract.d.ts +0 -119
- package/cjs/contracts/database-writer.contract.d.ts.map +0 -1
- package/cjs/contracts/driver-blueprint.contract.d.ts +0 -49
- package/cjs/contracts/driver-blueprint.contract.d.ts.map +0 -1
- package/cjs/contracts/index.d.ts +0 -10
- package/cjs/contracts/index.d.ts.map +0 -1
- package/cjs/contracts/migration-driver.contract.d.ts +0 -522
- package/cjs/contracts/migration-driver.contract.d.ts.map +0 -1
- package/cjs/contracts/query-builder.contract.d.ts +0 -1609
- package/cjs/contracts/query-builder.contract.d.ts.map +0 -1
- package/cjs/contracts/sync-adapter.contract.d.ts +0 -58
- package/cjs/contracts/sync-adapter.contract.d.ts.map +0 -1
- package/cjs/data-source/data-source-registry.d.ts +0 -108
- package/cjs/data-source/data-source-registry.d.ts.map +0 -1
- package/cjs/data-source/data-source-registry.js +0 -145
- package/cjs/data-source/data-source-registry.js.map +0 -1
- package/cjs/data-source/data-source.d.ts +0 -147
- package/cjs/data-source/data-source.d.ts.map +0 -1
- package/cjs/data-source/data-source.js +0 -83
- package/cjs/data-source/data-source.js.map +0 -1
- package/cjs/database-dirty-tracker.d.ts +0 -252
- package/cjs/database-dirty-tracker.d.ts.map +0 -1
- package/cjs/database-dirty-tracker.js +0 -386
- package/cjs/database-dirty-tracker.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-blueprint.d.ts +0 -30
- package/cjs/drivers/mongodb/mongodb-blueprint.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-blueprint.js +0 -51
- package/cjs/drivers/mongodb/mongodb-blueprint.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-driver.d.ts +0 -324
- package/cjs/drivers/mongodb/mongodb-driver.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-driver.js +0 -799
- package/cjs/drivers/mongodb/mongodb-driver.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-id-generator.d.ts +0 -116
- package/cjs/drivers/mongodb/mongodb-id-generator.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-id-generator.js +0 -149
- package/cjs/drivers/mongodb/mongodb-id-generator.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts +0 -317
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-migration-driver.js +0 -666
- package/cjs/drivers/mongodb/mongodb-migration-driver.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts +0 -1122
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-builder.js +0 -1988
- package/cjs/drivers/mongodb/mongodb-query-builder.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-operations.d.ts +0 -226
- package/cjs/drivers/mongodb/mongodb-query-operations.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-operations.js +0 -270
- package/cjs/drivers/mongodb/mongodb-query-operations.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-parser.d.ts +0 -262
- package/cjs/drivers/mongodb/mongodb-query-parser.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-parser.js +0 -1351
- package/cjs/drivers/mongodb/mongodb-query-parser.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts +0 -79
- package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-sync-adapter.js +0 -146
- package/cjs/drivers/mongodb/mongodb-sync-adapter.js.map +0 -1
- package/cjs/drivers/mongodb/types.d.ts +0 -43
- package/cjs/drivers/mongodb/types.d.ts.map +0 -1
- package/cjs/drivers/postgres/index.d.ts +0 -16
- package/cjs/drivers/postgres/index.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-blueprint.d.ts +0 -64
- package/cjs/drivers/postgres/postgres-blueprint.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-blueprint.js +0 -121
- package/cjs/drivers/postgres/postgres-blueprint.js.map +0 -1
- package/cjs/drivers/postgres/postgres-dialect.d.ts +0 -136
- package/cjs/drivers/postgres/postgres-dialect.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-dialect.js +0 -268
- package/cjs/drivers/postgres/postgres-dialect.js.map +0 -1
- package/cjs/drivers/postgres/postgres-driver.d.ts +0 -432
- package/cjs/drivers/postgres/postgres-driver.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-driver.js +0 -965
- package/cjs/drivers/postgres/postgres-driver.js.map +0 -1
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts +0 -397
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-migration-driver.js +0 -900
- package/cjs/drivers/postgres/postgres-migration-driver.js.map +0 -1
- package/cjs/drivers/postgres/postgres-query-builder.d.ts +0 -254
- package/cjs/drivers/postgres/postgres-query-builder.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-query-builder.js +0 -933
- package/cjs/drivers/postgres/postgres-query-builder.js.map +0 -1
- package/cjs/drivers/postgres/postgres-query-parser.d.ts +0 -328
- package/cjs/drivers/postgres/postgres-query-parser.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-query-parser.js +0 -864
- package/cjs/drivers/postgres/postgres-query-parser.js.map +0 -1
- package/cjs/drivers/postgres/postgres-sql-serializer.d.ts +0 -37
- package/cjs/drivers/postgres/postgres-sql-serializer.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-sql-serializer.js +0 -400
- package/cjs/drivers/postgres/postgres-sql-serializer.js.map +0 -1
- package/cjs/drivers/postgres/postgres-sync-adapter.d.ts +0 -83
- package/cjs/drivers/postgres/postgres-sync-adapter.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-sync-adapter.js +0 -197
- package/cjs/drivers/postgres/postgres-sync-adapter.js.map +0 -1
- package/cjs/drivers/postgres/types.d.ts +0 -142
- package/cjs/drivers/postgres/types.d.ts.map +0 -1
- package/cjs/drivers/sql/index.d.ts +0 -10
- package/cjs/drivers/sql/index.d.ts.map +0 -1
- package/cjs/drivers/sql/sql-dialect.contract.d.ts +0 -204
- package/cjs/drivers/sql/sql-dialect.contract.d.ts.map +0 -1
- package/cjs/drivers/sql/sql-types.d.ts +0 -202
- package/cjs/drivers/sql/sql-types.d.ts.map +0 -1
- package/cjs/errors/missing-data-source.error.d.ts +0 -22
- package/cjs/errors/missing-data-source.error.d.ts.map +0 -1
- package/cjs/errors/missing-data-source.error.js +0 -29
- package/cjs/errors/missing-data-source.error.js.map +0 -1
- package/cjs/errors/transaction-rollback.error.d.ts +0 -20
- package/cjs/errors/transaction-rollback.error.d.ts.map +0 -1
- package/cjs/errors/transaction-rollback.error.js +0 -27
- package/cjs/errors/transaction-rollback.error.js.map +0 -1
- package/cjs/events/model-events.d.ts +0 -231
- package/cjs/events/model-events.d.ts.map +0 -1
- package/cjs/events/model-events.js +0 -259
- package/cjs/events/model-events.js.map +0 -1
- package/cjs/expressions/aggregate-expressions.d.ts +0 -215
- package/cjs/expressions/aggregate-expressions.d.ts.map +0 -1
- package/cjs/expressions/aggregate-expressions.js +0 -221
- package/cjs/expressions/aggregate-expressions.js.map +0 -1
- package/cjs/expressions/index.d.ts +0 -2
- package/cjs/expressions/index.d.ts.map +0 -1
- package/cjs/index.d.ts +0 -45
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/migration/column-builder.d.ts +0 -417
- package/cjs/migration/column-builder.d.ts.map +0 -1
- package/cjs/migration/column-builder.js +0 -586
- package/cjs/migration/column-builder.js.map +0 -1
- package/cjs/migration/column-helpers.d.ts +0 -275
- package/cjs/migration/column-helpers.d.ts.map +0 -1
- package/cjs/migration/column-helpers.js +0 -389
- package/cjs/migration/column-helpers.js.map +0 -1
- package/cjs/migration/foreign-key-builder.d.ts +0 -103
- package/cjs/migration/foreign-key-builder.d.ts.map +0 -1
- package/cjs/migration/foreign-key-builder.js +0 -121
- package/cjs/migration/foreign-key-builder.js.map +0 -1
- package/cjs/migration/index.d.ts +0 -7
- package/cjs/migration/index.d.ts.map +0 -1
- package/cjs/migration/migration-runner.d.ts +0 -278
- package/cjs/migration/migration-runner.d.ts.map +0 -1
- package/cjs/migration/migration-runner.js +0 -815
- package/cjs/migration/migration-runner.js.map +0 -1
- package/cjs/migration/migration.d.ts +0 -1992
- package/cjs/migration/migration.d.ts.map +0 -1
- package/cjs/migration/migration.js +0 -2162
- package/cjs/migration/migration.js.map +0 -1
- package/cjs/migration/sql-grammar.d.ts +0 -61
- package/cjs/migration/sql-grammar.d.ts.map +0 -1
- package/cjs/migration/sql-grammar.js +0 -164
- package/cjs/migration/sql-grammar.js.map +0 -1
- package/cjs/migration/sql-serializer.d.ts +0 -22
- package/cjs/migration/sql-serializer.d.ts.map +0 -1
- package/cjs/migration/sql-serializer.js +0 -26
- package/cjs/migration/sql-serializer.js.map +0 -1
- package/cjs/migration/types.d.ts +0 -155
- package/cjs/migration/types.d.ts.map +0 -1
- package/cjs/model/methods/accessor-methods.d.ts +0 -13
- package/cjs/model/methods/accessor-methods.d.ts.map +0 -1
- package/cjs/model/methods/accessor-methods.js +0 -51
- package/cjs/model/methods/accessor-methods.js.map +0 -1
- package/cjs/model/methods/delete-methods.d.ts +0 -10
- package/cjs/model/methods/delete-methods.d.ts.map +0 -1
- package/cjs/model/methods/delete-methods.js +0 -10
- package/cjs/model/methods/delete-methods.js.map +0 -1
- package/cjs/model/methods/dirty-methods.d.ts +0 -10
- package/cjs/model/methods/dirty-methods.d.ts.map +0 -1
- package/cjs/model/methods/dirty-methods.js +0 -15
- package/cjs/model/methods/dirty-methods.js.map +0 -1
- package/cjs/model/methods/hydration-methods.d.ts +0 -10
- package/cjs/model/methods/hydration-methods.d.ts.map +0 -1
- package/cjs/model/methods/hydration-methods.js +0 -57
- package/cjs/model/methods/hydration-methods.js.map +0 -1
- package/cjs/model/methods/instance-event-methods.d.ts +0 -7
- package/cjs/model/methods/instance-event-methods.d.ts.map +0 -1
- package/cjs/model/methods/instance-event-methods.js +0 -15
- package/cjs/model/methods/instance-event-methods.js.map +0 -1
- package/cjs/model/methods/meta-methods.d.ts +0 -7
- package/cjs/model/methods/meta-methods.d.ts.map +0 -1
- package/cjs/model/methods/meta-methods.js +0 -78
- package/cjs/model/methods/meta-methods.js.map +0 -1
- package/cjs/model/methods/query-methods.d.ts +0 -24
- package/cjs/model/methods/query-methods.d.ts.map +0 -1
- package/cjs/model/methods/query-methods.js +0 -161
- package/cjs/model/methods/query-methods.js.map +0 -1
- package/cjs/model/methods/restore-methods.d.ts +0 -10
- package/cjs/model/methods/restore-methods.d.ts.map +0 -1
- package/cjs/model/methods/restore-methods.js +0 -13
- package/cjs/model/methods/restore-methods.js.map +0 -1
- package/cjs/model/methods/scope-methods.d.ts +0 -7
- package/cjs/model/methods/scope-methods.d.ts.map +0 -1
- package/cjs/model/methods/scope-methods.js +0 -15
- package/cjs/model/methods/scope-methods.js.map +0 -1
- package/cjs/model/methods/serialization-methods.d.ts +0 -3
- package/cjs/model/methods/serialization-methods.d.ts.map +0 -1
- package/cjs/model/methods/serialization-methods.js +0 -27
- package/cjs/model/methods/serialization-methods.js.map +0 -1
- package/cjs/model/methods/static-event-methods.d.ts +0 -9
- package/cjs/model/methods/static-event-methods.d.ts.map +0 -1
- package/cjs/model/methods/static-event-methods.js +0 -29
- package/cjs/model/methods/static-event-methods.js.map +0 -1
- package/cjs/model/methods/write-methods.d.ts +0 -10
- package/cjs/model/methods/write-methods.d.ts.map +0 -1
- package/cjs/model/methods/write-methods.js +0 -52
- package/cjs/model/methods/write-methods.js.map +0 -1
- package/cjs/model/model.d.ts +0 -1650
- package/cjs/model/model.d.ts.map +0 -1
- package/cjs/model/model.js +0 -1657
- package/cjs/model/model.js.map +0 -1
- package/cjs/model/model.types.d.ts +0 -44
- package/cjs/model/model.types.d.ts.map +0 -1
- package/cjs/model/register-model.d.ts +0 -81
- package/cjs/model/register-model.d.ts.map +0 -1
- package/cjs/model/register-model.js +0 -94
- package/cjs/model/register-model.js.map +0 -1
- package/cjs/query-builder/query-builder.d.ts +0 -556
- package/cjs/query-builder/query-builder.d.ts.map +0 -1
- package/cjs/query-builder/query-builder.js +0 -1070
- package/cjs/query-builder/query-builder.js.map +0 -1
- package/cjs/relations/helpers.d.ts +0 -156
- package/cjs/relations/helpers.d.ts.map +0 -1
- package/cjs/relations/helpers.js +0 -201
- package/cjs/relations/helpers.js.map +0 -1
- package/cjs/relations/index.d.ts +0 -35
- package/cjs/relations/index.d.ts.map +0 -1
- package/cjs/relations/pivot-operations.d.ts +0 -160
- package/cjs/relations/pivot-operations.d.ts.map +0 -1
- package/cjs/relations/pivot-operations.js +0 -293
- package/cjs/relations/pivot-operations.js.map +0 -1
- package/cjs/relations/relation-hydrator.d.ts +0 -68
- package/cjs/relations/relation-hydrator.d.ts.map +0 -1
- package/cjs/relations/relation-hydrator.js +0 -81
- package/cjs/relations/relation-hydrator.js.map +0 -1
- package/cjs/relations/relation-loader.d.ts +0 -194
- package/cjs/relations/relation-loader.d.ts.map +0 -1
- package/cjs/relations/relation-loader.js +0 -466
- package/cjs/relations/relation-loader.js.map +0 -1
- package/cjs/relations/types.d.ts +0 -306
- package/cjs/relations/types.d.ts.map +0 -1
- package/cjs/remover/database-remover.d.ts +0 -100
- package/cjs/remover/database-remover.d.ts.map +0 -1
- package/cjs/remover/database-remover.js +0 -214
- package/cjs/remover/database-remover.js.map +0 -1
- package/cjs/restorer/database-restorer.d.ts +0 -131
- package/cjs/restorer/database-restorer.d.ts.map +0 -1
- package/cjs/restorer/database-restorer.js +0 -434
- package/cjs/restorer/database-restorer.js.map +0 -1
- package/cjs/sql-database-dirty-tracker.d.ts +0 -13
- package/cjs/sql-database-dirty-tracker.d.ts.map +0 -1
- package/cjs/sql-database-dirty-tracker.js +0 -14
- package/cjs/sql-database-dirty-tracker.js.map +0 -1
- package/cjs/sync/index.d.ts +0 -12
- package/cjs/sync/index.d.ts.map +0 -1
- package/cjs/sync/model-events.d.ts +0 -62
- package/cjs/sync/model-events.d.ts.map +0 -1
- package/cjs/sync/model-events.js +0 -49
- package/cjs/sync/model-events.js.map +0 -1
- package/cjs/sync/model-sync-operation.d.ts +0 -163
- package/cjs/sync/model-sync-operation.d.ts.map +0 -1
- package/cjs/sync/model-sync-operation.js +0 -292
- package/cjs/sync/model-sync-operation.js.map +0 -1
- package/cjs/sync/model-sync.d.ts +0 -130
- package/cjs/sync/model-sync.d.ts.map +0 -1
- package/cjs/sync/model-sync.js +0 -178
- package/cjs/sync/model-sync.js.map +0 -1
- package/cjs/sync/sync-context.d.ts +0 -70
- package/cjs/sync/sync-context.d.ts.map +0 -1
- package/cjs/sync/sync-context.js +0 -101
- package/cjs/sync/sync-context.js.map +0 -1
- package/cjs/sync/sync-manager.d.ts +0 -213
- package/cjs/sync/sync-manager.d.ts.map +0 -1
- package/cjs/sync/sync-manager.js +0 -689
- package/cjs/sync/sync-manager.js.map +0 -1
- package/cjs/sync/types.d.ts +0 -289
- package/cjs/sync/types.d.ts.map +0 -1
- package/cjs/test-migrations/test-enhanced-features.migration.d.ts +0 -15
- package/cjs/test-migrations/test-enhanced-features.migration.d.ts.map +0 -1
- package/cjs/types.d.ts +0 -371
- package/cjs/types.d.ts.map +0 -1
- package/cjs/utils/connect-to-database.d.ts +0 -300
- package/cjs/utils/connect-to-database.d.ts.map +0 -1
- package/cjs/utils/connect-to-database.js +0 -128
- package/cjs/utils/connect-to-database.js.map +0 -1
- package/cjs/utils/database-writer.utils.d.ts +0 -15
- package/cjs/utils/database-writer.utils.d.ts.map +0 -1
- package/cjs/utils/database-writer.utils.js +0 -14
- package/cjs/utils/database-writer.utils.js.map +0 -1
- package/cjs/utils/define-model.js +0 -100
- package/cjs/utils/define-model.js.map +0 -1
- package/cjs/utils/is-valid-date-value.d.ts +0 -5
- package/cjs/utils/is-valid-date-value.d.ts.map +0 -1
- package/cjs/utils/is-valid-date-value.js +0 -25
- package/cjs/utils/is-valid-date-value.js.map +0 -1
- package/cjs/utils/once-connected.d.ts +0 -146
- package/cjs/utils/once-connected.d.ts.map +0 -1
- package/cjs/utils/once-connected.js +0 -251
- package/cjs/utils/once-connected.js.map +0 -1
- package/cjs/validation/database-seal-plugins.d.ts +0 -12
- package/cjs/validation/database-seal-plugins.d.ts.map +0 -1
- package/cjs/validation/database-seal-plugins.js +0 -1
- package/cjs/validation/database-seal-plugins.js.map +0 -1
- package/cjs/validation/database-writer-validation-error.d.ts +0 -97
- package/cjs/validation/database-writer-validation-error.d.ts.map +0 -1
- package/cjs/validation/database-writer-validation-error.js +0 -160
- package/cjs/validation/database-writer-validation-error.js.map +0 -1
- package/cjs/validation/index.d.ts +0 -3
- package/cjs/validation/index.d.ts.map +0 -1
- package/cjs/validation/mutators/embed-mutator.d.ts +0 -9
- package/cjs/validation/mutators/embed-mutator.d.ts.map +0 -1
- package/cjs/validation/mutators/embed-mutator.js +0 -33
- package/cjs/validation/mutators/embed-mutator.js.map +0 -1
- package/cjs/validation/plugins/embed-validator-plugin.d.ts +0 -24
- package/cjs/validation/plugins/embed-validator-plugin.d.ts.map +0 -1
- package/cjs/validation/plugins/embed-validator-plugin.js +0 -18
- package/cjs/validation/plugins/embed-validator-plugin.js.map +0 -1
- package/cjs/validation/rules/database-model-rule.d.ts +0 -7
- package/cjs/validation/rules/database-model-rule.d.ts.map +0 -1
- package/cjs/validation/rules/database-model-rule.js +0 -27
- package/cjs/validation/rules/database-model-rule.js.map +0 -1
- package/cjs/validation/transformers/embed-model-transformer.d.ts +0 -3
- package/cjs/validation/transformers/embed-model-transformer.d.ts.map +0 -1
- package/cjs/validation/transformers/embed-model-transformer.js +0 -18
- package/cjs/validation/transformers/embed-model-transformer.js.map +0 -1
- package/cjs/validation/validators/embed-validator.d.ts +0 -21
- package/cjs/validation/validators/embed-validator.d.ts.map +0 -1
- package/cjs/validation/validators/embed-validator.js +0 -43
- package/cjs/validation/validators/embed-validator.js.map +0 -1
- package/cjs/writer/database-writer.d.ts +0 -181
- package/cjs/writer/database-writer.d.ts.map +0 -1
- package/cjs/writer/database-writer.js +0 -407
- package/cjs/writer/database-writer.js.map +0 -1
- package/esm/context/database-data-source-context.d.ts +0 -29
- package/esm/context/database-data-source-context.d.ts.map +0 -1
- package/esm/context/database-data-source-context.js +0 -28
- package/esm/context/database-data-source-context.js.map +0 -1
- package/esm/context/database-transaction-context.d.ts +0 -35
- package/esm/context/database-transaction-context.d.ts.map +0 -1
- package/esm/context/database-transaction-context.js +0 -40
- package/esm/context/database-transaction-context.js.map +0 -1
- package/esm/contracts/database-driver.contract.d.ts +0 -450
- package/esm/contracts/database-driver.contract.d.ts.map +0 -1
- package/esm/contracts/database-id-generator.contract.d.ts +0 -109
- package/esm/contracts/database-id-generator.contract.d.ts.map +0 -1
- package/esm/contracts/database-remover.contract.d.ts +0 -104
- package/esm/contracts/database-remover.contract.d.ts.map +0 -1
- package/esm/contracts/database-restorer.contract.d.ts +0 -143
- package/esm/contracts/database-restorer.contract.d.ts.map +0 -1
- package/esm/contracts/database-writer.contract.d.ts +0 -119
- package/esm/contracts/database-writer.contract.d.ts.map +0 -1
- package/esm/contracts/driver-blueprint.contract.d.ts +0 -49
- package/esm/contracts/driver-blueprint.contract.d.ts.map +0 -1
- package/esm/contracts/index.d.ts +0 -10
- package/esm/contracts/index.d.ts.map +0 -1
- package/esm/contracts/migration-driver.contract.d.ts +0 -522
- package/esm/contracts/migration-driver.contract.d.ts.map +0 -1
- package/esm/contracts/query-builder.contract.d.ts +0 -1609
- package/esm/contracts/query-builder.contract.d.ts.map +0 -1
- package/esm/contracts/sync-adapter.contract.d.ts +0 -58
- package/esm/contracts/sync-adapter.contract.d.ts.map +0 -1
- package/esm/data-source/data-source-registry.d.ts +0 -108
- package/esm/data-source/data-source-registry.d.ts.map +0 -1
- package/esm/data-source/data-source-registry.js +0 -145
- package/esm/data-source/data-source-registry.js.map +0 -1
- package/esm/data-source/data-source.d.ts +0 -147
- package/esm/data-source/data-source.d.ts.map +0 -1
- package/esm/data-source/data-source.js +0 -83
- package/esm/data-source/data-source.js.map +0 -1
- package/esm/database-dirty-tracker.d.ts +0 -252
- package/esm/database-dirty-tracker.d.ts.map +0 -1
- package/esm/database-dirty-tracker.js +0 -386
- package/esm/database-dirty-tracker.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-blueprint.d.ts +0 -30
- package/esm/drivers/mongodb/mongodb-blueprint.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-blueprint.js +0 -51
- package/esm/drivers/mongodb/mongodb-blueprint.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-driver.d.ts +0 -324
- package/esm/drivers/mongodb/mongodb-driver.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-driver.js +0 -799
- package/esm/drivers/mongodb/mongodb-driver.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.ts +0 -116
- package/esm/drivers/mongodb/mongodb-id-generator.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-id-generator.js +0 -149
- package/esm/drivers/mongodb/mongodb-id-generator.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts +0 -317
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.js +0 -666
- package/esm/drivers/mongodb/mongodb-migration-driver.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts +0 -1122
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-builder.js +0 -1988
- package/esm/drivers/mongodb/mongodb-query-builder.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.ts +0 -226
- package/esm/drivers/mongodb/mongodb-query-operations.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-operations.js +0 -270
- package/esm/drivers/mongodb/mongodb-query-operations.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.ts +0 -262
- package/esm/drivers/mongodb/mongodb-query-parser.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-parser.js +0 -1351
- package/esm/drivers/mongodb/mongodb-query-parser.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts +0 -79
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.js +0 -146
- package/esm/drivers/mongodb/mongodb-sync-adapter.js.map +0 -1
- package/esm/drivers/mongodb/types.d.ts +0 -43
- package/esm/drivers/mongodb/types.d.ts.map +0 -1
- package/esm/drivers/postgres/index.d.ts +0 -16
- package/esm/drivers/postgres/index.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-blueprint.d.ts +0 -64
- package/esm/drivers/postgres/postgres-blueprint.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-blueprint.js +0 -121
- package/esm/drivers/postgres/postgres-blueprint.js.map +0 -1
- package/esm/drivers/postgres/postgres-dialect.d.ts +0 -136
- package/esm/drivers/postgres/postgres-dialect.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-dialect.js +0 -268
- package/esm/drivers/postgres/postgres-dialect.js.map +0 -1
- package/esm/drivers/postgres/postgres-driver.d.ts +0 -432
- package/esm/drivers/postgres/postgres-driver.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-driver.js +0 -965
- package/esm/drivers/postgres/postgres-driver.js.map +0 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.ts +0 -397
- package/esm/drivers/postgres/postgres-migration-driver.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-migration-driver.js +0 -900
- package/esm/drivers/postgres/postgres-migration-driver.js.map +0 -1
- package/esm/drivers/postgres/postgres-query-builder.d.ts +0 -254
- package/esm/drivers/postgres/postgres-query-builder.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-query-builder.js +0 -933
- package/esm/drivers/postgres/postgres-query-builder.js.map +0 -1
- package/esm/drivers/postgres/postgres-query-parser.d.ts +0 -328
- package/esm/drivers/postgres/postgres-query-parser.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-query-parser.js +0 -864
- package/esm/drivers/postgres/postgres-query-parser.js.map +0 -1
- package/esm/drivers/postgres/postgres-sql-serializer.d.ts +0 -37
- package/esm/drivers/postgres/postgres-sql-serializer.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-sql-serializer.js +0 -400
- package/esm/drivers/postgres/postgres-sql-serializer.js.map +0 -1
- package/esm/drivers/postgres/postgres-sync-adapter.d.ts +0 -83
- package/esm/drivers/postgres/postgres-sync-adapter.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-sync-adapter.js +0 -197
- package/esm/drivers/postgres/postgres-sync-adapter.js.map +0 -1
- package/esm/drivers/postgres/types.d.ts +0 -142
- package/esm/drivers/postgres/types.d.ts.map +0 -1
- package/esm/drivers/sql/index.d.ts +0 -10
- package/esm/drivers/sql/index.d.ts.map +0 -1
- package/esm/drivers/sql/sql-dialect.contract.d.ts +0 -204
- package/esm/drivers/sql/sql-dialect.contract.d.ts.map +0 -1
- package/esm/drivers/sql/sql-types.d.ts +0 -202
- package/esm/drivers/sql/sql-types.d.ts.map +0 -1
- package/esm/errors/missing-data-source.error.d.ts +0 -22
- package/esm/errors/missing-data-source.error.d.ts.map +0 -1
- package/esm/errors/missing-data-source.error.js +0 -29
- package/esm/errors/missing-data-source.error.js.map +0 -1
- package/esm/errors/transaction-rollback.error.d.ts +0 -20
- package/esm/errors/transaction-rollback.error.d.ts.map +0 -1
- package/esm/errors/transaction-rollback.error.js +0 -27
- package/esm/errors/transaction-rollback.error.js.map +0 -1
- package/esm/events/model-events.d.ts +0 -231
- package/esm/events/model-events.d.ts.map +0 -1
- package/esm/events/model-events.js +0 -259
- package/esm/events/model-events.js.map +0 -1
- package/esm/expressions/aggregate-expressions.d.ts +0 -215
- package/esm/expressions/aggregate-expressions.d.ts.map +0 -1
- package/esm/expressions/aggregate-expressions.js +0 -221
- package/esm/expressions/aggregate-expressions.js.map +0 -1
- package/esm/expressions/index.d.ts +0 -2
- package/esm/expressions/index.d.ts.map +0 -1
- package/esm/index.d.ts +0 -45
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +0 -1
- package/esm/migration/column-builder.d.ts +0 -417
- package/esm/migration/column-builder.d.ts.map +0 -1
- package/esm/migration/column-builder.js +0 -586
- package/esm/migration/column-builder.js.map +0 -1
- package/esm/migration/column-helpers.d.ts +0 -275
- package/esm/migration/column-helpers.d.ts.map +0 -1
- package/esm/migration/column-helpers.js +0 -389
- package/esm/migration/column-helpers.js.map +0 -1
- package/esm/migration/foreign-key-builder.d.ts +0 -103
- package/esm/migration/foreign-key-builder.d.ts.map +0 -1
- package/esm/migration/foreign-key-builder.js +0 -121
- package/esm/migration/foreign-key-builder.js.map +0 -1
- package/esm/migration/index.d.ts +0 -7
- package/esm/migration/index.d.ts.map +0 -1
- package/esm/migration/migration-runner.d.ts +0 -278
- package/esm/migration/migration-runner.d.ts.map +0 -1
- package/esm/migration/migration-runner.js +0 -815
- package/esm/migration/migration-runner.js.map +0 -1
- package/esm/migration/migration.d.ts +0 -1992
- package/esm/migration/migration.d.ts.map +0 -1
- package/esm/migration/migration.js +0 -2162
- package/esm/migration/migration.js.map +0 -1
- package/esm/migration/sql-grammar.d.ts +0 -61
- package/esm/migration/sql-grammar.d.ts.map +0 -1
- package/esm/migration/sql-grammar.js +0 -164
- package/esm/migration/sql-grammar.js.map +0 -1
- package/esm/migration/sql-serializer.d.ts +0 -22
- package/esm/migration/sql-serializer.d.ts.map +0 -1
- package/esm/migration/sql-serializer.js +0 -26
- package/esm/migration/sql-serializer.js.map +0 -1
- package/esm/migration/types.d.ts +0 -155
- package/esm/migration/types.d.ts.map +0 -1
- package/esm/model/methods/accessor-methods.d.ts +0 -13
- package/esm/model/methods/accessor-methods.d.ts.map +0 -1
- package/esm/model/methods/accessor-methods.js +0 -51
- package/esm/model/methods/accessor-methods.js.map +0 -1
- package/esm/model/methods/delete-methods.d.ts +0 -10
- package/esm/model/methods/delete-methods.d.ts.map +0 -1
- package/esm/model/methods/delete-methods.js +0 -10
- package/esm/model/methods/delete-methods.js.map +0 -1
- package/esm/model/methods/dirty-methods.d.ts +0 -10
- package/esm/model/methods/dirty-methods.d.ts.map +0 -1
- package/esm/model/methods/dirty-methods.js +0 -15
- package/esm/model/methods/dirty-methods.js.map +0 -1
- package/esm/model/methods/hydration-methods.d.ts +0 -10
- package/esm/model/methods/hydration-methods.d.ts.map +0 -1
- package/esm/model/methods/hydration-methods.js +0 -57
- package/esm/model/methods/hydration-methods.js.map +0 -1
- package/esm/model/methods/instance-event-methods.d.ts +0 -7
- package/esm/model/methods/instance-event-methods.d.ts.map +0 -1
- package/esm/model/methods/instance-event-methods.js +0 -15
- package/esm/model/methods/instance-event-methods.js.map +0 -1
- package/esm/model/methods/meta-methods.d.ts +0 -7
- package/esm/model/methods/meta-methods.d.ts.map +0 -1
- package/esm/model/methods/meta-methods.js +0 -78
- package/esm/model/methods/meta-methods.js.map +0 -1
- package/esm/model/methods/query-methods.d.ts +0 -24
- package/esm/model/methods/query-methods.d.ts.map +0 -1
- package/esm/model/methods/query-methods.js +0 -161
- package/esm/model/methods/query-methods.js.map +0 -1
- package/esm/model/methods/restore-methods.d.ts +0 -10
- package/esm/model/methods/restore-methods.d.ts.map +0 -1
- package/esm/model/methods/restore-methods.js +0 -13
- package/esm/model/methods/restore-methods.js.map +0 -1
- package/esm/model/methods/scope-methods.d.ts +0 -7
- package/esm/model/methods/scope-methods.d.ts.map +0 -1
- package/esm/model/methods/scope-methods.js +0 -15
- package/esm/model/methods/scope-methods.js.map +0 -1
- package/esm/model/methods/serialization-methods.d.ts +0 -3
- package/esm/model/methods/serialization-methods.d.ts.map +0 -1
- package/esm/model/methods/serialization-methods.js +0 -27
- package/esm/model/methods/serialization-methods.js.map +0 -1
- package/esm/model/methods/static-event-methods.d.ts +0 -9
- package/esm/model/methods/static-event-methods.d.ts.map +0 -1
- package/esm/model/methods/static-event-methods.js +0 -29
- package/esm/model/methods/static-event-methods.js.map +0 -1
- package/esm/model/methods/write-methods.d.ts +0 -10
- package/esm/model/methods/write-methods.d.ts.map +0 -1
- package/esm/model/methods/write-methods.js +0 -52
- package/esm/model/methods/write-methods.js.map +0 -1
- package/esm/model/model.d.ts +0 -1650
- package/esm/model/model.d.ts.map +0 -1
- package/esm/model/model.js +0 -1657
- package/esm/model/model.js.map +0 -1
- package/esm/model/model.types.d.ts +0 -44
- package/esm/model/model.types.d.ts.map +0 -1
- package/esm/model/register-model.d.ts +0 -81
- package/esm/model/register-model.d.ts.map +0 -1
- package/esm/model/register-model.js +0 -94
- package/esm/model/register-model.js.map +0 -1
- package/esm/query-builder/query-builder.d.ts +0 -556
- package/esm/query-builder/query-builder.d.ts.map +0 -1
- package/esm/query-builder/query-builder.js +0 -1070
- package/esm/query-builder/query-builder.js.map +0 -1
- package/esm/relations/helpers.d.ts +0 -156
- package/esm/relations/helpers.d.ts.map +0 -1
- package/esm/relations/helpers.js +0 -201
- package/esm/relations/helpers.js.map +0 -1
- package/esm/relations/index.d.ts +0 -35
- package/esm/relations/index.d.ts.map +0 -1
- package/esm/relations/pivot-operations.d.ts +0 -160
- package/esm/relations/pivot-operations.d.ts.map +0 -1
- package/esm/relations/pivot-operations.js +0 -293
- package/esm/relations/pivot-operations.js.map +0 -1
- package/esm/relations/relation-hydrator.d.ts +0 -68
- package/esm/relations/relation-hydrator.d.ts.map +0 -1
- package/esm/relations/relation-hydrator.js +0 -81
- package/esm/relations/relation-hydrator.js.map +0 -1
- package/esm/relations/relation-loader.d.ts +0 -194
- package/esm/relations/relation-loader.d.ts.map +0 -1
- package/esm/relations/relation-loader.js +0 -466
- package/esm/relations/relation-loader.js.map +0 -1
- package/esm/relations/types.d.ts +0 -306
- package/esm/relations/types.d.ts.map +0 -1
- package/esm/remover/database-remover.d.ts +0 -100
- package/esm/remover/database-remover.d.ts.map +0 -1
- package/esm/remover/database-remover.js +0 -214
- package/esm/remover/database-remover.js.map +0 -1
- package/esm/restorer/database-restorer.d.ts +0 -131
- package/esm/restorer/database-restorer.d.ts.map +0 -1
- package/esm/restorer/database-restorer.js +0 -434
- package/esm/restorer/database-restorer.js.map +0 -1
- package/esm/sql-database-dirty-tracker.d.ts +0 -13
- package/esm/sql-database-dirty-tracker.d.ts.map +0 -1
- package/esm/sql-database-dirty-tracker.js +0 -14
- package/esm/sql-database-dirty-tracker.js.map +0 -1
- package/esm/sync/index.d.ts +0 -12
- package/esm/sync/index.d.ts.map +0 -1
- package/esm/sync/model-events.d.ts +0 -62
- package/esm/sync/model-events.d.ts.map +0 -1
- package/esm/sync/model-events.js +0 -49
- package/esm/sync/model-events.js.map +0 -1
- package/esm/sync/model-sync-operation.d.ts +0 -163
- package/esm/sync/model-sync-operation.d.ts.map +0 -1
- package/esm/sync/model-sync-operation.js +0 -292
- package/esm/sync/model-sync-operation.js.map +0 -1
- package/esm/sync/model-sync.d.ts +0 -130
- package/esm/sync/model-sync.d.ts.map +0 -1
- package/esm/sync/model-sync.js +0 -178
- package/esm/sync/model-sync.js.map +0 -1
- package/esm/sync/sync-context.d.ts +0 -70
- package/esm/sync/sync-context.d.ts.map +0 -1
- package/esm/sync/sync-context.js +0 -101
- package/esm/sync/sync-context.js.map +0 -1
- package/esm/sync/sync-manager.d.ts +0 -213
- package/esm/sync/sync-manager.d.ts.map +0 -1
- package/esm/sync/sync-manager.js +0 -689
- package/esm/sync/sync-manager.js.map +0 -1
- package/esm/sync/types.d.ts +0 -289
- package/esm/sync/types.d.ts.map +0 -1
- package/esm/test-migrations/test-enhanced-features.migration.d.ts +0 -15
- package/esm/test-migrations/test-enhanced-features.migration.d.ts.map +0 -1
- package/esm/types.d.ts +0 -371
- package/esm/types.d.ts.map +0 -1
- package/esm/utils/connect-to-database.d.ts +0 -300
- package/esm/utils/connect-to-database.d.ts.map +0 -1
- package/esm/utils/connect-to-database.js +0 -128
- package/esm/utils/connect-to-database.js.map +0 -1
- package/esm/utils/database-writer.utils.d.ts +0 -15
- package/esm/utils/database-writer.utils.d.ts.map +0 -1
- package/esm/utils/database-writer.utils.js +0 -14
- package/esm/utils/database-writer.utils.js.map +0 -1
- package/esm/utils/define-model.js +0 -100
- package/esm/utils/define-model.js.map +0 -1
- package/esm/utils/is-valid-date-value.d.ts +0 -5
- package/esm/utils/is-valid-date-value.d.ts.map +0 -1
- package/esm/utils/is-valid-date-value.js +0 -25
- package/esm/utils/is-valid-date-value.js.map +0 -1
- package/esm/utils/once-connected.d.ts +0 -146
- package/esm/utils/once-connected.d.ts.map +0 -1
- package/esm/utils/once-connected.js +0 -251
- package/esm/utils/once-connected.js.map +0 -1
- package/esm/validation/database-seal-plugins.d.ts +0 -12
- package/esm/validation/database-seal-plugins.d.ts.map +0 -1
- package/esm/validation/database-seal-plugins.js +0 -1
- package/esm/validation/database-seal-plugins.js.map +0 -1
- package/esm/validation/database-writer-validation-error.d.ts +0 -97
- package/esm/validation/database-writer-validation-error.d.ts.map +0 -1
- package/esm/validation/database-writer-validation-error.js +0 -160
- package/esm/validation/database-writer-validation-error.js.map +0 -1
- package/esm/validation/index.d.ts +0 -3
- package/esm/validation/index.d.ts.map +0 -1
- package/esm/validation/mutators/embed-mutator.d.ts +0 -9
- package/esm/validation/mutators/embed-mutator.d.ts.map +0 -1
- package/esm/validation/mutators/embed-mutator.js +0 -33
- package/esm/validation/mutators/embed-mutator.js.map +0 -1
- package/esm/validation/plugins/embed-validator-plugin.d.ts +0 -24
- package/esm/validation/plugins/embed-validator-plugin.d.ts.map +0 -1
- package/esm/validation/plugins/embed-validator-plugin.js +0 -18
- package/esm/validation/plugins/embed-validator-plugin.js.map +0 -1
- package/esm/validation/rules/database-model-rule.d.ts +0 -7
- package/esm/validation/rules/database-model-rule.d.ts.map +0 -1
- package/esm/validation/rules/database-model-rule.js +0 -27
- package/esm/validation/rules/database-model-rule.js.map +0 -1
- package/esm/validation/transformers/embed-model-transformer.d.ts +0 -3
- package/esm/validation/transformers/embed-model-transformer.d.ts.map +0 -1
- package/esm/validation/transformers/embed-model-transformer.js +0 -18
- package/esm/validation/transformers/embed-model-transformer.js.map +0 -1
- package/esm/validation/validators/embed-validator.d.ts +0 -21
- package/esm/validation/validators/embed-validator.d.ts.map +0 -1
- package/esm/validation/validators/embed-validator.js +0 -43
- package/esm/validation/validators/embed-validator.js.map +0 -1
- package/esm/writer/database-writer.d.ts +0 -181
- package/esm/writer/database-writer.d.ts.map +0 -1
- package/esm/writer/database-writer.js +0 -407
- package/esm/writer/database-writer.js.map +0 -1
|
@@ -1,815 +0,0 @@
|
|
|
1
|
-
'use strict';var copper=require('@mongez/copper'),logger=require('@warlock.js/logger'),fs=require('fs'),path=require('path'),dataSourceRegistry=require('../data-source/data-source-registry.js'),sqlGrammar=require('./sql-grammar.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var fs__default=/*#__PURE__*/_interopDefault(fs);var path__default=/*#__PURE__*/_interopDefault(path);/**
|
|
2
|
-
* Parse createdAt timestamp from custom format to Date.
|
|
3
|
-
* Supports both: MM-DD-YYYY_HH-MM-SS and DD-MM-YYYY_HH-MM-SS
|
|
4
|
-
* Intelligently detects format by checking if first value > 12 (must be day)
|
|
5
|
-
* Falls back to standard Date parsing for ISO strings.
|
|
6
|
-
*/
|
|
7
|
-
function parseCreatedAt(createdAt) {
|
|
8
|
-
const match = createdAt.match(/^(\d{2})-(\d{2})-(\d{4})_(\d{2})-(\d{2})-(\d{2})$/);
|
|
9
|
-
if (match) {
|
|
10
|
-
const [, first, second, year, hour, minute, second_time] = match;
|
|
11
|
-
const firstNum = parseInt(first);
|
|
12
|
-
const secondNum = parseInt(second);
|
|
13
|
-
let month, day;
|
|
14
|
-
// Intelligently detect format:
|
|
15
|
-
// If first > 12, it must be DD-MM-YYYY (day can't be month)
|
|
16
|
-
// If second > 12, it must be MM-DD-YYYY (day can't be month)
|
|
17
|
-
// Otherwise, assume MM-DD-YYYY (US format as default)
|
|
18
|
-
if (firstNum > 12) {
|
|
19
|
-
// DD-MM-YYYY format
|
|
20
|
-
day = firstNum;
|
|
21
|
-
month = secondNum;
|
|
22
|
-
}
|
|
23
|
-
else if (secondNum > 12) {
|
|
24
|
-
// MM-DD-YYYY format
|
|
25
|
-
month = firstNum;
|
|
26
|
-
day = secondNum;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
// Ambiguous - default to MM-DD-YYYY
|
|
30
|
-
month = firstNum;
|
|
31
|
-
day = secondNum;
|
|
32
|
-
}
|
|
33
|
-
const date = new Date(parseInt(year), month - 1, // JavaScript months are 0-indexed
|
|
34
|
-
day, parseInt(hour), parseInt(minute), parseInt(second_time));
|
|
35
|
-
// Validate the date is actually valid
|
|
36
|
-
if (isNaN(date.getTime())) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
return date;
|
|
40
|
-
}
|
|
41
|
-
// Fallback to standard Date parsing for ISO strings
|
|
42
|
-
try {
|
|
43
|
-
const date = new Date(createdAt);
|
|
44
|
-
return isNaN(date.getTime()) ? undefined : date;
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Comparator for sorting migration classes.
|
|
52
|
-
*
|
|
53
|
-
* Priority:
|
|
54
|
-
* 1. `createdAt` timestamp (older = earlier)
|
|
55
|
-
* 2. Alphabetical by migration name (last resort)
|
|
56
|
-
*/
|
|
57
|
-
function sortMigrations(a, b) {
|
|
58
|
-
// Sort by createdAt timestamp
|
|
59
|
-
const aDate = a.createdAt ? parseCreatedAt(a.createdAt) : undefined;
|
|
60
|
-
const bDate = b.createdAt ? parseCreatedAt(b.createdAt) : undefined;
|
|
61
|
-
if (aDate && bDate)
|
|
62
|
-
return aDate.getTime() - bDate.getTime();
|
|
63
|
-
if (aDate)
|
|
64
|
-
return -1;
|
|
65
|
-
if (bDate)
|
|
66
|
-
return 1;
|
|
67
|
-
// Last resort: alphabetical
|
|
68
|
-
return a.migrationName.localeCompare(b.migrationName);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Migration runner that executes migrations.
|
|
72
|
-
*
|
|
73
|
-
* This is a pure executor - it doesn't discover migrations.
|
|
74
|
-
* Discovery is handled by the framework (e.g., @warlock.js/core CLI).
|
|
75
|
-
*
|
|
76
|
-
* The migration name is read from the static `name` property on the class,
|
|
77
|
-
* which should be set by the CLI after importing:
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* // In CLI after importing:
|
|
82
|
-
* const { default: MigrationClass } = await import("./create-users.migration.ts");
|
|
83
|
-
* MigrationClass.migrationName ??= "create-users";
|
|
84
|
-
*
|
|
85
|
-
* // Then register or execute:
|
|
86
|
-
* runner.register(MigrationClass);
|
|
87
|
-
* // or
|
|
88
|
-
* await runner.execute(MigrationClass);
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* // Simple direct execution
|
|
94
|
-
* await runner.execute(CreateUsersTable);
|
|
95
|
-
* await runner.rollback(CreateUsersTable);
|
|
96
|
-
*
|
|
97
|
-
* // Registry pattern for batch operations
|
|
98
|
-
* runner.register(CreateUsersTable);
|
|
99
|
-
* runner.register(AddEmailIndex);
|
|
100
|
-
* await runner.runAll();
|
|
101
|
-
* await runner.rollbackAll();
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
class MigrationRunner {
|
|
105
|
-
/** Registered migrations */
|
|
106
|
-
migrations = [];
|
|
107
|
-
/** Data source to use */
|
|
108
|
-
dataSource;
|
|
109
|
-
/** Cached migration driver */
|
|
110
|
-
cachedMigrationDriver;
|
|
111
|
-
/** Table name for tracking migrations */
|
|
112
|
-
migrationsTable;
|
|
113
|
-
/** Whether to log operations */
|
|
114
|
-
verbose;
|
|
115
|
-
/**
|
|
116
|
-
* Create a new migration runner.
|
|
117
|
-
*
|
|
118
|
-
* @param options - Runner options
|
|
119
|
-
*/
|
|
120
|
-
constructor(options = {}) {
|
|
121
|
-
this.dataSource = options.dataSource;
|
|
122
|
-
this.migrationsTable = options.migrationsTable ?? "_migrations";
|
|
123
|
-
this.verbose = options.verbose ?? true;
|
|
124
|
-
}
|
|
125
|
-
// ============================================================================
|
|
126
|
-
// DATA SOURCE
|
|
127
|
-
// ============================================================================
|
|
128
|
-
/**
|
|
129
|
-
* Set the data source.
|
|
130
|
-
*/
|
|
131
|
-
setDataSource(dataSource) {
|
|
132
|
-
this.dataSource = dataSource;
|
|
133
|
-
this.cachedMigrationDriver = undefined;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get the data source.
|
|
138
|
-
*/
|
|
139
|
-
getDataSource() {
|
|
140
|
-
if (!this.dataSource) {
|
|
141
|
-
this.dataSource = dataSourceRegistry.dataSourceRegistry.get();
|
|
142
|
-
}
|
|
143
|
-
return this.dataSource;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Get the migration driver.
|
|
147
|
-
*/
|
|
148
|
-
getMigrationDriver() {
|
|
149
|
-
if (!this.cachedMigrationDriver) {
|
|
150
|
-
this.cachedMigrationDriver = this.getDataSource().driver.migrationDriver();
|
|
151
|
-
}
|
|
152
|
-
return this.cachedMigrationDriver;
|
|
153
|
-
}
|
|
154
|
-
// ============================================================================
|
|
155
|
-
// REGISTRATION
|
|
156
|
-
// ============================================================================
|
|
157
|
-
/**
|
|
158
|
-
* Register a migration.
|
|
159
|
-
*
|
|
160
|
-
* The migration name is read from `MigrationClass.migrationName`.
|
|
161
|
-
*
|
|
162
|
-
* @param MigrationClass - Migration class (must have static `name` set)
|
|
163
|
-
* @param createdAt - Optional timestamp for ordering
|
|
164
|
-
* @returns This runner for chaining
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* CreateUsersTable.migrationName = "2024-01-15_create-users";
|
|
169
|
-
* runner.register(CreateUsersTable);
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
register(MigrationClass) {
|
|
173
|
-
const name = MigrationClass.migrationName;
|
|
174
|
-
if (!name) {
|
|
175
|
-
throw new Error(`Migration class must have a static 'migrationName' property set. ` +
|
|
176
|
-
`Set it in CLI after importing: MigrationClass.migrationName = "filename";`);
|
|
177
|
-
}
|
|
178
|
-
// Avoid duplicates
|
|
179
|
-
if (!this.migrations.some((m) => m.migrationName === name)) {
|
|
180
|
-
this.migrations.push(MigrationClass);
|
|
181
|
-
}
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Register multiple migrations.
|
|
186
|
-
*
|
|
187
|
-
* @param migrations - Array of migration classes
|
|
188
|
-
* @returns This runner for chaining
|
|
189
|
-
*/
|
|
190
|
-
registerMany(migrations) {
|
|
191
|
-
for (const MigrationClass of migrations) {
|
|
192
|
-
this.register(MigrationClass);
|
|
193
|
-
}
|
|
194
|
-
return this;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Clear all registered migrations.
|
|
198
|
-
*/
|
|
199
|
-
clear() {
|
|
200
|
-
this.migrations.length = 0;
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Get all registered migration names.
|
|
205
|
-
*/
|
|
206
|
-
getRegisteredNames() {
|
|
207
|
-
return this.migrations.map((m) => m.migrationName);
|
|
208
|
-
}
|
|
209
|
-
// ============================================================================
|
|
210
|
-
// SINGLE EXECUTION
|
|
211
|
-
// ============================================================================
|
|
212
|
-
/**
|
|
213
|
-
* Execute a single migration's up() method.
|
|
214
|
-
*
|
|
215
|
-
* @param MigrationClass - Migration class to execute
|
|
216
|
-
* @param options - Execution options
|
|
217
|
-
* @returns Migration result
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```typescript
|
|
221
|
-
* await runner.execute(CreateUsersTable);
|
|
222
|
-
* await runner.execute(AddEmailIndex, { dryRun: true });
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
async run(MigrationClass, options = {}) {
|
|
226
|
-
return this.runMigration(MigrationClass, "up", {
|
|
227
|
-
dryRun: options.dryRun,
|
|
228
|
-
record: options.record ?? false,
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Execute a single migration's down() method.
|
|
233
|
-
*
|
|
234
|
-
* @param MigrationClass - Migration class to rollback
|
|
235
|
-
* @param options - Execution options
|
|
236
|
-
* @returns Migration result
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```typescript
|
|
240
|
-
* await runner.rollback(CreateUsersTable);
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
async rollback(MigrationClass, options = {}) {
|
|
244
|
-
return this.runMigration(MigrationClass, "down", {
|
|
245
|
-
dryRun: options.dryRun,
|
|
246
|
-
record: options.record ?? false,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
// ============================================================================
|
|
250
|
-
// BATCH EXECUTION (REGISTERED MIGRATIONS)
|
|
251
|
-
// ============================================================================
|
|
252
|
-
/**
|
|
253
|
-
* Run all pending registered migrations.
|
|
254
|
-
*
|
|
255
|
-
* Only runs migrations not already in the migrations table.
|
|
256
|
-
*
|
|
257
|
-
* @param options - Execution options
|
|
258
|
-
* @returns Results for each migration
|
|
259
|
-
*
|
|
260
|
-
* @example
|
|
261
|
-
* ```typescript
|
|
262
|
-
* runner.register(CreateUsersTable);
|
|
263
|
-
* runner.register(AddEmailIndex);
|
|
264
|
-
* const results = await runner.runAll();
|
|
265
|
-
* ```
|
|
266
|
-
*/
|
|
267
|
-
async runAll(options = {}) {
|
|
268
|
-
const { dryRun = false, record = true } = options;
|
|
269
|
-
const results = [];
|
|
270
|
-
// Get pending migrations
|
|
271
|
-
const pending = await this.getPendingMigrations();
|
|
272
|
-
if (pending.length === 0) {
|
|
273
|
-
logger.log.warn("database", "migration", "Nothing to migrate.");
|
|
274
|
-
return results;
|
|
275
|
-
}
|
|
276
|
-
logger.log.info("database", "migration", `Found ${pending.length} pending migration(s). Generating SQL pool...`);
|
|
277
|
-
const nextBatch = await this.getNextBatchNumber();
|
|
278
|
-
const taggedStatements = [];
|
|
279
|
-
const migrationsData = [];
|
|
280
|
-
// 1. Collect SQL from each pending migration.
|
|
281
|
-
// Fire extension checks concurrently as we encounter CREATE EXTENSION
|
|
282
|
-
// statements — they resolve before execution begins.
|
|
283
|
-
const extensionChecks = [];
|
|
284
|
-
for (const MigrationClass of pending) {
|
|
285
|
-
const migration = this.createMigrationInstance(MigrationClass);
|
|
286
|
-
const name = MigrationClass.migrationName;
|
|
287
|
-
await migration.up();
|
|
288
|
-
const upStatements = migration.toSQL();
|
|
289
|
-
migrationsData.push({ MigrationClass, migration, name });
|
|
290
|
-
for (const sql of upStatements) {
|
|
291
|
-
const statementType = sqlGrammar.SQLGrammar.classify(sql);
|
|
292
|
-
if (statementType === "CREATE_EXTENSION") {
|
|
293
|
-
const ext = sqlGrammar.SQLGrammar.extractExtensionName(sql);
|
|
294
|
-
if (ext)
|
|
295
|
-
extensionChecks.push(this.informIfExtensionMissing(ext));
|
|
296
|
-
}
|
|
297
|
-
taggedStatements.push({
|
|
298
|
-
sql,
|
|
299
|
-
phase: sqlGrammar.SQLGrammar.phase(sql),
|
|
300
|
-
statementType,
|
|
301
|
-
createdAt: MigrationClass.createdAt,
|
|
302
|
-
migrationName: name,
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
// 2. Resolve all extension checks before any SQL is executed.
|
|
307
|
-
// Each check displays a rich message if the extension is missing
|
|
308
|
-
// but does not throw — execution continues and Postgres will
|
|
309
|
-
// surface its own error with full context already shown.
|
|
310
|
-
await Promise.all(extensionChecks);
|
|
311
|
-
// 3. Sort all SQL statements globally across all pending migrations
|
|
312
|
-
const sortedStatements = sqlGrammar.SQLGrammar.sort(taggedStatements);
|
|
313
|
-
// 4. Execute in a single batch
|
|
314
|
-
if (dryRun) {
|
|
315
|
-
logger.log.info("database", "migration", "Dry run enabled. Would execute the following statements:");
|
|
316
|
-
for (const statement of sortedStatements) {
|
|
317
|
-
console.log(`-- [${statement.statementType}] Phase ${statement.phase} [${statement.migrationName}]`);
|
|
318
|
-
console.log(statement.sql + ";\n");
|
|
319
|
-
}
|
|
320
|
-
return [];
|
|
321
|
-
}
|
|
322
|
-
const driver = this.getDataSource().driver;
|
|
323
|
-
let transactionFailed = false;
|
|
324
|
-
let errorMessage = "";
|
|
325
|
-
/** The migration name that owns the SQL statement that threw. */
|
|
326
|
-
let failingMigrationName;
|
|
327
|
-
const startTime = Date.now();
|
|
328
|
-
/**
|
|
329
|
-
* Execute all sorted statements, capturing which migration owns the
|
|
330
|
-
* statement that throws — so we report a precise culprit instead of
|
|
331
|
-
* blaming every migration in the batch.
|
|
332
|
-
*/
|
|
333
|
-
const executeStatements = async () => {
|
|
334
|
-
for (const statement of sortedStatements) {
|
|
335
|
-
try {
|
|
336
|
-
await driver.query(statement.sql);
|
|
337
|
-
}
|
|
338
|
-
catch (err) {
|
|
339
|
-
failingMigrationName = statement.migrationName;
|
|
340
|
-
throw err;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (record) {
|
|
344
|
-
for (const data of migrationsData) {
|
|
345
|
-
await this.recordMigration(data.name, nextBatch, data.MigrationClass.createdAt
|
|
346
|
-
? parseCreatedAt(data.MigrationClass.createdAt)
|
|
347
|
-
: new Date());
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
try {
|
|
352
|
-
if (driver.transaction) {
|
|
353
|
-
await driver.transaction(executeStatements);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
await executeStatements();
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
catch (err) {
|
|
360
|
-
transactionFailed = true;
|
|
361
|
-
errorMessage = err instanceof Error ? err.message : String(err);
|
|
362
|
-
}
|
|
363
|
-
const durationMs = Date.now() - startTime;
|
|
364
|
-
// Report results per-migration.
|
|
365
|
-
// Only the migration that owns the failing statement is marked as failed;
|
|
366
|
-
// all others are reported as rolled back / not reached.
|
|
367
|
-
for (const data of migrationsData) {
|
|
368
|
-
const isCulprit = transactionFailed && data.name === failingMigrationName;
|
|
369
|
-
const wasSkipped = transactionFailed && !isCulprit;
|
|
370
|
-
results.push({
|
|
371
|
-
name: data.name,
|
|
372
|
-
table: data.migration.table,
|
|
373
|
-
direction: "up",
|
|
374
|
-
success: !transactionFailed,
|
|
375
|
-
error: isCulprit ? errorMessage : undefined,
|
|
376
|
-
durationMs: Math.round(durationMs / migrationsData.length),
|
|
377
|
-
executedAt: new Date(),
|
|
378
|
-
});
|
|
379
|
-
if (isCulprit) {
|
|
380
|
-
logger.log.error("database", "migration", `${copper.colors.magenta(data.name)}: ✗ Failed: ${errorMessage}`);
|
|
381
|
-
}
|
|
382
|
-
else if (wasSkipped) {
|
|
383
|
-
logger.log.warn("database", "migration", `${copper.colors.magenta(data.name)}: rolled back (batch transaction failed)`);
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
logger.log.success("database", "migration", `Migrated: ${copper.colors.magenta(data.name)} successfully`);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
if (transactionFailed) {
|
|
390
|
-
logger.log.error("database", "migration", `Batch execution failed. Rollback performed if transactional.`);
|
|
391
|
-
throw new Error("Migration batch failed: " + errorMessage);
|
|
392
|
-
}
|
|
393
|
-
const successCount = results.filter((r) => r.success).length;
|
|
394
|
-
logger.log.success("database", "migration", `Migration bulk phase execution complete: ${successCount}/${pending.length} migrations processed successfully.`);
|
|
395
|
-
return results;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Export migrations as phase-ordered SQL files in database/sql/ directory.
|
|
399
|
-
* By default, it exports all registered migrations. Use `pendingOnly: true` to export only pending ones.
|
|
400
|
-
*/
|
|
401
|
-
async exportSQL(options = {}) {
|
|
402
|
-
const migrationsToExport = options.pendingOnly
|
|
403
|
-
? await this.getPendingMigrations()
|
|
404
|
-
: this.migrations;
|
|
405
|
-
if (migrationsToExport.length === 0) {
|
|
406
|
-
logger.log.warn("database", "migration", "No migrations to export.");
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
logger.log.info("database", "migration", `Exporting ${migrationsToExport.length} ${options.pendingOnly ? "pending " : ""}migration(s) to SQL files...`);
|
|
410
|
-
const upStatements = [];
|
|
411
|
-
const downStatements = [];
|
|
412
|
-
for (const MigrationClass of migrationsToExport) {
|
|
413
|
-
const migration = this.createMigrationInstance(MigrationClass);
|
|
414
|
-
const name = MigrationClass.migrationName;
|
|
415
|
-
// Collect up SQL
|
|
416
|
-
await migration.up();
|
|
417
|
-
for (const sql of migration.toSQL()) {
|
|
418
|
-
upStatements.push({
|
|
419
|
-
sql,
|
|
420
|
-
phase: sqlGrammar.SQLGrammar.phase(sql),
|
|
421
|
-
statementType: sqlGrammar.SQLGrammar.classify(sql),
|
|
422
|
-
createdAt: MigrationClass.createdAt,
|
|
423
|
-
migrationName: name,
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
// Collect down SQL (reuse same instance — toSQL() cleared pendingOps)
|
|
427
|
-
await migration.down();
|
|
428
|
-
for (const sql of migration.toSQL()) {
|
|
429
|
-
downStatements.push({
|
|
430
|
-
sql,
|
|
431
|
-
phase: sqlGrammar.SQLGrammar.phase(sql),
|
|
432
|
-
statementType: sqlGrammar.SQLGrammar.classify(sql),
|
|
433
|
-
createdAt: MigrationClass.createdAt,
|
|
434
|
-
migrationName: name,
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
const sortedUp = sqlGrammar.SQLGrammar.sort(upStatements);
|
|
439
|
-
// Down SQL: reverse order (undo in reverse dependency order)
|
|
440
|
-
const sortedDown = downStatements.reverse();
|
|
441
|
-
const upSQLString = this.formatSQLForExport(sortedUp, options.compact);
|
|
442
|
-
const downSQLString = this.formatSQLForExport(sortedDown, options.compact);
|
|
443
|
-
const rootPath = process.cwd();
|
|
444
|
-
const sqlDir = path__default.default.join(rootPath, "database", "sql");
|
|
445
|
-
if (!fs__default.default.existsSync(sqlDir)) {
|
|
446
|
-
fs__default.default.mkdirSync(sqlDir, { recursive: true });
|
|
447
|
-
}
|
|
448
|
-
const timestamp = new Date().toISOString().replace(/T/, "_").replace(/:/g, "-").split(".")[0];
|
|
449
|
-
const upPath = path__default.default.join(sqlDir, `migration_${timestamp}.up.sql`);
|
|
450
|
-
const downPath = path__default.default.join(sqlDir, `migration_${timestamp}.down.sql`);
|
|
451
|
-
fs__default.default.writeFileSync(upPath, upSQLString);
|
|
452
|
-
fs__default.default.writeFileSync(downPath, downSQLString);
|
|
453
|
-
logger.log.success("database", "migration", `Exported to:\n- ${upPath}\n- ${downPath}`);
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Rollback the last batch of migrations.
|
|
457
|
-
*
|
|
458
|
-
* @param options - Execution options
|
|
459
|
-
* @returns Results for each migration
|
|
460
|
-
*/
|
|
461
|
-
async rollbackLast(options = {}) {
|
|
462
|
-
return this.rollbackBatches(1, options);
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Rollback N batches of migrations.
|
|
466
|
-
*
|
|
467
|
-
* @param batches - Number of batches to rollback
|
|
468
|
-
* @param options - Execution options
|
|
469
|
-
* @returns Results for each migration
|
|
470
|
-
*/
|
|
471
|
-
async rollbackBatches(batches, options = {}) {
|
|
472
|
-
const dryRun = options.dryRun ?? false;
|
|
473
|
-
const record = options.record ?? true;
|
|
474
|
-
const results = [];
|
|
475
|
-
const toRollback = await this.getMigrationsToRollback(batches);
|
|
476
|
-
if (toRollback.length === 0) {
|
|
477
|
-
logger.log.warn("database", "migration", "Nothing to rollback.");
|
|
478
|
-
return results;
|
|
479
|
-
}
|
|
480
|
-
logger.log.info("database", "migration", `Rolling back ${toRollback.length} migration(s).`);
|
|
481
|
-
for (const MigrationClass of toRollback) {
|
|
482
|
-
const result = await this.runMigration(MigrationClass, "down", {
|
|
483
|
-
dryRun,
|
|
484
|
-
record,
|
|
485
|
-
});
|
|
486
|
-
results.push(result);
|
|
487
|
-
if (!result.success) {
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
const successCount = results.filter((r) => r.success).length;
|
|
492
|
-
logger.log.success("database", "migration", `Rollback complete: ${successCount}/${toRollback.length} successful.`);
|
|
493
|
-
return results;
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Rollback all executed migrations.
|
|
497
|
-
*
|
|
498
|
-
* @param options - Execution options
|
|
499
|
-
* @returns Results for each migration
|
|
500
|
-
*/
|
|
501
|
-
async rollbackAll(options = {}) {
|
|
502
|
-
const executed = await this.getExecutedMigrations();
|
|
503
|
-
if (executed.length === 0) {
|
|
504
|
-
logger.log.warn("database", "migration", "Nothing to rollback.");
|
|
505
|
-
return [];
|
|
506
|
-
}
|
|
507
|
-
const maxBatch = Math.max(...executed.map((r) => r.batch));
|
|
508
|
-
return this.rollbackBatches(maxBatch, options);
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Reset and re-run: rollback all then run all.
|
|
512
|
-
*
|
|
513
|
-
* @param options - Execution options
|
|
514
|
-
* @returns Combined results
|
|
515
|
-
*/
|
|
516
|
-
async fresh(options = {}) {
|
|
517
|
-
const rollbackResults = await this.rollbackAll(options);
|
|
518
|
-
const runResults = await this.runAll(options);
|
|
519
|
-
return [...rollbackResults, ...runResults];
|
|
520
|
-
}
|
|
521
|
-
// ============================================================================
|
|
522
|
-
// STATUS
|
|
523
|
-
// ============================================================================
|
|
524
|
-
/**
|
|
525
|
-
* Get status of all registered migrations.
|
|
526
|
-
*/
|
|
527
|
-
async status() {
|
|
528
|
-
const executed = await this.getExecutedMigrations();
|
|
529
|
-
const executedMap = new Map(executed.map((r) => [r.name, r]));
|
|
530
|
-
return this.migrations.map((MigrationClass) => {
|
|
531
|
-
const instance = new MigrationClass();
|
|
532
|
-
const name = MigrationClass.migrationName;
|
|
533
|
-
const record = executedMap.get(name);
|
|
534
|
-
return {
|
|
535
|
-
name,
|
|
536
|
-
table: instance.table,
|
|
537
|
-
executed: !!record,
|
|
538
|
-
batch: record?.batch ?? null,
|
|
539
|
-
};
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
// ============================================================================
|
|
543
|
-
// EXTENSION PRE-FLIGHT
|
|
544
|
-
// ============================================================================
|
|
545
|
-
/**
|
|
546
|
-
* Check whether a database extension is available and inform the developer
|
|
547
|
-
* if it is not installed.
|
|
548
|
-
*
|
|
549
|
-
* Does NOT throw — execution proceeds normally. If the extension is truly
|
|
550
|
-
* missing, the database will surface its own error with full context already
|
|
551
|
-
* displayed to the developer.
|
|
552
|
-
*
|
|
553
|
-
* @example
|
|
554
|
-
* await this.informIfExtensionMissing("vector");
|
|
555
|
-
*/
|
|
556
|
-
async informIfExtensionMissing(extension) {
|
|
557
|
-
try {
|
|
558
|
-
const migrationDriver = this.getMigrationDriver();
|
|
559
|
-
const isAvailable = await migrationDriver.isExtensionAvailable(extension);
|
|
560
|
-
if (!isAvailable) {
|
|
561
|
-
const hr = "─".repeat(60);
|
|
562
|
-
console.log(`\n${copper.colors.yellow(hr)}`);
|
|
563
|
-
console.log(copper.colors.yellow(` ⚠ Missing Database Extension: ${copper.colors.bold(extension)}`));
|
|
564
|
-
console.log(copper.colors.yellow(hr));
|
|
565
|
-
console.log();
|
|
566
|
-
console.log(` A pending migration requires the ${copper.colors.cyan(extension)} extension,`);
|
|
567
|
-
console.log(` which is not installed on your database server.`);
|
|
568
|
-
console.log();
|
|
569
|
-
console.log(` ${copper.colors.bold("This means the physical database server is missing the extension package.")}`);
|
|
570
|
-
console.log(` You cannot simply run CREATE EXTENSION until the package is installed`);
|
|
571
|
-
console.log(` on the host machine or Docker container.`);
|
|
572
|
-
console.log();
|
|
573
|
-
const docsUrl = migrationDriver.getExtensionDocsUrl(extension);
|
|
574
|
-
if (docsUrl) {
|
|
575
|
-
console.log(` ${copper.colors.bold("Or follow the installation guide:")}`);
|
|
576
|
-
console.log(` ${copper.colors.cyan(docsUrl)}`);
|
|
577
|
-
}
|
|
578
|
-
console.log(`\n${copper.colors.yellow(hr)}\n`);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
catch {
|
|
582
|
-
// If the check itself fails, silently skip — don't break the migration.
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
// ============================================================================
|
|
586
|
-
// PRIVATE HELPERS
|
|
587
|
-
// ============================================================================
|
|
588
|
-
/**
|
|
589
|
-
* Run a single migration.
|
|
590
|
-
*/
|
|
591
|
-
async runMigration(MigrationClass, direction, options = {}) {
|
|
592
|
-
const { dryRun = false, record = true } = options;
|
|
593
|
-
const startTime = Date.now();
|
|
594
|
-
let success = true;
|
|
595
|
-
let error;
|
|
596
|
-
const migration = new MigrationClass();
|
|
597
|
-
const name = MigrationClass.migrationName;
|
|
598
|
-
logger.log.info("database", "migration", `${direction === "up" ? "Migrating" : "Rolling back"}: ${copper.colors.magenta(name)}...`);
|
|
599
|
-
try {
|
|
600
|
-
if (!dryRun) {
|
|
601
|
-
const driver = this.getMigrationDriver();
|
|
602
|
-
migration.setDriver(driver);
|
|
603
|
-
migration.setMigrationDefaults(this.getDataSource().migrationDefaults);
|
|
604
|
-
// ============================================================================
|
|
605
|
-
// TRANSACTION RESOLUTION (3-tier hierarchy)
|
|
606
|
-
// ============================================================================
|
|
607
|
-
// 1. Migration-level explicit override
|
|
608
|
-
// 2. Config-level global override
|
|
609
|
-
// 3. Driver default (PostgreSQL: true, MongoDB: false)
|
|
610
|
-
const shouldUseTransaction = migration.transactional ??
|
|
611
|
-
this.getDataSource().migrations?.transactional ??
|
|
612
|
-
driver.getDefaultTransactional();
|
|
613
|
-
// ============================================================================
|
|
614
|
-
// EXECUTE WITH OR WITHOUT TRANSACTION
|
|
615
|
-
// ============================================================================
|
|
616
|
-
// Collect SQL for the requested direction
|
|
617
|
-
if (direction === "up") {
|
|
618
|
-
await migration.up();
|
|
619
|
-
}
|
|
620
|
-
else {
|
|
621
|
-
await migration.down();
|
|
622
|
-
}
|
|
623
|
-
const sqlStatements = migration.toSQL();
|
|
624
|
-
const databaseDriver = this.getDataSource().driver;
|
|
625
|
-
if (shouldUseTransaction && databaseDriver.transaction) {
|
|
626
|
-
// Transactional execution
|
|
627
|
-
await databaseDriver.transaction(async () => {
|
|
628
|
-
// Execute generated SQL statements sequentially (no phase-sorting here since it's single execution)
|
|
629
|
-
for (const sql of sqlStatements) {
|
|
630
|
-
await databaseDriver.query(sql);
|
|
631
|
-
}
|
|
632
|
-
// Record migration tracking
|
|
633
|
-
if (record) {
|
|
634
|
-
if (direction === "up") {
|
|
635
|
-
const batch = options.batch ?? (await this.getNextBatchNumber());
|
|
636
|
-
await this.recordMigration(name, batch, MigrationClass.createdAt ? parseCreatedAt(MigrationClass.createdAt) : new Date());
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
await this.removeMigrationRecord(name);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
// Non-transactional execution
|
|
646
|
-
for (const sql of sqlStatements) {
|
|
647
|
-
await databaseDriver.query(sql);
|
|
648
|
-
}
|
|
649
|
-
if (record) {
|
|
650
|
-
if (direction === "up") {
|
|
651
|
-
const batch = options.batch ?? (await this.getNextBatchNumber());
|
|
652
|
-
await this.recordMigration(name, batch, MigrationClass.createdAt ? parseCreatedAt(MigrationClass.createdAt) : new Date());
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
await this.removeMigrationRecord(name);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
catch (err) {
|
|
662
|
-
success = false;
|
|
663
|
-
error = err instanceof Error ? err.message : String(err);
|
|
664
|
-
logger.log.error("database", "migration", `${copper.colors.magenta(name)}: ✗ Failed: ${error}`);
|
|
665
|
-
throw err;
|
|
666
|
-
}
|
|
667
|
-
const durationMs = Date.now() - startTime;
|
|
668
|
-
if (success) {
|
|
669
|
-
logger.log.success("database", "migration", `${direction == "up" ? "Migrated" : "Rolled back"}: ${copper.colors.magenta(name)} successfully (${durationMs}ms)`);
|
|
670
|
-
}
|
|
671
|
-
return {
|
|
672
|
-
name,
|
|
673
|
-
table: migration.table,
|
|
674
|
-
direction,
|
|
675
|
-
success,
|
|
676
|
-
error,
|
|
677
|
-
durationMs,
|
|
678
|
-
executedAt: new Date(),
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* Create, configure, and return a ready-to-use migration instance.
|
|
683
|
-
*
|
|
684
|
-
* Centralises the repeated "new + setDriver + setMigrationDefaults" boilerplate
|
|
685
|
-
* that all batch/single execution paths need.
|
|
686
|
-
*
|
|
687
|
-
* @internal
|
|
688
|
-
*/
|
|
689
|
-
createMigrationInstance(MigrationClass) {
|
|
690
|
-
const migration = new MigrationClass();
|
|
691
|
-
migration.setDriver(this.getMigrationDriver());
|
|
692
|
-
migration.setMigrationDefaults(this.getDataSource().migrationDefaults);
|
|
693
|
-
return migration;
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Format an ordered array of TaggedSQL into a human-readable SQL file string.
|
|
697
|
-
*
|
|
698
|
-
* Consecutive statements that belong to the same (phase, migration) group share
|
|
699
|
-
* a single block comment at the top, avoiding the noisy per-statement repetition.
|
|
700
|
-
*
|
|
701
|
-
* Example output:
|
|
702
|
-
* ```sql
|
|
703
|
-
* /* Phase 3 [create-users] *\/
|
|
704
|
-
* ALTER TABLE "users" ADD COLUMN "name" TEXT NOT NULL;
|
|
705
|
-
* ALTER TABLE "users" ADD COLUMN "email" TEXT NOT NULL;
|
|
706
|
-
*
|
|
707
|
-
* /* Phase 4 [create-users] *\/
|
|
708
|
-
* CREATE UNIQUE INDEX ...;
|
|
709
|
-
* ```
|
|
710
|
-
*
|
|
711
|
-
* @internal
|
|
712
|
-
*/
|
|
713
|
-
formatSQLForExport(statements, compact = false) {
|
|
714
|
-
const lines = [];
|
|
715
|
-
if (compact) {
|
|
716
|
-
// Just output raw statements, no grouping, no blank lines
|
|
717
|
-
for (const stmt of statements) {
|
|
718
|
-
lines.push(`${stmt.sql};`);
|
|
719
|
-
}
|
|
720
|
-
return lines.join("\n");
|
|
721
|
-
}
|
|
722
|
-
// Group statements by their phase and migration name
|
|
723
|
-
const grouped = new Map();
|
|
724
|
-
for (const stmt of statements) {
|
|
725
|
-
const groupKey = `Phase ${stmt.phase} [${stmt.migrationName}]`;
|
|
726
|
-
if (!grouped.has(groupKey)) {
|
|
727
|
-
grouped.set(groupKey, []);
|
|
728
|
-
}
|
|
729
|
-
grouped.get(groupKey).push(stmt.sql);
|
|
730
|
-
}
|
|
731
|
-
// Format each group
|
|
732
|
-
for (const [groupKey, sqls] of grouped.entries()) {
|
|
733
|
-
if (lines.length > 0)
|
|
734
|
-
lines.push(""); // blank line between groups
|
|
735
|
-
lines.push(`/* ${groupKey} */`);
|
|
736
|
-
for (const sql of sqls) {
|
|
737
|
-
lines.push(`${sql};`);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
return lines.join("\n");
|
|
741
|
-
}
|
|
742
|
-
/**
|
|
743
|
-
* Get pending (not executed) registered migrations.
|
|
744
|
-
*/
|
|
745
|
-
async getPendingMigrations() {
|
|
746
|
-
const executed = await this.getExecutedMigrations();
|
|
747
|
-
const executedNames = new Set(executed.map((r) => r.name));
|
|
748
|
-
const migrations = this.migrations.filter((m) => !executedNames.has(m.migrationName));
|
|
749
|
-
return migrations.sort(sortMigrations);
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Get migrations to rollback.
|
|
753
|
-
*/
|
|
754
|
-
async getMigrationsToRollback(batches) {
|
|
755
|
-
const executed = await this.getExecutedMigrations();
|
|
756
|
-
if (executed.length === 0)
|
|
757
|
-
return [];
|
|
758
|
-
const batchNumbers = [...new Set(executed.map((r) => r.batch))]
|
|
759
|
-
.sort((a, b) => b - a)
|
|
760
|
-
.slice(0, batches);
|
|
761
|
-
const toRollback = executed.filter((r) => batchNumbers.includes(r.batch)).reverse();
|
|
762
|
-
const migrations = toRollback
|
|
763
|
-
.map((r) => this.migrations.find((m) => m.migrationName === r.name))
|
|
764
|
-
.filter((m) => !!m);
|
|
765
|
-
return migrations.sort(sortMigrations);
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Get executed migration records.
|
|
769
|
-
*/
|
|
770
|
-
async getExecutedMigrations() {
|
|
771
|
-
const driver = this.getDataSource().driver;
|
|
772
|
-
try {
|
|
773
|
-
const migrationDriver = this.getMigrationDriver();
|
|
774
|
-
// Ensure migrations table exists
|
|
775
|
-
await migrationDriver.ensureMigrationsTable(this.migrationsTable);
|
|
776
|
-
const queryBuilder = driver.queryBuilder(this.migrationsTable);
|
|
777
|
-
return await queryBuilder.orderBy("batch", "asc").orderBy("name", "asc").get();
|
|
778
|
-
}
|
|
779
|
-
catch {
|
|
780
|
-
return [];
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
/**
|
|
784
|
-
* Record a migration.
|
|
785
|
-
*/
|
|
786
|
-
async recordMigration(name, batch, createdAt) {
|
|
787
|
-
const driver = this.getDataSource().driver;
|
|
788
|
-
const migrationDriver = this.getMigrationDriver();
|
|
789
|
-
// Ensure migrations table exists
|
|
790
|
-
await migrationDriver.ensureMigrationsTable(this.migrationsTable);
|
|
791
|
-
await driver.insert(this.migrationsTable, {
|
|
792
|
-
name,
|
|
793
|
-
batch,
|
|
794
|
-
executedAt: new Date(),
|
|
795
|
-
createdAt,
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* Remove a migration record.
|
|
800
|
-
*/
|
|
801
|
-
async removeMigrationRecord(name) {
|
|
802
|
-
const driver = this.getDataSource().driver;
|
|
803
|
-
await driver.delete(this.migrationsTable, { name });
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Get next batch number.
|
|
807
|
-
*/
|
|
808
|
-
async getNextBatchNumber() {
|
|
809
|
-
const executed = await this.getExecutedMigrations();
|
|
810
|
-
if (executed.length === 0)
|
|
811
|
-
return 1;
|
|
812
|
-
return Math.max(...executed.map((r) => r.batch)) + 1;
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
const migrationRunner = new MigrationRunner();exports.MigrationRunner=MigrationRunner;exports.migrationRunner=migrationRunner;//# sourceMappingURL=migration-runner.js.map
|