@warlock.js/cascade 4.1.15 → 4.2.0
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 +21 -0
- package/LICENSE +21 -0
- package/cjs/index.cjs +21388 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/context/database-data-source-context.d.mts +1 -1
- package/esm/context/database-data-source-context.d.mts.map +1 -1
- package/esm/context/database-data-source-context.mjs +1 -1
- package/esm/context/database-data-source-context.mjs.map +1 -1
- package/esm/context/database-transaction-context.d.mts +1 -1
- package/esm/context/database-transaction-context.d.mts.map +1 -1
- package/esm/context/database-transaction-context.mjs +1 -1
- package/esm/context/database-transaction-context.mjs.map +1 -1
- package/esm/contracts/database-driver.contract.d.mts +1 -1
- package/esm/contracts/database-driver.contract.d.mts.map +1 -1
- package/esm/contracts/database-id-generator.contract.d.mts +1 -1
- package/esm/contracts/database-id-generator.contract.d.mts.map +1 -1
- package/esm/contracts/database-remover.contract.d.mts +1 -1
- package/esm/contracts/database-remover.contract.d.mts.map +1 -1
- package/esm/contracts/database-restorer.contract.d.mts +1 -1
- package/esm/contracts/database-restorer.contract.d.mts.map +1 -1
- package/esm/contracts/database-writer.contract.d.mts +1 -1
- package/esm/contracts/database-writer.contract.d.mts.map +1 -1
- package/esm/contracts/driver-blueprint.contract.d.mts +1 -1
- package/esm/contracts/driver-blueprint.contract.d.mts.map +1 -1
- package/esm/contracts/migration-driver.contract.d.mts +1 -1
- package/esm/contracts/migration-driver.contract.d.mts.map +1 -1
- package/esm/contracts/query-builder.contract.d.mts +1 -1
- package/esm/contracts/query-builder.contract.d.mts.map +1 -1
- package/esm/contracts/sync-adapter.contract.d.mts +1 -1
- package/esm/contracts/sync-adapter.contract.d.mts.map +1 -1
- package/esm/data-source/data-source-registry.d.mts +1 -1
- package/esm/data-source/data-source-registry.d.mts.map +1 -1
- package/esm/data-source/data-source-registry.mjs +1 -1
- package/esm/data-source/data-source-registry.mjs.map +1 -1
- package/esm/data-source/data-source.d.mts +1 -1
- package/esm/data-source/data-source.d.mts.map +1 -1
- package/esm/data-source/data-source.mjs +1 -1
- package/esm/data-source/data-source.mjs.map +1 -1
- package/esm/database-dirty-tracker.d.mts +1 -1
- package/esm/database-dirty-tracker.d.mts.map +1 -1
- package/esm/database-dirty-tracker.mjs +1 -1
- package/esm/database-dirty-tracker.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-blueprint.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-blueprint.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.mjs +2 -2
- package/esm/drivers/mongodb/mongodb-driver.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.mjs.map +1 -1
- package/esm/drivers/mongodb/types.d.mts +1 -1
- package/esm/drivers/mongodb/types.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-blueprint.d.mts +1 -1
- package/esm/drivers/postgres/postgres-blueprint.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-blueprint.mjs +1 -1
- package/esm/drivers/postgres/postgres-blueprint.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.d.mts +1 -1
- package/esm/drivers/postgres/postgres-dialect.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.mjs +1 -1
- package/esm/drivers/postgres/postgres-dialect.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.mjs +2 -2
- package/esm/drivers/postgres/postgres-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.mts +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.mjs +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.d.mts +1 -1
- package/esm/drivers/postgres/postgres-query-builder.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.mjs +7 -5
- package/esm/drivers/postgres/postgres-query-builder.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.d.mts +1 -1
- package/esm/drivers/postgres/postgres-query-parser.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.mjs +1 -1
- package/esm/drivers/postgres/postgres-query-parser.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-sql-serializer.mjs +1 -1
- package/esm/drivers/postgres/postgres-sql-serializer.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.d.mts +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.mjs +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.mjs.map +1 -1
- package/esm/drivers/postgres/types.d.mts +1 -1
- package/esm/drivers/postgres/types.d.mts.map +1 -1
- package/esm/drivers/sql/sql-dialect.contract.d.mts +1 -1
- package/esm/drivers/sql/sql-dialect.contract.d.mts.map +1 -1
- package/esm/drivers/sql/sql-types.d.mts +1 -1
- package/esm/drivers/sql/sql-types.d.mts.map +1 -1
- package/esm/errors/missing-data-source.error.d.mts +1 -1
- package/esm/errors/missing-data-source.error.d.mts.map +1 -1
- package/esm/errors/missing-data-source.error.mjs +1 -1
- package/esm/errors/missing-data-source.error.mjs.map +1 -1
- package/esm/errors/transaction-rollback.error.d.mts +1 -1
- package/esm/errors/transaction-rollback.error.d.mts.map +1 -1
- package/esm/errors/transaction-rollback.error.mjs +1 -1
- package/esm/errors/transaction-rollback.error.mjs.map +1 -1
- package/esm/events/model-events.d.mts +1 -1
- package/esm/events/model-events.d.mts.map +1 -1
- package/esm/events/model-events.mjs +1 -1
- package/esm/events/model-events.mjs.map +1 -1
- package/esm/expressions/aggregate-expressions.d.mts +1 -1
- package/esm/expressions/aggregate-expressions.d.mts.map +1 -1
- package/esm/expressions/aggregate-expressions.mjs +1 -1
- package/esm/expressions/aggregate-expressions.mjs.map +1 -1
- package/esm/migration/column-builder.d.mts +1 -1
- package/esm/migration/column-builder.d.mts.map +1 -1
- package/esm/migration/column-builder.mjs +1 -1
- package/esm/migration/column-builder.mjs.map +1 -1
- package/esm/migration/column-helpers.d.mts +1 -1
- package/esm/migration/column-helpers.d.mts.map +1 -1
- package/esm/migration/column-helpers.mjs +1 -1
- package/esm/migration/column-helpers.mjs.map +1 -1
- package/esm/migration/foreign-key-builder.d.mts +1 -1
- package/esm/migration/foreign-key-builder.d.mts.map +1 -1
- package/esm/migration/foreign-key-builder.mjs +1 -1
- package/esm/migration/foreign-key-builder.mjs.map +1 -1
- package/esm/migration/migration-runner.d.mts +1 -1
- package/esm/migration/migration-runner.d.mts.map +1 -1
- package/esm/migration/migration-runner.mjs +1 -1
- package/esm/migration/migration-runner.mjs.map +1 -1
- package/esm/migration/migration.d.mts +1 -1
- package/esm/migration/migration.d.mts.map +1 -1
- package/esm/migration/migration.mjs +1 -1
- package/esm/migration/migration.mjs.map +1 -1
- package/esm/migration/sql-grammar.mjs +1 -1
- package/esm/migration/sql-grammar.mjs.map +1 -1
- package/esm/migration/sql-serializer.d.mts +1 -1
- package/esm/migration/sql-serializer.d.mts.map +1 -1
- package/esm/migration/sql-serializer.mjs +1 -1
- package/esm/migration/sql-serializer.mjs.map +1 -1
- package/esm/migration/types.d.mts +1 -1
- package/esm/migration/types.d.mts.map +1 -1
- package/esm/model/methods/accessor-methods.mjs +1 -1
- package/esm/model/methods/accessor-methods.mjs.map +1 -1
- package/esm/model/methods/delete-methods.mjs +1 -1
- package/esm/model/methods/delete-methods.mjs.map +1 -1
- package/esm/model/methods/dirty-methods.mjs +1 -1
- package/esm/model/methods/dirty-methods.mjs.map +1 -1
- package/esm/model/methods/hydration-methods.mjs +1 -1
- package/esm/model/methods/hydration-methods.mjs.map +1 -1
- package/esm/model/methods/instance-event-methods.mjs +1 -1
- package/esm/model/methods/instance-event-methods.mjs.map +1 -1
- package/esm/model/methods/meta-methods.mjs +1 -1
- package/esm/model/methods/meta-methods.mjs.map +1 -1
- package/esm/model/methods/pivot-methods.mjs +1 -1
- package/esm/model/methods/pivot-methods.mjs.map +1 -1
- package/esm/model/methods/query-methods.mjs +1 -1
- package/esm/model/methods/query-methods.mjs.map +1 -1
- package/esm/model/methods/restore-methods.mjs +1 -1
- package/esm/model/methods/restore-methods.mjs.map +1 -1
- package/esm/model/methods/scope-methods.mjs +1 -1
- package/esm/model/methods/scope-methods.mjs.map +1 -1
- package/esm/model/methods/serialization-methods.mjs +1 -1
- package/esm/model/methods/serialization-methods.mjs.map +1 -1
- package/esm/model/methods/static-event-methods.mjs +1 -1
- package/esm/model/methods/static-event-methods.mjs.map +1 -1
- package/esm/model/methods/write-methods.mjs +1 -1
- package/esm/model/methods/write-methods.mjs.map +1 -1
- package/esm/model/model.d.mts +1 -1
- package/esm/model/model.d.mts.map +1 -1
- package/esm/model/model.mjs +1 -1
- package/esm/model/model.mjs.map +1 -1
- package/esm/model/model.types.d.mts +1 -1
- package/esm/model/model.types.d.mts.map +1 -1
- package/esm/model/register-model.d.mts +1 -1
- package/esm/model/register-model.d.mts.map +1 -1
- package/esm/model/register-model.mjs +1 -1
- package/esm/model/register-model.mjs.map +1 -1
- package/esm/model/relation-decorators.d.mts +1 -1
- package/esm/model/relation-decorators.d.mts.map +1 -1
- package/esm/model/relation-decorators.mjs +2 -2
- package/esm/model/relation-decorators.mjs.map +1 -1
- package/esm/operations/database.d.mts +1 -1
- package/esm/operations/database.d.mts.map +1 -1
- package/esm/operations/database.mjs +1 -1
- package/esm/operations/database.mjs.map +1 -1
- package/esm/operations/migrations.d.mts +1 -1
- package/esm/operations/migrations.d.mts.map +1 -1
- package/esm/operations/migrations.mjs +1 -1
- package/esm/operations/migrations.mjs.map +1 -1
- package/esm/query-builder/query-builder.d.mts +1 -1
- package/esm/query-builder/query-builder.d.mts.map +1 -1
- package/esm/query-builder/query-builder.mjs +1 -1
- package/esm/query-builder/query-builder.mjs.map +1 -1
- package/esm/relations/key-conventions.mjs +1 -1
- package/esm/relations/key-conventions.mjs.map +1 -1
- package/esm/relations/pivot-operations.d.mts +1 -1
- package/esm/relations/pivot-operations.d.mts.map +1 -1
- package/esm/relations/pivot-operations.mjs +1 -1
- package/esm/relations/pivot-operations.mjs.map +1 -1
- package/esm/relations/relation-hydrator.d.mts +1 -1
- package/esm/relations/relation-hydrator.d.mts.map +1 -1
- package/esm/relations/relation-hydrator.mjs +1 -1
- package/esm/relations/relation-hydrator.mjs.map +1 -1
- package/esm/relations/relation-loader.d.mts +1 -1
- package/esm/relations/relation-loader.d.mts.map +1 -1
- package/esm/relations/relation-loader.mjs +1 -1
- package/esm/relations/relation-loader.mjs.map +1 -1
- package/esm/relations/types.d.mts +1 -1
- package/esm/relations/types.d.mts.map +1 -1
- package/esm/remover/database-remover.d.mts +1 -1
- package/esm/remover/database-remover.d.mts.map +1 -1
- package/esm/remover/database-remover.mjs +1 -1
- package/esm/remover/database-remover.mjs.map +1 -1
- package/esm/restorer/database-restorer.d.mts +1 -1
- package/esm/restorer/database-restorer.d.mts.map +1 -1
- package/esm/restorer/database-restorer.mjs +1 -1
- package/esm/restorer/database-restorer.mjs.map +1 -1
- package/esm/sql-database-dirty-tracker.d.mts +1 -1
- package/esm/sql-database-dirty-tracker.d.mts.map +1 -1
- package/esm/sql-database-dirty-tracker.mjs +1 -1
- package/esm/sql-database-dirty-tracker.mjs.map +1 -1
- package/esm/sync/model-events.mjs +1 -1
- package/esm/sync/model-events.mjs.map +1 -1
- package/esm/sync/model-sync-operation.d.mts +1 -1
- package/esm/sync/model-sync-operation.d.mts.map +1 -1
- package/esm/sync/model-sync-operation.mjs +1 -1
- package/esm/sync/model-sync-operation.mjs.map +1 -1
- package/esm/sync/model-sync.d.mts +1 -1
- package/esm/sync/model-sync.d.mts.map +1 -1
- package/esm/sync/model-sync.mjs +1 -1
- package/esm/sync/model-sync.mjs.map +1 -1
- package/esm/sync/sync-context.d.mts +1 -1
- package/esm/sync/sync-context.d.mts.map +1 -1
- package/esm/sync/sync-context.mjs +1 -1
- package/esm/sync/sync-context.mjs.map +1 -1
- package/esm/sync/sync-manager.d.mts +1 -1
- package/esm/sync/sync-manager.d.mts.map +1 -1
- package/esm/sync/sync-manager.mjs +1 -1
- package/esm/sync/sync-manager.mjs.map +1 -1
- package/esm/sync/types.d.mts +1 -1
- package/esm/sync/types.d.mts.map +1 -1
- package/esm/types.d.mts +1 -1
- package/esm/types.d.mts.map +1 -1
- package/esm/utils/connect-to-database.d.mts +1 -1
- package/esm/utils/connect-to-database.d.mts.map +1 -1
- package/esm/utils/connect-to-database.mjs +1 -1
- package/esm/utils/connect-to-database.mjs.map +1 -1
- package/esm/utils/database-writer.utils.d.mts +1 -1
- package/esm/utils/database-writer.utils.d.mts.map +1 -1
- package/esm/utils/database-writer.utils.mjs +1 -1
- package/esm/utils/database-writer.utils.mjs.map +1 -1
- package/esm/utils/define-model.d.mts +1 -1
- package/esm/utils/define-model.d.mts.map +1 -1
- package/esm/utils/define-model.mjs +1 -1
- package/esm/utils/define-model.mjs.map +1 -1
- package/esm/utils/is-valid-date-value.mjs +1 -1
- package/esm/utils/is-valid-date-value.mjs.map +1 -1
- package/esm/utils/once-connected.d.mts +1 -1
- package/esm/utils/once-connected.d.mts.map +1 -1
- package/esm/utils/once-connected.mjs +1 -1
- package/esm/utils/once-connected.mjs.map +1 -1
- package/esm/validation/database-seal-plugins.mjs +1 -1
- package/esm/validation/database-seal-plugins.mjs.map +1 -1
- package/esm/validation/database-writer-validation-error.d.mts +1 -1
- package/esm/validation/database-writer-validation-error.d.mts.map +1 -1
- package/esm/validation/database-writer-validation-error.mjs +1 -1
- package/esm/validation/database-writer-validation-error.mjs.map +1 -1
- package/esm/validation/mutators/embed-mutator.mjs +1 -1
- package/esm/validation/mutators/embed-mutator.mjs.map +1 -1
- package/esm/validation/plugins/database-rules-plugin.d.mts +1 -1
- package/esm/validation/plugins/database-rules-plugin.d.mts.map +1 -1
- package/esm/validation/plugins/database-rules-plugin.mjs +1 -1
- package/esm/validation/plugins/database-rules-plugin.mjs.map +1 -1
- package/esm/validation/plugins/embed-validator-plugin.d.mts +1 -1
- package/esm/validation/plugins/embed-validator-plugin.d.mts.map +1 -1
- package/esm/validation/plugins/embed-validator-plugin.mjs +1 -1
- package/esm/validation/plugins/embed-validator-plugin.mjs.map +1 -1
- package/esm/validation/rules/database-model-rule.mjs +1 -1
- package/esm/validation/rules/database-model-rule.mjs.map +1 -1
- package/esm/validation/rules/exists-rule.mjs +1 -1
- package/esm/validation/rules/exists-rule.mjs.map +1 -1
- package/esm/validation/rules/unique-rule.mjs +1 -1
- package/esm/validation/rules/unique-rule.mjs.map +1 -1
- package/esm/validation/transformers/embed-model-transformer.mjs +1 -1
- package/esm/validation/transformers/embed-model-transformer.mjs.map +1 -1
- package/esm/validation/types.d.mts +1 -1
- package/esm/validation/types.d.mts.map +1 -1
- package/esm/validation/validators/embed-validator.d.mts +1 -1
- package/esm/validation/validators/embed-validator.d.mts.map +1 -1
- package/esm/validation/validators/embed-validator.mjs +1 -1
- package/esm/validation/validators/embed-validator.mjs.map +1 -1
- package/esm/writer/database-writer.d.mts +1 -1
- package/esm/writer/database-writer.d.mts.map +1 -1
- package/esm/writer/database-writer.mjs +1 -1
- package/esm/writer/database-writer.mjs.map +1 -1
- package/llms-full.txt +535 -0
- package/llms.txt +1 -0
- package/package.json +9 -12
- package/skills/README.md +4 -0
- package/skills/alter-migration/SKILL.md +531 -0
- package/bin/cascade.js +0 -3
- package/bin/cascadejs +0 -3
- package/esm/cli/commands/migrate-export-sql.mjs +0 -48
- package/esm/cli/commands/migrate-export-sql.mjs.map +0 -1
- package/esm/cli/commands/migrate-list.mjs +0 -26
- package/esm/cli/commands/migrate-list.mjs.map +0 -1
- package/esm/cli/commands/migrate-rollback.mjs +0 -50
- package/esm/cli/commands/migrate-rollback.mjs.map +0 -1
- package/esm/cli/commands/migrate.mjs +0 -65
- package/esm/cli/commands/migrate.mjs.map +0 -1
- package/esm/cli/connection-from-env.mjs +0 -181
- package/esm/cli/connection-from-env.mjs.map +0 -1
- package/esm/cli/index.mjs +0 -31
- package/esm/cli/index.mjs.map +0 -1
- package/esm/cli/load-migrations.mjs +0 -78
- package/esm/cli/load-migrations.mjs.map +0 -1
- package/esm/cli/printers.mjs +0 -57
- package/esm/cli/printers.mjs.map +0 -1
- package/esm/cli/setup-logger.mjs +0 -30
- package/esm/cli/setup-logger.mjs.map +0 -1
- package/esm/cli/with-cli-connection.mjs +0 -39
- package/esm/cli/with-cli-connection.mjs.map +0 -1
- package/esm/cli.d.mts +0 -1
- package/esm/cli.mjs +0 -26
- package/esm/cli.mjs.map +0 -1
package/llms-full.txt
CHANGED
|
@@ -110,6 +110,541 @@ The `orderBy` reference matches the alias from the aggregates object.
|
|
|
110
110
|
- [`@warlock.js/cache/use-cached-hof/SKILL.md`](@warlock.js/cache/use-cached-hof/SKILL.md) — caching expensive aggregate results
|
|
111
111
|
|
|
112
112
|
|
|
113
|
+
## alter-migration `@warlock.js/cascade/alter-migration/SKILL.md`
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
name: alter-migration
|
|
117
|
+
description: 'Evolve an existing table with `Migration.alter(Model, schema, options?)` — add/drop/rename/modify columns; add/drop regular, unique, expression, full-text, geo, vector, and TTL indexes; add/drop foreign keys and CHECK constraints; write rollbacks with class-form methods in `down()`. Triggers: "alter a table", "add a column to existing table", "drop a column", "rename a column", "add an index", "drop a unique constraint", "change a column type", `Migration.alter`, `dropUnique`, `addIndex`, `addForeign`. Skip: creating a brand-new table — `@warlock.js/cascade/write-migration/SKILL.md`.'
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
# Alter a migration
|
|
121
|
+
|
|
122
|
+
Use `Migration.alter` to evolve an existing table — adding or dropping columns, renaming them, changing their type, and managing every variety of index or constraint. It's the declarative counterpart to `Migration.create` and inherits the table name and data source straight from the model.
|
|
123
|
+
|
|
124
|
+
> **Key difference from `Migration.create`:** `alter` does **not** auto-infer rollbacks. You must supply a `down()` function in options whenever you need to be able to roll back.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Minimal example
|
|
129
|
+
|
|
130
|
+
```ts title="src/app/users/models/user/migrations/06-09-2026_00-00-00-add-phone-to-users.migration.ts"
|
|
131
|
+
import { Migration, text } from "@warlock.js/cascade";
|
|
132
|
+
import { User } from "../user.model";
|
|
133
|
+
|
|
134
|
+
export default Migration.alter(User, {
|
|
135
|
+
add: {
|
|
136
|
+
phone: text().nullable(),
|
|
137
|
+
},
|
|
138
|
+
}, {
|
|
139
|
+
down() {
|
|
140
|
+
this.dropColumn("phone");
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Signature
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
Migration.alter(
|
|
151
|
+
model: ModelClass,
|
|
152
|
+
schema: AlterSchema,
|
|
153
|
+
options?: MigrationAlterOptions,
|
|
154
|
+
): MigrationConstructor
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- **`model`** — the model class; provides `table` and `dataSource` automatically.
|
|
158
|
+
- **`schema`** — any combination of the keys below; omit everything you don't need.
|
|
159
|
+
- **`options`** — rollback logic + order/transaction overrides (see [Options](#options)).
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Column operations
|
|
164
|
+
|
|
165
|
+
### `add` — new columns
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { Migration, text, integer, bool, uuid } from "@warlock.js/cascade";
|
|
169
|
+
import { Organization } from "app/organizations/models/organization";
|
|
170
|
+
import { User } from "../user.model";
|
|
171
|
+
|
|
172
|
+
export default Migration.alter(User, {
|
|
173
|
+
add: {
|
|
174
|
+
phone: text().nullable(),
|
|
175
|
+
login_attempts: integer().notNullable().default(0),
|
|
176
|
+
is_verified: bool().notNullable().default(false),
|
|
177
|
+
organization_id: uuid().references(Organization.table).onDelete("cascade").notNullable(),
|
|
178
|
+
},
|
|
179
|
+
}, {
|
|
180
|
+
down() {
|
|
181
|
+
this.dropColumn("phone");
|
|
182
|
+
this.dropColumn("login_attempts");
|
|
183
|
+
this.dropColumn("is_verified");
|
|
184
|
+
this.dropColumn("organization_id");
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Column helpers (`text`, `integer`, `bool`, `uuid`, `double`, `json`, `timestamp`, `date`, …) are imported from `@warlock.js/cascade` and support the same modifier chain as in `Migration.create`.
|
|
190
|
+
|
|
191
|
+
### `drop` — remove columns
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
export default Migration.alter(User, {
|
|
195
|
+
drop: ["legacy_token", "old_avatar_url"],
|
|
196
|
+
}, {
|
|
197
|
+
down() {
|
|
198
|
+
// re-add with the original definition if rollback is meaningful
|
|
199
|
+
this.text("legacy_token").nullable();
|
|
200
|
+
this.text("old_avatar_url").nullable();
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### `rename` — rename columns
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
export default Migration.alter(Post, {
|
|
209
|
+
rename: {
|
|
210
|
+
body: "content",
|
|
211
|
+
thumb_url: "thumbnail_url",
|
|
212
|
+
},
|
|
213
|
+
}, {
|
|
214
|
+
down() {
|
|
215
|
+
this.renameColumn("content", "body");
|
|
216
|
+
this.renameColumn("thumbnail_url", "thumb_url");
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### `modify` — change column type or nullability
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import { Migration, string } from "@warlock.js/cascade";
|
|
225
|
+
import { User } from "../user.model";
|
|
226
|
+
|
|
227
|
+
export default Migration.alter(User, {
|
|
228
|
+
modify: {
|
|
229
|
+
// widen email from text to varchar(320) and keep not-null
|
|
230
|
+
email: string(320).notNullable(),
|
|
231
|
+
},
|
|
232
|
+
}, {
|
|
233
|
+
down() {
|
|
234
|
+
// revert to unbounded text
|
|
235
|
+
this.text("email").notNullable();
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
> `modify` re-declares the column. Include every modifier you want to keep (`.notNullable()`, `.default(…)`, etc.) — the declaration replaces the old one entirely.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Index operations
|
|
245
|
+
|
|
246
|
+
### Regular indexes — `addIndex` / `dropIndex`
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
export default Migration.alter(Order, {
|
|
250
|
+
// single column
|
|
251
|
+
addIndex: [{ columns: "status" }],
|
|
252
|
+
}, {
|
|
253
|
+
down() {
|
|
254
|
+
this.dropIndex("status");
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
// composite index with an explicit name
|
|
261
|
+
export default Migration.alter(Order, {
|
|
262
|
+
addIndex: [
|
|
263
|
+
{ columns: ["organization_id", "status"], name: "idx_org_status" },
|
|
264
|
+
{ columns: "created_at" },
|
|
265
|
+
],
|
|
266
|
+
}, {
|
|
267
|
+
down() {
|
|
268
|
+
this.dropIndex("idx_org_status");
|
|
269
|
+
this.dropIndex("created_at");
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
`dropIndex` accepts a name string or a columns array:
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
export default Migration.alter(Order, {
|
|
278
|
+
dropIndex: ["idx_org_status", ["created_at"]],
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
`options.concurrently: true` builds the index without locking the table (Postgres):
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
addIndex: [{ columns: "email", options: { concurrently: true } }]
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Unique constraints — `addUnique` / `dropUnique`
|
|
289
|
+
|
|
290
|
+
```ts
|
|
291
|
+
// promote an indexed column to unique
|
|
292
|
+
export default Migration.alter(User, {
|
|
293
|
+
addUnique: [{ columns: "email" }],
|
|
294
|
+
}, {
|
|
295
|
+
down() {
|
|
296
|
+
this.dropUnique("email");
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Composite unique constraint:
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
export default Migration.alter(Membership, {
|
|
305
|
+
addUnique: [{ columns: ["organization_id", "user_id"], name: "uq_org_member" }],
|
|
306
|
+
}, {
|
|
307
|
+
down() {
|
|
308
|
+
this.dropUnique(["organization_id", "user_id"]);
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Downgrade a unique to a plain index (the pattern used in this session):
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
export default Migration.alter(User, {
|
|
317
|
+
dropUnique: [["email"]],
|
|
318
|
+
addIndex: [{ columns: "email", name: "users_email_index" }],
|
|
319
|
+
}, {
|
|
320
|
+
down() {
|
|
321
|
+
this.dropIndex("users_email_index");
|
|
322
|
+
this.unique("email");
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Expression indexes — `addExpressionIndex` (Postgres)
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
export default Migration.alter(User, {
|
|
331
|
+
addExpressionIndex: [
|
|
332
|
+
{ expressions: "lower(email)", name: "idx_email_ci" },
|
|
333
|
+
{ expressions: "lower(name)", name: "idx_name_ci" },
|
|
334
|
+
{ expressions: ["year(created_at)", "status"] },
|
|
335
|
+
],
|
|
336
|
+
}, {
|
|
337
|
+
down() {
|
|
338
|
+
this.dropIndex("idx_email_ci");
|
|
339
|
+
this.dropIndex("idx_name_ci");
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Specialized indexes
|
|
347
|
+
|
|
348
|
+
### Full-text — `addFullText` / `dropFullText`
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
export default Migration.alter(Article, {
|
|
352
|
+
addFullText: [
|
|
353
|
+
{
|
|
354
|
+
columns: ["title", "body"],
|
|
355
|
+
options: { name: "ft_article_search", language: "english" },
|
|
356
|
+
},
|
|
357
|
+
],
|
|
358
|
+
}, {
|
|
359
|
+
down() {
|
|
360
|
+
this.dropFullText("ft_article_search");
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Geo-spatial — `addGeoIndex` / `dropGeoIndex`
|
|
366
|
+
|
|
367
|
+
```ts
|
|
368
|
+
export default Migration.alter(Store, {
|
|
369
|
+
addGeoIndex: [{ column: "location" }],
|
|
370
|
+
}, {
|
|
371
|
+
down() {
|
|
372
|
+
this.dropGeoIndex("location");
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Options: `{ name?, type?: "2dsphere" | "2d", min?, max? }`
|
|
378
|
+
|
|
379
|
+
### Vector (AI embeddings) — `addVectorIndex` / `dropVectorIndex`
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
export default Migration.alter(Document, {
|
|
383
|
+
addVectorIndex: [{
|
|
384
|
+
column: "embedding",
|
|
385
|
+
options: { dimensions: 1536, similarity: "cosine", name: "idx_doc_embedding" },
|
|
386
|
+
}],
|
|
387
|
+
}, {
|
|
388
|
+
down() {
|
|
389
|
+
this.dropVectorIndex("embedding");
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Similarity options: `"cosine"` | `"euclidean"` | `"dotProduct"`.
|
|
395
|
+
|
|
396
|
+
### TTL (MongoDB) — `addTTLIndex` / `dropTTLIndex`
|
|
397
|
+
|
|
398
|
+
Expires documents automatically after a fixed duration:
|
|
399
|
+
|
|
400
|
+
```ts
|
|
401
|
+
export default Migration.alter(Session, {
|
|
402
|
+
addTTLIndex: [{ column: "created_at", expireAfterSeconds: 86400 }], // 24 h
|
|
403
|
+
}, {
|
|
404
|
+
down() {
|
|
405
|
+
this.dropTTLIndex("created_at");
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
## Constraints
|
|
413
|
+
|
|
414
|
+
### Foreign keys — `addForeign` / `dropForeign`
|
|
415
|
+
|
|
416
|
+
Pass a model class or a raw table-name string for `references`:
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
import { Migration } from "@warlock.js/cascade";
|
|
420
|
+
import { Team } from "app/teams/models/team";
|
|
421
|
+
import { User } from "../user.model";
|
|
422
|
+
|
|
423
|
+
export default Migration.alter(User, {
|
|
424
|
+
addForeign: [
|
|
425
|
+
{ column: "team_id", references: Team, onDelete: "cascade" },
|
|
426
|
+
{ column: "owner_id", references: "users", on: "id", onDelete: "setNull" },
|
|
427
|
+
],
|
|
428
|
+
}, {
|
|
429
|
+
down() {
|
|
430
|
+
this.dropForeign("team_id", Team.table);
|
|
431
|
+
this.dropForeign("owner_id", "users");
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
`onDelete` / `onUpdate` values: `"cascade"` | `"restrict"` | `"setNull"` | `"noAction"`. Both default to `"restrict"` when omitted.
|
|
437
|
+
|
|
438
|
+
Drop by constraint name when you named it manually:
|
|
439
|
+
|
|
440
|
+
```ts
|
|
441
|
+
dropForeign: [{ columnOrConstraint: "fk_my_custom_name" }]
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### CHECK constraints — `addCheck` / `dropCheck`
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
export default Migration.alter(Product, {
|
|
448
|
+
addCheck: [
|
|
449
|
+
{ name: "price_positive", expression: "price_cents >= 0" },
|
|
450
|
+
{ name: "stock_non_negative", expression: "stock >= 0" },
|
|
451
|
+
],
|
|
452
|
+
}, {
|
|
453
|
+
down() {
|
|
454
|
+
this.dropCheck("price_positive");
|
|
455
|
+
this.dropCheck("stock_non_negative");
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
## Raw SQL inside an alter
|
|
463
|
+
|
|
464
|
+
Use `raw` when you need a one-off SQL statement alongside declarative changes (e.g. backfilling a new column in the same migration when the table is small):
|
|
465
|
+
|
|
466
|
+
```ts
|
|
467
|
+
export default Migration.alter(User, {
|
|
468
|
+
add: {
|
|
469
|
+
full_name: text().nullable(),
|
|
470
|
+
},
|
|
471
|
+
raw: `UPDATE users SET full_name = first_name || ' ' || last_name`,
|
|
472
|
+
}, {
|
|
473
|
+
down() {
|
|
474
|
+
this.dropColumn("full_name");
|
|
475
|
+
},
|
|
476
|
+
});
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
Pass an array for multiple statements:
|
|
480
|
+
|
|
481
|
+
```ts
|
|
482
|
+
raw: [
|
|
483
|
+
`UPDATE users SET status = 'active' WHERE status IS NULL`,
|
|
484
|
+
`UPDATE users SET role = 'member' WHERE role IS NULL`,
|
|
485
|
+
]
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## Writing `down()` — the rollback function
|
|
491
|
+
|
|
492
|
+
`Migration.alter` **never** auto-infers rollback. Supply `down()` in options whenever you want `cascade migrate:rollback` to work. Inside `down()`, `this` is a full `Migration` instance — every class-form builder is available:
|
|
493
|
+
|
|
494
|
+
| Operation | Class-form call in `down()` |
|
|
495
|
+
|---|---|
|
|
496
|
+
| Drop an added column | `this.dropColumn("name")` |
|
|
497
|
+
| Re-add a dropped column | `this.text("name").nullable()` |
|
|
498
|
+
| Undo a rename | `this.renameColumn("new", "old")` |
|
|
499
|
+
| Undo a column modify | `this.text("col").notNullable()` |
|
|
500
|
+
| Drop a plain index (by name) | `this.dropIndex("idx_name")` |
|
|
501
|
+
| Drop a plain index (by columns) | `this.dropIndex(["col_a", "col_b"])` |
|
|
502
|
+
| Drop a unique constraint | `this.dropUnique("email")` or `this.dropUnique(["a", "b"])` |
|
|
503
|
+
| Add a unique constraint back | `this.unique("email")` |
|
|
504
|
+
| Add a plain index back | `this.index("email", "idx_name")` |
|
|
505
|
+
| Drop a foreign key | `this.dropForeign("col", "ref_table")` |
|
|
506
|
+
| Drop a CHECK constraint | `this.dropCheck("constraint_name")` |
|
|
507
|
+
| Drop full-text index | `this.dropFullText("ft_name")` |
|
|
508
|
+
| Drop geo index | `this.dropGeoIndex("column")` |
|
|
509
|
+
| Drop vector index | `this.dropVectorIndex("column")` |
|
|
510
|
+
| Drop TTL index | `this.dropTTLIndex("column")` |
|
|
511
|
+
| Raw SQL | `this.raw("SQL statement")` |
|
|
512
|
+
|
|
513
|
+
If a migration is genuinely irreversible, throw inside `down()` so accidental rollbacks fail loudly:
|
|
514
|
+
|
|
515
|
+
```ts
|
|
516
|
+
{
|
|
517
|
+
down() {
|
|
518
|
+
throw new Error("This migration is irreversible — restore from backup.");
|
|
519
|
+
},
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
## Options (`MigrationAlterOptions`)
|
|
526
|
+
|
|
527
|
+
| Key | Type | Purpose |
|
|
528
|
+
|---|---|---|
|
|
529
|
+
| `down` | `(this: Migration) => void \| Promise<void>` | Rollback logic (not auto-inferred) |
|
|
530
|
+
| `up` | `(this: Migration) => void \| Promise<void>` | Extra imperative logic to run after declarative changes |
|
|
531
|
+
| `order` | `number` | Execution order override (default `0`) |
|
|
532
|
+
| `createdAt` | `string` | ISO timestamp override for migration name ordering |
|
|
533
|
+
| `transactional` | `boolean` | Wrap the migration in a DB transaction |
|
|
534
|
+
|
|
535
|
+
The `up` hook runs **after** the declarative schema changes, making it useful for data backfills or conditional DDL that depends on the added schema:
|
|
536
|
+
|
|
537
|
+
```ts
|
|
538
|
+
export default Migration.alter(User, {
|
|
539
|
+
add: { verified_at: timestamp().nullable() },
|
|
540
|
+
}, {
|
|
541
|
+
up() {
|
|
542
|
+
// backfill: mark existing confirmed users as verified
|
|
543
|
+
this.raw(`UPDATE users SET verified_at = updated_at WHERE status = 'confirmed'`);
|
|
544
|
+
},
|
|
545
|
+
down() {
|
|
546
|
+
this.dropColumn("verified_at");
|
|
547
|
+
},
|
|
548
|
+
});
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
## Common recipes
|
|
554
|
+
|
|
555
|
+
### Add a column + foreign key together
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
import { Migration, uuid } from "@warlock.js/cascade";
|
|
559
|
+
import { Team } from "app/teams/models/team";
|
|
560
|
+
import { User } from "../user.model";
|
|
561
|
+
|
|
562
|
+
export default Migration.alter(User, {
|
|
563
|
+
add: {
|
|
564
|
+
team_id: uuid().nullable(),
|
|
565
|
+
},
|
|
566
|
+
addForeign: [
|
|
567
|
+
{ column: "team_id", references: Team, onDelete: "setNull" },
|
|
568
|
+
],
|
|
569
|
+
addIndex: [{ columns: "team_id" }],
|
|
570
|
+
}, {
|
|
571
|
+
down() {
|
|
572
|
+
this.dropForeign("team_id", Team.table);
|
|
573
|
+
this.dropIndex("team_id");
|
|
574
|
+
this.dropColumn("team_id");
|
|
575
|
+
},
|
|
576
|
+
});
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### Swap unique → plain index
|
|
580
|
+
|
|
581
|
+
```ts
|
|
582
|
+
export default Migration.alter(User, {
|
|
583
|
+
dropUnique: [["email"]],
|
|
584
|
+
addIndex: [{ columns: "email", name: "users_email_index" }],
|
|
585
|
+
}, {
|
|
586
|
+
down() {
|
|
587
|
+
this.dropIndex("users_email_index");
|
|
588
|
+
this.unique("email");
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### Rename + widen a column
|
|
594
|
+
|
|
595
|
+
```ts
|
|
596
|
+
export default Migration.alter(Post, {
|
|
597
|
+
rename: { body: "content" },
|
|
598
|
+
modify: { content: text().notNullable() },
|
|
599
|
+
}, {
|
|
600
|
+
down() {
|
|
601
|
+
this.renameColumn("content", "body");
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### Multiple operations in one migration
|
|
607
|
+
|
|
608
|
+
Combine freely — all operations run in a single `up()` call:
|
|
609
|
+
|
|
610
|
+
```ts
|
|
611
|
+
export default Migration.alter(Product, {
|
|
612
|
+
add: { sku: text().unique().notNullable() },
|
|
613
|
+
drop: ["old_code"],
|
|
614
|
+
rename: { price: "price_cents" },
|
|
615
|
+
modify: { price_cents: integer().notNullable() },
|
|
616
|
+
addIndex: [{ columns: ["category_id", "status"], name: "idx_cat_status" }],
|
|
617
|
+
addCheck: [{ name: "price_non_negative", expression: "price_cents >= 0" }],
|
|
618
|
+
}, {
|
|
619
|
+
down() {
|
|
620
|
+
this.dropCheck("price_non_negative");
|
|
621
|
+
this.dropIndex("idx_cat_status");
|
|
622
|
+
this.renameColumn("price_cents", "price");
|
|
623
|
+
this.text("old_code").nullable();
|
|
624
|
+
this.dropColumn("sku");
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
## Things NOT to do
|
|
632
|
+
|
|
633
|
+
- **Don't edit a shipped migration.** If it's already run in any environment, add a new migration on top.
|
|
634
|
+
- **Don't skip `down()` for reversible changes.** Without it, `cascade migrate:rollback` is a no-op on your migration.
|
|
635
|
+
- **Don't put large backfills and schema changes together.** Schema change first (nullable column or default), backfill second — in its own migration or a background job. This keeps rollback safe.
|
|
636
|
+
- **Don't use `raw` for something the declarative API already covers.** Use `addIndex`, `addUnique`, etc. — raw SQL bypasses Cascade's driver abstraction and breaks on non-Postgres sources.
|
|
637
|
+
- **Don't declare `id`, `createdAt`, or `updatedAt`** — they're managed by the framework.
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
## See also
|
|
642
|
+
|
|
643
|
+
- [`@warlock.js/cascade/write-migration/SKILL.md`](@warlock.js/cascade/write-migration/SKILL.md) — `Migration.create` for brand-new tables + all column helpers
|
|
644
|
+
- [`@warlock.js/cascade/run-cascade-cli/SKILL.md`](@warlock.js/cascade/run-cascade-cli/SKILL.md) — CLI flags + programmatic Operations API
|
|
645
|
+
- [`@warlock.js/cascade/manage-data-sources/SKILL.md`](@warlock.js/cascade/manage-data-sources/SKILL.md) — multi-DB migrations
|
|
646
|
+
|
|
647
|
+
|
|
113
648
|
## cascade-basics `@warlock.js/cascade/cascade-basics/SKILL.md`
|
|
114
649
|
|
|
115
650
|
---
|
package/llms.txt
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
## Skills
|
|
8
8
|
|
|
9
9
|
- [aggregate-data](@warlock.js/cascade/aggregate-data/SKILL.md): Compute aggregates over a query — scalar `.count()` / `.sum(field)` / `.avg` / `.min` / `.max`, plus grouped rollups via the two-arg `.groupBy(fields, { alias: $agg.* })` with the `$agg` helpers and `.having(alias, op, value)` on computed aggregates. Triggers: `.count`, `.sum`, `.avg`, `.min`, `.max`, `.groupBy`, `.having`, `$agg`, `$agg.sum`, `$agg.count`; "monthly revenue report", "X per category", "group by status", "dashboard rollup"; typical import `import { Model, $agg } from "@warlock.js/cascade"`. Skip: row queries — `@warlock.js/cascade/query-data/SKILL.md`; cached aggregates — `@warlock.js/cache/use-cached-hof/SKILL.md`; competing tools raw SQL `GROUP BY`, `mongoose aggregate`, `prisma` `groupBy`.
|
|
10
|
+
- [alter-migration](@warlock.js/cascade/alter-migration/SKILL.md): Evolve an existing table with `Migration.alter(Model, schema, options?)` — add/drop/rename/modify columns; add/drop regular, unique, expression, full-text, geo, vector, and TTL indexes; add/drop foreign keys and CHECK constraints; write rollbacks with class-form methods in `down()`. Triggers: "alter a table", "add a column to existing table", "drop a column", "rename a column", "add an index", "drop a unique constraint", "change a column type", `Migration.alter`, `dropUnique`, `addIndex`, `addForeign`. Skip: creating a brand-new table — `@warlock.js/cascade/write-migration/SKILL.md`.
|
|
10
11
|
- [cascade-basics](@warlock.js/cascade/cascade-basics/SKILL.md): Start with @warlock.js/cascade ORM — model-first for MongoDB and Postgres, one schema (seal) does triple duty (type / validator / DB shape), model is the query entry point. Triggers: `Model`, `RegisterModel`, `connectToDatabase`, `Infer`, `v.object`; "which cascade skill do I need", "set up the ORM", "define my first model", "model-first ORM"; typical import `import { Model, RegisterModel } from "@warlock.js/cascade"`. Skip: schema vocabulary — `@warlock.js/seal/seal-basics/SKILL.md`; competing libs `mongoose`, `prisma`, `typeorm`, `drizzle`, `sequelize`, `mongodb` driver, `knex`.
|
|
11
12
|
- [configure-delete-strategy](@warlock.js/cascade/configure-delete-strategy/SKILL.md): Pick the delete behavior — `permanent` (hard delete), `soft` (set `deletedAt`, keep the row), `trash` (move to a separate table). Configure via `static deleteStrategy` or `.destroy({ strategy })`; restore via static `Model.restore(id)` / `Model.restoreAll()`. Triggers: `static deleteStrategy`, `.destroy`, `Model.restore`, `Model.restoreAll`, `deletedAtColumn`, `trashTable`; "soft delete users", "restore a deleted record", "GDPR hard delete"; typical import `import { Model } from "@warlock.js/cascade"`. Skip: lifecycle events — `@warlock.js/cascade/subscribe-to-model-events/SKILL.md`; competing libs `mongoose-delete`, `typeorm softRemove`, `sequelize` paranoid.
|
|
12
13
|
- [define-model](@warlock.js/cascade/define-model/SKILL.md): Define a Cascade model — `@RegisterModel()`, class extends `Model<TSchema>`, `static table`, `static schema`, three update idioms (`.set` / `.merge` / `.save`), `.unset`, `.destroy`, `static toJsonColumns` / `resource` for output shaping. Triggers: `Model`, `RegisterModel`, `static schema`, `.set`, `.merge`, `.save`, `.unset`, `.destroy`, `toJsonColumns`, `resource`; "how do I define a model", "shape the JSON output", "remove a field"; typical import `import { Model, RegisterModel } from "@warlock.js/cascade"`. Skip: querying — `@warlock.js/cascade/query-data/SKILL.md`; relations — `@warlock.js/cascade/define-relations/SKILL.md`; competing libs `mongoose`, `prisma`, `typeorm` `@Entity`.
|
package/package.json
CHANGED
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@mongez/events": "^2.2.6",
|
|
28
28
|
"@mongez/reinforcements": "^3.2.0",
|
|
29
29
|
"@mongez/supportive-is": "^2.1.3",
|
|
30
|
-
"@warlock.js/context": "4.
|
|
31
|
-
"@warlock.js/logger": "4.
|
|
32
|
-
"@warlock.js/seal": "4.
|
|
30
|
+
"@warlock.js/context": "4.2.0",
|
|
31
|
+
"@warlock.js/logger": "4.2.0",
|
|
32
|
+
"@warlock.js/seal": "4.2.0",
|
|
33
33
|
"citty": "^0.2.2",
|
|
34
34
|
"fast-glob": "^3.3.3"
|
|
35
35
|
},
|
|
@@ -40,9 +40,8 @@
|
|
|
40
40
|
"bin": {
|
|
41
41
|
"cascade": "bin/cascade.js"
|
|
42
42
|
},
|
|
43
|
-
"version": "4.
|
|
44
|
-
"
|
|
45
|
-
"main": "./esm/index.mjs",
|
|
43
|
+
"version": "4.2.0",
|
|
44
|
+
"main": "./cjs/index.cjs",
|
|
46
45
|
"module": "./esm/index.mjs",
|
|
47
46
|
"types": "./esm/index.d.mts",
|
|
48
47
|
"exports": {
|
|
@@ -50,12 +49,10 @@
|
|
|
50
49
|
"import": {
|
|
51
50
|
"types": "./esm/index.d.mts",
|
|
52
51
|
"default": "./esm/index.mjs"
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"types": "./esm/cli.d.mts",
|
|
58
|
-
"default": "./esm/cli.mjs"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./esm/index.d.mts",
|
|
55
|
+
"default": "./cjs/index.cjs"
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
}
|
package/skills/README.md
CHANGED
|
@@ -4,6 +4,10 @@ Per-task skills. All cross-references use the form `@warlock.js/<pkg>/<skill>/SK
|
|
|
4
4
|
|
|
5
5
|
## Skills
|
|
6
6
|
|
|
7
|
+
### [`alter-migration/`](./alter-migration/SKILL.md)
|
|
8
|
+
|
|
9
|
+
Evolve an existing table with `Migration.alter(Model, schema, options?)` — add/drop/rename/modify columns; add/drop regular, unique, expression, full-text, geo, vector, and TTL indexes; add/drop foreign keys and CHECK constraints; write rollbacks with class-form methods in `down()`. Load when changing an existing table — adding columns, swapping unique→index, wiring new foreign keys, or any DDL that's not creating a brand-new table.
|
|
10
|
+
|
|
7
11
|
### [`aggregate-data/`](./aggregate-data/SKILL.md)
|
|
8
12
|
|
|
9
13
|
Compute aggregates over a query — `.count()`, `.sum(field)`, `.avg`, `.min`, `.max`, plus the two-arg `.groupBy(fields, { alias: $agg.* })` + `.having` for group-level rollups. Load when building reports, dashboards, 'X per category' rollups, or any query returning numbers rather than rows.
|