velocious 1.0.430 → 1.0.432
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/bin/velocious.js +48 -0
- package/build/application.js +229 -0
- package/build/authorization/ability.js +329 -0
- package/build/authorization/base-resource.js +143 -0
- package/build/background-jobs/client.js +50 -0
- package/build/background-jobs/cron-expression.js +277 -0
- package/build/background-jobs/forked-runner-child.js +86 -0
- package/build/background-jobs/job-record.js +13 -0
- package/build/background-jobs/job-registry.js +92 -0
- package/build/background-jobs/job-runner.js +107 -0
- package/build/background-jobs/job.js +77 -0
- package/build/background-jobs/json-socket.js +78 -0
- package/build/background-jobs/main.js +926 -0
- package/build/background-jobs/normalize-error.js +26 -0
- package/build/background-jobs/scheduler.js +274 -0
- package/build/background-jobs/socket-request.js +68 -0
- package/build/background-jobs/status-reporter.js +101 -0
- package/build/background-jobs/store.js +994 -0
- package/build/background-jobs/types.js +70 -0
- package/build/background-jobs/web/authorization.js +89 -0
- package/build/background-jobs/web/controller.js +280 -0
- package/build/background-jobs/web/index.js +57 -0
- package/build/background-jobs/web/path-matcher.js +74 -0
- package/build/background-jobs/web/registry.js +49 -0
- package/build/background-jobs/worker.js +683 -0
- package/build/beacon/client.js +330 -0
- package/build/beacon/in-process-broker.js +71 -0
- package/build/beacon/in-process-client.js +139 -0
- package/build/beacon/server.js +148 -0
- package/build/beacon/types.js +55 -0
- package/build/bin/velocious.js +39 -34
- package/build/cli/base-command.js +67 -0
- package/build/cli/browser-cli.js +45 -0
- package/build/cli/commands/background-jobs-main.js +7 -0
- package/build/cli/commands/background-jobs-runner.js +7 -0
- package/build/cli/commands/background-jobs-worker.js +7 -0
- package/build/cli/commands/beacon.js +7 -0
- package/build/cli/commands/console.js +12 -0
- package/build/cli/commands/db/base-command.js +82 -0
- package/build/cli/commands/db/create.js +64 -0
- package/build/cli/commands/db/drop.js +75 -0
- package/build/cli/commands/db/migrate.js +17 -0
- package/build/cli/commands/db/reset.js +22 -0
- package/build/cli/commands/db/rollback.js +15 -0
- package/build/cli/commands/db/schema/dump.js +12 -0
- package/build/cli/commands/db/schema/load.js +12 -0
- package/build/cli/commands/db/seed.js +12 -0
- package/build/cli/commands/db/tenants/check.js +38 -0
- package/build/cli/commands/db/tenants/create.js +33 -0
- package/build/cli/commands/db/tenants/migrate.js +49 -0
- package/build/cli/commands/destroy/migration.js +7 -0
- package/build/cli/commands/generate/base-models.js +7 -0
- package/build/cli/commands/generate/frontend-models.js +12 -0
- package/build/cli/commands/generate/migration.js +7 -0
- package/build/cli/commands/generate/model.js +7 -0
- package/build/cli/commands/init.js +11 -0
- package/build/cli/commands/routes.js +7 -0
- package/build/cli/commands/run-script.js +12 -0
- package/build/cli/commands/runner.js +12 -0
- package/build/cli/commands/server.js +7 -0
- package/build/cli/commands/test.js +9 -0
- package/build/cli/index.js +152 -0
- package/build/cli/tenant-database-command-helper.js +198 -0
- package/build/cli/use-browser-cli.js +30 -0
- package/build/configuration-resolver.js +65 -0
- package/build/configuration-types.js +429 -0
- package/build/configuration.js +2590 -0
- package/build/controller.js +421 -0
- package/build/current-configuration.js +31 -0
- package/build/current.js +80 -0
- package/build/database/annotations-async-hooks.js +47 -0
- package/build/database/annotations.js +40 -0
- package/build/database/drivers/base-column.js +182 -0
- package/build/database/drivers/base-columns-index.js +81 -0
- package/build/database/drivers/base-foreign-key.js +104 -0
- package/build/database/drivers/base-table.js +156 -0
- package/build/database/drivers/base.js +1609 -0
- package/build/database/drivers/mssql/column.js +74 -0
- package/build/database/drivers/mssql/columns-index.js +6 -0
- package/build/database/drivers/mssql/connect-connection.js +16 -0
- package/build/database/drivers/mssql/foreign-key.js +12 -0
- package/build/database/drivers/mssql/index.js +590 -0
- package/build/database/drivers/mssql/options.js +79 -0
- package/build/database/drivers/mssql/query-parser.js +6 -0
- package/build/database/drivers/mssql/sql/alter-table.js +4 -0
- package/build/database/drivers/mssql/sql/create-database.js +36 -0
- package/build/database/drivers/mssql/sql/create-index.js +4 -0
- package/build/database/drivers/mssql/sql/create-table.js +4 -0
- package/build/database/drivers/mssql/sql/delete.js +19 -0
- package/build/database/drivers/mssql/sql/drop-database.js +36 -0
- package/build/database/drivers/mssql/sql/drop-table.js +4 -0
- package/build/database/drivers/mssql/sql/insert.js +4 -0
- package/build/database/drivers/mssql/sql/update.js +31 -0
- package/build/database/drivers/mssql/sql/upsert.js +23 -0
- package/build/database/drivers/mssql/structure-sql.js +120 -0
- package/build/database/drivers/mssql/table.js +145 -0
- package/build/database/drivers/mysql/column.js +112 -0
- package/build/database/drivers/mysql/columns-index.js +22 -0
- package/build/database/drivers/mysql/foreign-key.js +12 -0
- package/build/database/drivers/mysql/index.js +473 -0
- package/build/database/drivers/mysql/options.js +34 -0
- package/build/database/drivers/mysql/query-parser.js +6 -0
- package/build/database/drivers/mysql/query.js +37 -0
- package/build/database/drivers/mysql/sql/alter-table.js +6 -0
- package/build/database/drivers/mysql/sql/create-database.js +39 -0
- package/build/database/drivers/mysql/sql/create-index.js +6 -0
- package/build/database/drivers/mysql/sql/create-table.js +6 -0
- package/build/database/drivers/mysql/sql/delete.js +21 -0
- package/build/database/drivers/mysql/sql/drop-database.js +6 -0
- package/build/database/drivers/mysql/sql/drop-table.js +6 -0
- package/build/database/drivers/mysql/sql/insert.js +6 -0
- package/build/database/drivers/mysql/sql/update.js +33 -0
- package/build/database/drivers/mysql/sql/upsert.js +13 -0
- package/build/database/drivers/mysql/structure-sql.js +93 -0
- package/build/database/drivers/mysql/table.js +121 -0
- package/build/database/drivers/pgsql/column.js +90 -0
- package/build/database/drivers/pgsql/columns-index.js +6 -0
- package/build/database/drivers/pgsql/foreign-key.js +12 -0
- package/build/database/drivers/pgsql/index.js +441 -0
- package/build/database/drivers/pgsql/options.js +32 -0
- package/build/database/drivers/pgsql/query-parser.js +6 -0
- package/build/database/drivers/pgsql/sql/alter-table.js +6 -0
- package/build/database/drivers/pgsql/sql/create-database.js +38 -0
- package/build/database/drivers/pgsql/sql/create-index.js +6 -0
- package/build/database/drivers/pgsql/sql/create-table.js +6 -0
- package/build/database/drivers/pgsql/sql/delete.js +21 -0
- package/build/database/drivers/pgsql/sql/drop-database.js +6 -0
- package/build/database/drivers/pgsql/sql/drop-table.js +6 -0
- package/build/database/drivers/pgsql/sql/insert.js +6 -0
- package/build/database/drivers/pgsql/sql/update.js +33 -0
- package/build/database/drivers/pgsql/sql/upsert.js +14 -0
- package/build/database/drivers/pgsql/structure-sql.js +126 -0
- package/build/database/drivers/pgsql/table.js +135 -0
- package/build/database/drivers/sqlite/base.js +509 -0
- package/build/database/drivers/sqlite/column.js +75 -0
- package/build/database/drivers/sqlite/columns-index.js +30 -0
- package/build/database/drivers/sqlite/connection-sql-js.js +46 -0
- package/build/database/drivers/sqlite/foreign-key.js +24 -0
- package/build/database/drivers/sqlite/index.js +394 -0
- package/build/database/drivers/sqlite/index.native.js +72 -0
- package/build/database/drivers/sqlite/index.web.js +99 -0
- package/build/database/drivers/sqlite/options.js +32 -0
- package/build/database/drivers/sqlite/query-parser.js +6 -0
- package/build/database/drivers/sqlite/query.js +35 -0
- package/build/database/drivers/sqlite/query.native.js +35 -0
- package/build/database/drivers/sqlite/query.web.js +49 -0
- package/build/database/drivers/sqlite/sql/alter-table.js +187 -0
- package/build/database/drivers/sqlite/sql/create-index.js +6 -0
- package/build/database/drivers/sqlite/sql/create-table.js +6 -0
- package/build/database/drivers/sqlite/sql/delete.js +26 -0
- package/build/database/drivers/sqlite/sql/drop-table.js +6 -0
- package/build/database/drivers/sqlite/sql/insert.js +6 -0
- package/build/database/drivers/sqlite/sql/update.js +33 -0
- package/build/database/drivers/sqlite/sql/upsert.js +14 -0
- package/build/database/drivers/sqlite/structure-sql.js +56 -0
- package/build/database/drivers/sqlite/table-rebuilder.js +96 -0
- package/build/database/drivers/sqlite/table.js +131 -0
- package/build/database/drivers/structure-sql/utils.js +35 -0
- package/build/database/handler.js +13 -0
- package/build/database/initializer-from-require-context.js +101 -0
- package/build/database/migration/index.js +438 -0
- package/build/database/migrator/files-finder.js +55 -0
- package/build/database/migrator/types.js +31 -0
- package/build/database/migrator.js +557 -0
- package/build/database/pool/async-tracked-multi-connection.js +1164 -0
- package/build/database/pool/base-methods-forward.js +52 -0
- package/build/database/pool/base.js +380 -0
- package/build/database/pool/single-multi-use.js +118 -0
- package/build/database/query/alter-table-base.js +104 -0
- package/build/database/query/base.js +49 -0
- package/build/database/query/create-database-base.js +42 -0
- package/build/database/query/create-index-base.js +117 -0
- package/build/database/query/create-table-base.js +205 -0
- package/build/database/query/delete-base.js +19 -0
- package/build/database/query/drop-database-base.js +38 -0
- package/build/database/query/drop-table-base.js +58 -0
- package/build/database/query/from-base.js +36 -0
- package/build/database/query/from-plain.js +16 -0
- package/build/database/query/from-table.js +18 -0
- package/build/database/query/index.js +533 -0
- package/build/database/query/insert-base.js +172 -0
- package/build/database/query/join-base.js +43 -0
- package/build/database/query/join-object.js +167 -0
- package/build/database/query/join-plain.js +18 -0
- package/build/database/query/join-tracker.js +93 -0
- package/build/database/query/model-class-query.js +1577 -0
- package/build/database/query/order-base.js +33 -0
- package/build/database/query/order-column.js +77 -0
- package/build/database/query/order-plain.js +28 -0
- package/build/database/query/preloader/belongs-to.js +267 -0
- package/build/database/query/preloader/ensure-model-class-initialized.js +18 -0
- package/build/database/query/preloader/has-many.js +316 -0
- package/build/database/query/preloader/has-one.js +123 -0
- package/build/database/query/preloader/selection.js +152 -0
- package/build/database/query/preloader.js +201 -0
- package/build/database/query/query-data.js +305 -0
- package/build/database/query/select-base.js +30 -0
- package/build/database/query/select-plain.js +18 -0
- package/build/database/query/select-table-and-column.js +28 -0
- package/build/database/query/update-base.js +41 -0
- package/build/database/query/upsert-base.js +103 -0
- package/build/database/query/where-base.js +38 -0
- package/build/database/query/where-combinator.js +31 -0
- package/build/database/query/where-hash.js +77 -0
- package/build/database/query/where-model-class-hash.js +505 -0
- package/build/database/query/where-not.js +23 -0
- package/build/database/query/where-plain.js +20 -0
- package/build/database/query/with-count.js +219 -0
- package/build/database/query-parser/base-query-parser.js +40 -0
- package/build/database/query-parser/from-parser.js +49 -0
- package/build/database/query-parser/group-parser.js +55 -0
- package/build/database/query-parser/joins-parser.js +37 -0
- package/build/database/query-parser/limit-parser.js +77 -0
- package/build/database/query-parser/options.js +94 -0
- package/build/database/query-parser/order-parser.js +45 -0
- package/build/database/query-parser/select-parser.js +67 -0
- package/build/database/query-parser/where-parser.js +46 -0
- package/build/database/record/acts-as-list.js +374 -0
- package/build/database/record/attachments/download.js +49 -0
- package/build/database/record/attachments/handle.js +188 -0
- package/build/database/record/attachments/normalize-input.js +213 -0
- package/build/database/record/attachments/storage-drivers/filesystem.js +114 -0
- package/build/database/record/attachments/storage-drivers/native.js +146 -0
- package/build/database/record/attachments/storage-drivers/s3.js +245 -0
- package/build/database/record/attachments/store.js +591 -0
- package/build/database/record/index.js +4094 -0
- package/build/database/record/instance-relationships/base.js +289 -0
- package/build/database/record/instance-relationships/belongs-to.js +84 -0
- package/build/database/record/instance-relationships/has-many.js +284 -0
- package/build/database/record/instance-relationships/has-one.js +117 -0
- package/build/database/record/record-not-found-error.js +3 -0
- package/build/database/record/relationships/base.js +195 -0
- package/build/database/record/relationships/belongs-to.js +57 -0
- package/build/database/record/relationships/has-many.js +46 -0
- package/build/database/record/relationships/has-one.js +46 -0
- package/build/database/record/state-machine.js +278 -0
- package/build/database/record/user-module.js +43 -0
- package/build/database/record/validators/base.js +27 -0
- package/build/database/record/validators/format.js +50 -0
- package/build/database/record/validators/presence.js +24 -0
- package/build/database/record/validators/uniqueness.js +124 -0
- package/build/database/table-data/index.js +241 -0
- package/build/database/table-data/table-column.js +416 -0
- package/build/database/table-data/table-foreign-key.js +69 -0
- package/build/database/table-data/table-index.js +46 -0
- package/build/database/table-data/table-reference.js +13 -0
- package/build/database/use-database.js +48 -0
- package/build/environment-handlers/base.js +561 -0
- package/build/environment-handlers/browser.js +338 -0
- package/build/environment-handlers/node/cli/commands/background-jobs-main.js +21 -0
- package/build/environment-handlers/node/cli/commands/background-jobs-runner.js +24 -0
- package/build/environment-handlers/node/cli/commands/background-jobs-worker.js +47 -0
- package/build/environment-handlers/node/cli/commands/beacon.js +21 -0
- package/build/environment-handlers/node/cli/commands/cli-command-context.js +31 -0
- package/build/environment-handlers/node/cli/commands/console.js +149 -0
- package/build/environment-handlers/node/cli/commands/db/schema/dump.js +43 -0
- package/build/environment-handlers/node/cli/commands/db/schema/load.js +69 -0
- package/build/environment-handlers/node/cli/commands/db/seed.js +79 -0
- package/build/environment-handlers/node/cli/commands/destroy/migration.js +47 -0
- package/build/environment-handlers/node/cli/commands/generate/base-models.js +396 -0
- package/build/environment-handlers/node/cli/commands/generate/frontend-models.js +872 -0
- package/build/environment-handlers/node/cli/commands/generate/migration.js +45 -0
- package/build/environment-handlers/node/cli/commands/generate/model.js +45 -0
- package/build/environment-handlers/node/cli/commands/init.js +68 -0
- package/build/environment-handlers/node/cli/commands/routes.js +63 -0
- package/build/environment-handlers/node/cli/commands/run-script.js +85 -0
- package/build/environment-handlers/node/cli/commands/runner.js +84 -0
- package/build/environment-handlers/node/cli/commands/server.js +151 -0
- package/build/environment-handlers/node/cli/commands/test.js +118 -0
- package/build/environment-handlers/node.js +887 -0
- package/build/error-logger.js +30 -0
- package/build/frontend-model-controller.js +3491 -0
- package/build/frontend-model-resource/base-resource.js +935 -0
- package/build/frontend-models/base.js +4004 -0
- package/build/frontend-models/clear-pending-debounced-callback.js +16 -0
- package/build/frontend-models/event-hook-models.js +49 -0
- package/build/frontend-models/model-registry.js +28 -0
- package/build/frontend-models/outgoing-event-buffer.js +51 -0
- package/build/frontend-models/preloader.js +169 -0
- package/build/frontend-models/query.js +2245 -0
- package/build/frontend-models/resource-config-validation.js +56 -0
- package/build/frontend-models/resource-definition.js +399 -0
- package/build/frontend-models/transport-serialization.js +369 -0
- package/build/frontend-models/use-created-event.js +21 -0
- package/build/frontend-models/use-destroyed-event.js +148 -0
- package/build/frontend-models/use-model-class-event.js +164 -0
- package/build/frontend-models/use-updated-event.js +152 -0
- package/build/frontend-models/websocket-channel.js +494 -0
- package/build/frontend-models/websocket-publishers.js +224 -0
- package/build/http-client/header.js +17 -0
- package/build/http-client/index.js +139 -0
- package/build/http-client/request.js +94 -0
- package/build/http-client/response.js +151 -0
- package/build/http-client/websocket-client.js +27 -0
- package/build/http-server/client/index.js +507 -0
- package/build/http-server/client/params-to-object.js +152 -0
- package/build/http-server/client/request-buffer/form-data-part.js +139 -0
- package/build/http-server/client/request-buffer/header.js +19 -0
- package/build/http-server/client/request-buffer/index.js +535 -0
- package/build/http-server/client/request-parser.js +195 -0
- package/build/http-server/client/request-runner.js +321 -0
- package/build/http-server/client/request-timing.js +171 -0
- package/build/http-server/client/request.js +114 -0
- package/build/http-server/client/response.js +251 -0
- package/build/http-server/client/uploaded-file/memory-uploaded-file.js +32 -0
- package/build/http-server/client/uploaded-file/temporary-uploaded-file.js +32 -0
- package/build/http-server/client/uploaded-file/uploaded-file.js +36 -0
- package/build/http-server/client/websocket-request.js +147 -0
- package/build/http-server/client/websocket-session.js +1755 -0
- package/build/http-server/cookie.js +245 -0
- package/build/http-server/development-reloader.js +240 -0
- package/build/http-server/index.js +561 -0
- package/build/http-server/remote-address.js +77 -0
- package/build/http-server/server-client.js +222 -0
- package/build/http-server/server-lock.js +178 -0
- package/build/http-server/websocket-channel-subscribers.js +110 -0
- package/build/http-server/websocket-channel.js +137 -0
- package/build/http-server/websocket-connection.js +118 -0
- package/build/http-server/websocket-event-log-store.js +433 -0
- package/build/http-server/websocket-events-host.js +170 -0
- package/build/http-server/websocket-events.js +50 -0
- package/build/http-server/worker-handler/channel-subscriber-dispatch.js +28 -0
- package/build/http-server/worker-handler/in-process.js +155 -0
- package/build/http-server/worker-handler/index.js +370 -0
- package/build/http-server/worker-handler/worker-script.js +6 -0
- package/build/http-server/worker-handler/worker-thread.js +286 -0
- package/build/index.js +1 -2
- package/build/initializer.js +39 -0
- package/build/jobs/mail-delivery.js +22 -0
- package/build/logger/base-logger.js +34 -0
- package/build/logger/console-logger.js +28 -0
- package/build/logger/file-logger.js +36 -0
- package/build/logger/outputs/array-output.js +50 -0
- package/build/logger/outputs/console-output.js +32 -0
- package/build/logger/outputs/file-output.js +55 -0
- package/build/logger/outputs/stdout-output.js +64 -0
- package/build/logger.js +507 -0
- package/build/mailer/backends/smtp.js +197 -0
- package/build/mailer/base.js +337 -0
- package/build/mailer/delivery.js +70 -0
- package/build/mailer/index.js +24 -0
- package/build/mailer.js +15 -0
- package/build/plugins/sqljs-wasm-route-controller.js +70 -0
- package/build/plugins/sqljs-wasm-route.js +71 -0
- package/build/record-payload-values.js +83 -0
- package/build/routes/app-routes.js +17 -0
- package/build/routes/base-route.js +133 -0
- package/build/routes/basic-route.js +109 -0
- package/build/routes/built-in/debug/controller.js +12 -0
- package/build/routes/built-in/errors/controller.js +7 -0
- package/build/routes/get-route.js +75 -0
- package/build/routes/hooks/frontend-model-command-route-hook.js +100 -0
- package/build/routes/index.js +50 -0
- package/build/routes/namespace-route.js +51 -0
- package/build/routes/plugin-routes.js +141 -0
- package/build/routes/post-route.js +74 -0
- package/build/routes/resolver.js +535 -0
- package/build/routes/resource-route.js +154 -0
- package/build/routes/root-route.js +11 -0
- package/build/src/authorization/ability.d.ts +24 -23
- package/build/src/authorization/ability.d.ts.map +1 -1
- package/build/src/authorization/ability.js +14 -13
- package/build/src/authorization/base-resource.d.ts +20 -26
- package/build/src/authorization/base-resource.d.ts.map +1 -1
- package/build/src/authorization/base-resource.js +13 -11
- package/build/src/configuration-types.d.ts +21 -2
- package/build/src/configuration-types.d.ts.map +1 -1
- package/build/src/configuration-types.js +8 -2
- package/build/src/database/query/where-combinator.d.ts.map +1 -1
- package/build/src/database/query/where-combinator.js +1 -2
- package/build/src/database/record/acts-as-list.js +2 -2
- package/build/src/database/record/attachments/store.d.ts +1 -1
- package/build/src/database/record/attachments/store.d.ts.map +1 -1
- package/build/src/database/record/attachments/store.js +2 -2
- package/build/src/database/record/index.d.ts +82 -20
- package/build/src/database/record/index.d.ts.map +1 -1
- package/build/src/database/record/index.js +126 -13
- package/build/src/database/record/relationships/base.d.ts +2 -2
- package/build/src/database/record/relationships/base.d.ts.map +1 -1
- package/build/src/database/record/relationships/base.js +3 -3
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.d.ts +4 -2
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.js +59 -36
- package/build/src/frontend-model-controller.d.ts +6 -6
- package/build/src/frontend-model-controller.d.ts.map +1 -1
- package/build/src/frontend-model-controller.js +4 -4
- package/build/src/frontend-model-resource/base-resource.d.ts +18 -17
- package/build/src/frontend-model-resource/base-resource.d.ts.map +1 -1
- package/build/src/frontend-model-resource/base-resource.js +22 -10
- package/build/src/frontend-models/base.d.ts +19 -12
- package/build/src/frontend-models/base.d.ts.map +1 -1
- package/build/src/frontend-models/base.js +79 -48
- package/build/src/frontend-models/preloader.d.ts +6 -6
- package/build/src/frontend-models/preloader.d.ts.map +1 -1
- package/build/src/frontend-models/preloader.js +5 -5
- package/build/src/frontend-models/query.d.ts.map +1 -1
- package/build/src/frontend-models/query.js +1 -4
- package/build/src/utils/ransack.d.ts.map +1 -1
- package/build/src/utils/ransack.js +1 -2
- package/build/templates/configuration.js +61 -0
- package/build/templates/generate-migration.js +11 -0
- package/build/templates/generate-model.js +6 -0
- package/build/templates/routes.js +11 -0
- package/build/testing/base-expect.js +17 -0
- package/build/testing/browser-frontend-model-event-hook-scenarios.js +520 -0
- package/build/testing/browser-test-app.js +32 -0
- package/build/testing/expect-to-change.js +55 -0
- package/build/testing/expect-utils.js +269 -0
- package/build/testing/expect.js +763 -0
- package/build/testing/request-client.js +90 -0
- package/build/testing/test-files-finder.js +364 -0
- package/build/testing/test-filter-parser.js +198 -0
- package/build/testing/test-runner.js +1168 -0
- package/build/testing/test-suite-splitter.js +177 -0
- package/build/testing/test.js +370 -0
- package/build/utils/backtrace-cleaner-node.js +87 -0
- package/build/utils/backtrace-cleaner.js +266 -0
- package/build/utils/ensure-error.js +15 -0
- package/build/utils/event-emitter.js +8 -0
- package/build/utils/file-exists.js +18 -0
- package/build/utils/format-value.js +101 -0
- package/build/utils/model-scope.js +56 -0
- package/build/utils/nest-callbacks.js +22 -0
- package/build/utils/plain-object.js +14 -0
- package/build/utils/ransack.js +859 -0
- package/build/utils/rest-args-error.js +14 -0
- package/build/utils/singularize-model-name.js +18 -0
- package/build/utils/split-sql-statements.js +88 -0
- package/build/utils/to-import-specifier.js +53 -0
- package/build/utils/with-tracked-stack-async-hooks.js +103 -0
- package/build/utils/with-tracked-stack.js +38 -0
- package/build/velocious-error.js +34 -0
- package/index.js +1 -0
- package/package.json +10 -4
- package/scripts/clean-build.js +8 -0
- package/scripts/ensure-bin-executable.js +13 -0
- package/scripts/run-tests.js +37 -0
- package/scripts/test-browser.js +486 -0
- package/src/application.js +229 -0
- package/src/authorization/ability.js +329 -0
- package/src/authorization/base-resource.js +143 -0
- package/src/background-jobs/client.js +50 -0
- package/src/background-jobs/cron-expression.js +277 -0
- package/src/background-jobs/forked-runner-child.js +86 -0
- package/src/background-jobs/job-record.js +13 -0
- package/src/background-jobs/job-registry.js +92 -0
- package/src/background-jobs/job-runner.js +107 -0
- package/src/background-jobs/job.js +77 -0
- package/src/background-jobs/json-socket.js +78 -0
- package/src/background-jobs/main.js +926 -0
- package/src/background-jobs/normalize-error.js +26 -0
- package/src/background-jobs/scheduler.js +274 -0
- package/src/background-jobs/socket-request.js +68 -0
- package/src/background-jobs/status-reporter.js +101 -0
- package/src/background-jobs/store.js +994 -0
- package/src/background-jobs/types.js +70 -0
- package/src/background-jobs/web/authorization.js +89 -0
- package/src/background-jobs/web/controller.js +280 -0
- package/src/background-jobs/web/index.js +57 -0
- package/src/background-jobs/web/path-matcher.js +74 -0
- package/src/background-jobs/web/registry.js +49 -0
- package/src/background-jobs/worker.js +683 -0
- package/src/beacon/client.js +330 -0
- package/src/beacon/in-process-broker.js +71 -0
- package/src/beacon/in-process-client.js +139 -0
- package/src/beacon/server.js +148 -0
- package/src/beacon/types.js +55 -0
- package/src/cli/base-command.js +67 -0
- package/src/cli/browser-cli.js +45 -0
- package/src/cli/commands/background-jobs-main.js +7 -0
- package/src/cli/commands/background-jobs-runner.js +7 -0
- package/src/cli/commands/background-jobs-worker.js +7 -0
- package/src/cli/commands/beacon.js +7 -0
- package/src/cli/commands/console.js +12 -0
- package/src/cli/commands/db/base-command.js +82 -0
- package/src/cli/commands/db/create.js +64 -0
- package/src/cli/commands/db/drop.js +75 -0
- package/src/cli/commands/db/migrate.js +17 -0
- package/src/cli/commands/db/reset.js +22 -0
- package/src/cli/commands/db/rollback.js +15 -0
- package/src/cli/commands/db/schema/dump.js +12 -0
- package/src/cli/commands/db/schema/load.js +12 -0
- package/src/cli/commands/db/seed.js +12 -0
- package/src/cli/commands/db/tenants/check.js +38 -0
- package/src/cli/commands/db/tenants/create.js +33 -0
- package/src/cli/commands/db/tenants/migrate.js +49 -0
- package/src/cli/commands/destroy/migration.js +7 -0
- package/src/cli/commands/generate/base-models.js +7 -0
- package/src/cli/commands/generate/frontend-models.js +12 -0
- package/src/cli/commands/generate/migration.js +7 -0
- package/src/cli/commands/generate/model.js +7 -0
- package/src/cli/commands/init.js +11 -0
- package/src/cli/commands/routes.js +7 -0
- package/src/cli/commands/run-script.js +12 -0
- package/src/cli/commands/runner.js +12 -0
- package/src/cli/commands/server.js +7 -0
- package/src/cli/commands/test.js +9 -0
- package/src/cli/index.js +152 -0
- package/src/cli/tenant-database-command-helper.js +198 -0
- package/src/cli/use-browser-cli.js +30 -0
- package/src/configuration-resolver.js +65 -0
- package/src/configuration-types.js +429 -0
- package/src/configuration.js +2590 -0
- package/src/controller.js +421 -0
- package/src/current-configuration.js +31 -0
- package/src/current.js +80 -0
- package/src/database/annotations-async-hooks.js +47 -0
- package/src/database/annotations.js +40 -0
- package/src/database/drivers/base-column.js +182 -0
- package/src/database/drivers/base-columns-index.js +81 -0
- package/src/database/drivers/base-foreign-key.js +104 -0
- package/src/database/drivers/base-table.js +156 -0
- package/src/database/drivers/base.js +1609 -0
- package/src/database/drivers/mssql/column.js +74 -0
- package/src/database/drivers/mssql/columns-index.js +6 -0
- package/src/database/drivers/mssql/connect-connection.js +16 -0
- package/src/database/drivers/mssql/foreign-key.js +12 -0
- package/src/database/drivers/mssql/index.js +590 -0
- package/src/database/drivers/mssql/options.js +79 -0
- package/src/database/drivers/mssql/query-parser.js +6 -0
- package/src/database/drivers/mssql/sql/alter-table.js +4 -0
- package/src/database/drivers/mssql/sql/create-database.js +36 -0
- package/src/database/drivers/mssql/sql/create-index.js +4 -0
- package/src/database/drivers/mssql/sql/create-table.js +4 -0
- package/src/database/drivers/mssql/sql/delete.js +19 -0
- package/src/database/drivers/mssql/sql/drop-database.js +36 -0
- package/src/database/drivers/mssql/sql/drop-table.js +4 -0
- package/src/database/drivers/mssql/sql/insert.js +4 -0
- package/src/database/drivers/mssql/sql/update.js +31 -0
- package/src/database/drivers/mssql/sql/upsert.js +23 -0
- package/src/database/drivers/mssql/structure-sql.js +120 -0
- package/src/database/drivers/mssql/table.js +145 -0
- package/src/database/drivers/mysql/column.js +112 -0
- package/src/database/drivers/mysql/columns-index.js +22 -0
- package/src/database/drivers/mysql/foreign-key.js +12 -0
- package/src/database/drivers/mysql/index.js +473 -0
- package/src/database/drivers/mysql/options.js +34 -0
- package/src/database/drivers/mysql/query-parser.js +6 -0
- package/src/database/drivers/mysql/query.js +37 -0
- package/src/database/drivers/mysql/sql/alter-table.js +6 -0
- package/src/database/drivers/mysql/sql/create-database.js +39 -0
- package/src/database/drivers/mysql/sql/create-index.js +6 -0
- package/src/database/drivers/mysql/sql/create-table.js +6 -0
- package/src/database/drivers/mysql/sql/delete.js +21 -0
- package/src/database/drivers/mysql/sql/drop-database.js +6 -0
- package/src/database/drivers/mysql/sql/drop-table.js +6 -0
- package/src/database/drivers/mysql/sql/insert.js +6 -0
- package/src/database/drivers/mysql/sql/update.js +33 -0
- package/src/database/drivers/mysql/sql/upsert.js +13 -0
- package/src/database/drivers/mysql/structure-sql.js +93 -0
- package/src/database/drivers/mysql/table.js +121 -0
- package/src/database/drivers/pgsql/column.js +90 -0
- package/src/database/drivers/pgsql/columns-index.js +6 -0
- package/src/database/drivers/pgsql/foreign-key.js +12 -0
- package/src/database/drivers/pgsql/index.js +441 -0
- package/src/database/drivers/pgsql/options.js +32 -0
- package/src/database/drivers/pgsql/query-parser.js +6 -0
- package/src/database/drivers/pgsql/sql/alter-table.js +6 -0
- package/src/database/drivers/pgsql/sql/create-database.js +38 -0
- package/src/database/drivers/pgsql/sql/create-index.js +6 -0
- package/src/database/drivers/pgsql/sql/create-table.js +6 -0
- package/src/database/drivers/pgsql/sql/delete.js +21 -0
- package/src/database/drivers/pgsql/sql/drop-database.js +6 -0
- package/src/database/drivers/pgsql/sql/drop-table.js +6 -0
- package/src/database/drivers/pgsql/sql/insert.js +6 -0
- package/src/database/drivers/pgsql/sql/update.js +33 -0
- package/src/database/drivers/pgsql/sql/upsert.js +14 -0
- package/src/database/drivers/pgsql/structure-sql.js +126 -0
- package/src/database/drivers/pgsql/table.js +135 -0
- package/src/database/drivers/sqlite/base.js +509 -0
- package/src/database/drivers/sqlite/column.js +75 -0
- package/src/database/drivers/sqlite/columns-index.js +30 -0
- package/src/database/drivers/sqlite/connection-sql-js.js +46 -0
- package/src/database/drivers/sqlite/foreign-key.js +24 -0
- package/src/database/drivers/sqlite/index.js +394 -0
- package/src/database/drivers/sqlite/index.native.js +72 -0
- package/src/database/drivers/sqlite/index.web.js +99 -0
- package/src/database/drivers/sqlite/options.js +32 -0
- package/src/database/drivers/sqlite/query-parser.js +6 -0
- package/src/database/drivers/sqlite/query.js +35 -0
- package/src/database/drivers/sqlite/query.native.js +35 -0
- package/src/database/drivers/sqlite/query.web.js +49 -0
- package/src/database/drivers/sqlite/sql/alter-table.js +187 -0
- package/src/database/drivers/sqlite/sql/create-index.js +6 -0
- package/src/database/drivers/sqlite/sql/create-table.js +6 -0
- package/src/database/drivers/sqlite/sql/delete.js +26 -0
- package/src/database/drivers/sqlite/sql/drop-table.js +6 -0
- package/src/database/drivers/sqlite/sql/insert.js +6 -0
- package/src/database/drivers/sqlite/sql/update.js +33 -0
- package/src/database/drivers/sqlite/sql/upsert.js +14 -0
- package/src/database/drivers/sqlite/structure-sql.js +56 -0
- package/src/database/drivers/sqlite/table-rebuilder.js +96 -0
- package/src/database/drivers/sqlite/table.js +131 -0
- package/src/database/drivers/structure-sql/utils.js +35 -0
- package/src/database/handler.js +13 -0
- package/src/database/initializer-from-require-context.js +101 -0
- package/src/database/migration/index.js +438 -0
- package/src/database/migrator/files-finder.js +55 -0
- package/src/database/migrator/types.js +31 -0
- package/src/database/migrator.js +557 -0
- package/src/database/pool/async-tracked-multi-connection.js +1164 -0
- package/src/database/pool/base-methods-forward.js +52 -0
- package/src/database/pool/base.js +380 -0
- package/src/database/pool/single-multi-use.js +118 -0
- package/src/database/query/alter-table-base.js +104 -0
- package/src/database/query/base.js +49 -0
- package/src/database/query/create-database-base.js +42 -0
- package/src/database/query/create-index-base.js +117 -0
- package/src/database/query/create-table-base.js +205 -0
- package/src/database/query/delete-base.js +19 -0
- package/src/database/query/drop-database-base.js +38 -0
- package/src/database/query/drop-table-base.js +58 -0
- package/src/database/query/from-base.js +36 -0
- package/src/database/query/from-plain.js +16 -0
- package/src/database/query/from-table.js +18 -0
- package/src/database/query/index.js +533 -0
- package/src/database/query/insert-base.js +172 -0
- package/src/database/query/join-base.js +43 -0
- package/src/database/query/join-object.js +167 -0
- package/src/database/query/join-plain.js +18 -0
- package/src/database/query/join-tracker.js +93 -0
- package/src/database/query/model-class-query.js +1577 -0
- package/src/database/query/order-base.js +33 -0
- package/src/database/query/order-column.js +77 -0
- package/src/database/query/order-plain.js +28 -0
- package/src/database/query/preloader/belongs-to.js +267 -0
- package/src/database/query/preloader/ensure-model-class-initialized.js +18 -0
- package/src/database/query/preloader/has-many.js +316 -0
- package/src/database/query/preloader/has-one.js +123 -0
- package/src/database/query/preloader/selection.js +152 -0
- package/src/database/query/preloader.js +201 -0
- package/src/database/query/query-data.js +305 -0
- package/src/database/query/select-base.js +30 -0
- package/src/database/query/select-plain.js +18 -0
- package/src/database/query/select-table-and-column.js +28 -0
- package/src/database/query/update-base.js +41 -0
- package/src/database/query/upsert-base.js +103 -0
- package/src/database/query/where-base.js +38 -0
- package/src/database/query/where-combinator.js +31 -0
- package/src/database/query/where-hash.js +77 -0
- package/src/database/query/where-model-class-hash.js +505 -0
- package/src/database/query/where-not.js +23 -0
- package/src/database/query/where-plain.js +20 -0
- package/src/database/query/with-count.js +219 -0
- package/src/database/query-parser/base-query-parser.js +40 -0
- package/src/database/query-parser/from-parser.js +49 -0
- package/src/database/query-parser/group-parser.js +55 -0
- package/src/database/query-parser/joins-parser.js +37 -0
- package/src/database/query-parser/limit-parser.js +77 -0
- package/src/database/query-parser/options.js +94 -0
- package/src/database/query-parser/order-parser.js +45 -0
- package/src/database/query-parser/select-parser.js +67 -0
- package/src/database/query-parser/where-parser.js +46 -0
- package/src/database/record/acts-as-list.js +374 -0
- package/src/database/record/attachments/download.js +49 -0
- package/src/database/record/attachments/handle.js +188 -0
- package/src/database/record/attachments/normalize-input.js +213 -0
- package/src/database/record/attachments/storage-drivers/filesystem.js +114 -0
- package/src/database/record/attachments/storage-drivers/native.js +146 -0
- package/src/database/record/attachments/storage-drivers/s3.js +245 -0
- package/src/database/record/attachments/store.js +591 -0
- package/src/database/record/index.js +4094 -0
- package/src/database/record/instance-relationships/base.js +289 -0
- package/src/database/record/instance-relationships/belongs-to.js +84 -0
- package/src/database/record/instance-relationships/has-many.js +284 -0
- package/src/database/record/instance-relationships/has-one.js +117 -0
- package/src/database/record/record-not-found-error.js +3 -0
- package/src/database/record/relationships/base.js +195 -0
- package/src/database/record/relationships/belongs-to.js +57 -0
- package/src/database/record/relationships/has-many.js +46 -0
- package/src/database/record/relationships/has-one.js +46 -0
- package/src/database/record/state-machine.js +278 -0
- package/src/database/record/user-module.js +43 -0
- package/src/database/record/validators/base.js +27 -0
- package/src/database/record/validators/format.js +50 -0
- package/src/database/record/validators/presence.js +24 -0
- package/src/database/record/validators/uniqueness.js +124 -0
- package/src/database/table-data/index.js +241 -0
- package/src/database/table-data/table-column.js +416 -0
- package/src/database/table-data/table-foreign-key.js +69 -0
- package/src/database/table-data/table-index.js +46 -0
- package/src/database/table-data/table-reference.js +13 -0
- package/src/database/use-database.js +48 -0
- package/src/environment-handlers/base.js +561 -0
- package/src/environment-handlers/browser.js +338 -0
- package/src/environment-handlers/node/cli/commands/background-jobs-main.js +21 -0
- package/src/environment-handlers/node/cli/commands/background-jobs-runner.js +24 -0
- package/src/environment-handlers/node/cli/commands/background-jobs-worker.js +47 -0
- package/src/environment-handlers/node/cli/commands/beacon.js +21 -0
- package/src/environment-handlers/node/cli/commands/cli-command-context.js +31 -0
- package/src/environment-handlers/node/cli/commands/console.js +149 -0
- package/src/environment-handlers/node/cli/commands/db/schema/dump.js +43 -0
- package/src/environment-handlers/node/cli/commands/db/schema/load.js +69 -0
- package/src/environment-handlers/node/cli/commands/db/seed.js +79 -0
- package/src/environment-handlers/node/cli/commands/destroy/migration.js +47 -0
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +396 -0
- package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +872 -0
- package/src/environment-handlers/node/cli/commands/generate/migration.js +45 -0
- package/src/environment-handlers/node/cli/commands/generate/model.js +45 -0
- package/src/environment-handlers/node/cli/commands/init.js +68 -0
- package/src/environment-handlers/node/cli/commands/routes.js +63 -0
- package/src/environment-handlers/node/cli/commands/run-script.js +85 -0
- package/src/environment-handlers/node/cli/commands/runner.js +84 -0
- package/src/environment-handlers/node/cli/commands/server.js +151 -0
- package/src/environment-handlers/node/cli/commands/test.js +118 -0
- package/src/environment-handlers/node.js +887 -0
- package/src/error-logger.js +30 -0
- package/src/frontend-model-controller.js +3491 -0
- package/src/frontend-model-resource/base-resource.js +935 -0
- package/src/frontend-models/base.js +4004 -0
- package/src/frontend-models/clear-pending-debounced-callback.js +16 -0
- package/src/frontend-models/event-hook-models.js +49 -0
- package/src/frontend-models/model-registry.js +28 -0
- package/src/frontend-models/outgoing-event-buffer.js +51 -0
- package/src/frontend-models/preloader.js +169 -0
- package/src/frontend-models/query.js +2245 -0
- package/src/frontend-models/resource-config-validation.js +56 -0
- package/src/frontend-models/resource-definition.js +399 -0
- package/src/frontend-models/transport-serialization.js +369 -0
- package/src/frontend-models/use-created-event.js +21 -0
- package/src/frontend-models/use-destroyed-event.js +148 -0
- package/src/frontend-models/use-model-class-event.js +164 -0
- package/src/frontend-models/use-updated-event.js +152 -0
- package/src/frontend-models/websocket-channel.js +494 -0
- package/src/frontend-models/websocket-publishers.js +224 -0
- package/src/http-client/header.js +17 -0
- package/src/http-client/index.js +139 -0
- package/src/http-client/request.js +94 -0
- package/src/http-client/response.js +151 -0
- package/src/http-client/websocket-client.js +27 -0
- package/src/http-server/client/index.js +507 -0
- package/src/http-server/client/params-to-object.js +152 -0
- package/src/http-server/client/request-buffer/form-data-part.js +139 -0
- package/src/http-server/client/request-buffer/header.js +19 -0
- package/src/http-server/client/request-buffer/index.js +535 -0
- package/src/http-server/client/request-parser.js +195 -0
- package/src/http-server/client/request-runner.js +321 -0
- package/src/http-server/client/request-timing.js +171 -0
- package/src/http-server/client/request.js +114 -0
- package/src/http-server/client/response.js +251 -0
- package/src/http-server/client/uploaded-file/memory-uploaded-file.js +32 -0
- package/src/http-server/client/uploaded-file/temporary-uploaded-file.js +32 -0
- package/src/http-server/client/uploaded-file/uploaded-file.js +36 -0
- package/src/http-server/client/websocket-request.js +147 -0
- package/src/http-server/client/websocket-session.js +1755 -0
- package/src/http-server/cookie.js +245 -0
- package/src/http-server/development-reloader.js +240 -0
- package/src/http-server/index.js +561 -0
- package/src/http-server/remote-address.js +77 -0
- package/src/http-server/server-client.js +222 -0
- package/src/http-server/server-lock.js +178 -0
- package/src/http-server/websocket-channel-subscribers.js +110 -0
- package/src/http-server/websocket-channel.js +137 -0
- package/src/http-server/websocket-connection.js +118 -0
- package/src/http-server/websocket-event-log-store.js +433 -0
- package/src/http-server/websocket-events-host.js +170 -0
- package/src/http-server/websocket-events.js +50 -0
- package/src/http-server/worker-handler/channel-subscriber-dispatch.js +28 -0
- package/src/http-server/worker-handler/in-process.js +155 -0
- package/src/http-server/worker-handler/index.js +370 -0
- package/src/http-server/worker-handler/worker-script.js +6 -0
- package/src/http-server/worker-handler/worker-thread.js +286 -0
- package/src/initializer.js +39 -0
- package/src/jobs/.gitkeep +1 -0
- package/src/jobs/mail-delivery.js +22 -0
- package/src/logger/base-logger.js +34 -0
- package/src/logger/console-logger.js +28 -0
- package/src/logger/file-logger.js +36 -0
- package/src/logger/outputs/array-output.js +50 -0
- package/src/logger/outputs/console-output.js +32 -0
- package/src/logger/outputs/file-output.js +55 -0
- package/src/logger/outputs/stdout-output.js +64 -0
- package/src/logger.js +507 -0
- package/src/mailer/backends/smtp.js +197 -0
- package/src/mailer/base.js +337 -0
- package/src/mailer/delivery.js +70 -0
- package/src/mailer/index.js +24 -0
- package/src/mailer.js +15 -0
- package/src/plugins/sqljs-wasm-route-controller.js +70 -0
- package/src/plugins/sqljs-wasm-route.js +71 -0
- package/src/record-payload-values.js +83 -0
- package/src/routes/app-routes.js +17 -0
- package/src/routes/base-route.js +133 -0
- package/src/routes/basic-route.js +109 -0
- package/src/routes/built-in/debug/controller.js +12 -0
- package/src/routes/built-in/errors/controller.js +7 -0
- package/src/routes/built-in/errors/not-found.ejs +1 -0
- package/src/routes/get-route.js +75 -0
- package/src/routes/hooks/frontend-model-command-route-hook.js +100 -0
- package/src/routes/index.js +50 -0
- package/src/routes/namespace-route.js +51 -0
- package/src/routes/plugin-routes.js +141 -0
- package/src/routes/post-route.js +74 -0
- package/src/routes/resolver.js +535 -0
- package/src/routes/resource-route.js +154 -0
- package/src/routes/root-route.js +11 -0
- package/src/templates/configuration.js +61 -0
- package/src/templates/generate-migration.js +11 -0
- package/src/templates/generate-model.js +6 -0
- package/src/templates/routes.js +11 -0
- package/src/testing/base-expect.js +17 -0
- package/src/testing/browser-frontend-model-event-hook-scenarios.js +520 -0
- package/src/testing/browser-test-app.js +32 -0
- package/src/testing/expect-to-change.js +55 -0
- package/src/testing/expect-utils.js +269 -0
- package/src/testing/expect.js +763 -0
- package/src/testing/request-client.js +90 -0
- package/src/testing/test-files-finder.js +364 -0
- package/src/testing/test-filter-parser.js +198 -0
- package/src/testing/test-runner.js +1168 -0
- package/src/testing/test-suite-splitter.js +177 -0
- package/src/testing/test.js +370 -0
- package/src/types/external-modules.d.ts +57 -0
- package/src/utils/backtrace-cleaner-node.js +87 -0
- package/src/utils/backtrace-cleaner.js +266 -0
- package/src/utils/ensure-error.js +15 -0
- package/src/utils/event-emitter.js +8 -0
- package/src/utils/file-exists.js +18 -0
- package/src/utils/format-value.js +101 -0
- package/src/utils/model-scope.js +56 -0
- package/src/utils/nest-callbacks.js +22 -0
- package/src/utils/plain-object.js +14 -0
- package/src/utils/ransack.js +859 -0
- package/src/utils/rest-args-error.js +14 -0
- package/src/utils/singularize-model-name.js +18 -0
- package/src/utils/split-sql-statements.js +88 -0
- package/src/utils/to-import-specifier.js +53 -0
- package/src/utils/with-tracked-stack-async-hooks.js +103 -0
- package/src/utils/with-tracked-stack.js +38 -0
- package/src/velocious-error.js +34 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {digg} from "diggerize"
|
|
4
|
+
import * as inflection from "inflection"
|
|
5
|
+
import Logger from "../logger.js"
|
|
6
|
+
import {NotImplementedError} from "./migration/index.js"
|
|
7
|
+
import restArgsError from "../utils/rest-args-error.js"
|
|
8
|
+
import TableData from "./table-data/index.js"
|
|
9
|
+
|
|
10
|
+
export default class VelociousDatabaseMigrator {
|
|
11
|
+
/**
|
|
12
|
+
* Migrations versions.
|
|
13
|
+
@type {Record<string, Record<string, boolean>>} */
|
|
14
|
+
migrationsVersions = {}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Runs constructor.
|
|
18
|
+
* @param {object} args - Options object.
|
|
19
|
+
* @param {import("../configuration.js").default} args.configuration - Configuration instance.
|
|
20
|
+
* @param {string[]} [args.databaseIdentifiers] - Optional database identifiers to migrate.
|
|
21
|
+
*/
|
|
22
|
+
constructor({configuration, databaseIdentifiers, ...restArgs}) {
|
|
23
|
+
restArgsError(restArgs)
|
|
24
|
+
|
|
25
|
+
if (!configuration) throw new Error("configuration argument is required")
|
|
26
|
+
|
|
27
|
+
this.configuration = configuration
|
|
28
|
+
this.databaseIdentifiers = databaseIdentifiers
|
|
29
|
+
this.logger = new Logger(this)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Runs handles database identifier.
|
|
34
|
+
* @param {string} dbIdentifier - Database identifier.
|
|
35
|
+
* @returns {boolean} - Whether this migrator should touch the database identifier.
|
|
36
|
+
*/
|
|
37
|
+
handlesDatabaseIdentifier(dbIdentifier) {
|
|
38
|
+
if (!this.databaseIdentifiers) return true
|
|
39
|
+
|
|
40
|
+
return this.databaseIdentifiers.includes(dbIdentifier)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Runs prepare.
|
|
46
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
47
|
+
*/
|
|
48
|
+
async prepare() {
|
|
49
|
+
await this.createMigrationsTable()
|
|
50
|
+
await this.loadMigrationsVersions()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Runs create migrations table.
|
|
55
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
56
|
+
*/
|
|
57
|
+
async createMigrationsTable() {
|
|
58
|
+
const dbs = await this.configuration.getCurrentConnections()
|
|
59
|
+
|
|
60
|
+
for (const dbIdentifier in dbs) {
|
|
61
|
+
if (!this.handlesDatabaseIdentifier(dbIdentifier)) continue
|
|
62
|
+
|
|
63
|
+
await this.createMigrationsTableForDatabase({dbIdentifier, db: dbs[dbIdentifier]})
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Runs create migrations table for database.
|
|
69
|
+
* @param {object} args - Options object.
|
|
70
|
+
* @param {string} args.dbIdentifier - Database identifier.
|
|
71
|
+
* @param {import("./drivers/base.js").default} args.db - Database connection.
|
|
72
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
73
|
+
*/
|
|
74
|
+
async createMigrationsTableForDatabase({dbIdentifier, db}) {
|
|
75
|
+
const databaseConfiguration = this.configuration.getDatabaseIdentifier(dbIdentifier)
|
|
76
|
+
|
|
77
|
+
if (!databaseConfiguration.migrations) {
|
|
78
|
+
this.logger.debug(`${dbIdentifier} isn't configured for migrations - skipping creating migrations table for it`)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exists = await this.migrationsTableExist(db)
|
|
83
|
+
|
|
84
|
+
if (exists) {
|
|
85
|
+
this.logger.debug(`${dbIdentifier} migrations table already exists - skipping`)
|
|
86
|
+
} else {
|
|
87
|
+
this.logger.debug("New TableData for schema_migrations")
|
|
88
|
+
const schemaMigrationsTable = new TableData("schema_migrations", {ifNotExists: true})
|
|
89
|
+
|
|
90
|
+
schemaMigrationsTable.string("version", {null: false, primaryKey: true})
|
|
91
|
+
|
|
92
|
+
const createSchemaMigrationsTableSqls = await db.createTableSql(schemaMigrationsTable)
|
|
93
|
+
|
|
94
|
+
for (const createSchemaMigrationsTableSql of createSchemaMigrationsTableSqls) {
|
|
95
|
+
this.logger.debug(`Creating migrations table with SQL`, createSchemaMigrationsTableSql)
|
|
96
|
+
await db.query(createSchemaMigrationsTableSql)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Runs has run migration version.
|
|
103
|
+
* @param {string} dbIdentifier - Db identifier.
|
|
104
|
+
* @param {number} version - Version.
|
|
105
|
+
* @returns {boolean} - Whether it has run migration version.
|
|
106
|
+
*/
|
|
107
|
+
hasRunMigrationVersion(dbIdentifier, version) {
|
|
108
|
+
if (!this.migrationsVersions) throw new Error("Migrations versions hasn't been loaded yet")
|
|
109
|
+
if (!this.migrationsVersions[dbIdentifier]) throw new Error(`Migrations versions hasn't been loaded yet for db: ${dbIdentifier}`)
|
|
110
|
+
|
|
111
|
+
if (version in this.migrationsVersions[dbIdentifier]) {
|
|
112
|
+
return true
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Runs migrate files.
|
|
120
|
+
* @param {import("./migrator/types.js").MigrationObjectType[]} files - Files.
|
|
121
|
+
* @param {import("./migrator/types.js").ImportFullpathCallbackType} importCallback - Import callback.
|
|
122
|
+
* @returns {Promise<number>} - Number of migrations actually applied (not skipped as already-run).
|
|
123
|
+
*/
|
|
124
|
+
async migrateFiles(files, importCallback) {
|
|
125
|
+
let appliedCount = 0
|
|
126
|
+
|
|
127
|
+
await this.configuration.ensureConnections({name: "Database migrator: migrate files"}, async () => {
|
|
128
|
+
for (const migration of files) {
|
|
129
|
+
const applied = await this.runMigrationFile({
|
|
130
|
+
migration,
|
|
131
|
+
requireMigration: async () => {
|
|
132
|
+
if (!migration.fullPath) throw new Error(`Migration didn't have a fullPath key: ${Object.keys(migration).join(", ")}`)
|
|
133
|
+
|
|
134
|
+
const migrationImport = await importCallback(migration.fullPath)
|
|
135
|
+
|
|
136
|
+
if (!migrationImport) {
|
|
137
|
+
throw new Error(`Migration file must export migration class: ${migration.fullPath}`)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return migrationImport
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
if (applied) appliedCount++
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await this._afterMigrations()
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
return appliedCount
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Runs migrate files from require context.
|
|
155
|
+
* @param {import("./migrator/types.js").RequireMigrationContextType} requireContext - Require context.
|
|
156
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
157
|
+
*/
|
|
158
|
+
async migrateFilesFromRequireContext(requireContext) {
|
|
159
|
+
/**
|
|
160
|
+
* Files.
|
|
161
|
+
@type {import("./migrator/types.js").MigrationObjectType[]} */
|
|
162
|
+
let files = []
|
|
163
|
+
|
|
164
|
+
for (const file of requireContext.keys()) {
|
|
165
|
+
// "13,14" because somes "require-context"-npm-module deletes first character!?
|
|
166
|
+
const match = file.match(/(\d{13,14})-(.+)\.js$/)
|
|
167
|
+
|
|
168
|
+
if (!match) continue
|
|
169
|
+
|
|
170
|
+
// Fix require-context-npm-module deletes first character
|
|
171
|
+
let fileName = file
|
|
172
|
+
let dateNumber = match[1]
|
|
173
|
+
|
|
174
|
+
if (dateNumber.length == 13) {
|
|
175
|
+
dateNumber = `2${dateNumber}`
|
|
176
|
+
fileName = `2${fileName}`
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Parse regex
|
|
180
|
+
const date = parseInt(dateNumber)
|
|
181
|
+
const migrationName = match[2]
|
|
182
|
+
const migrationClassName = inflection.camelize(migrationName.replaceAll("-", "_"))
|
|
183
|
+
|
|
184
|
+
files.push({
|
|
185
|
+
file: fileName,
|
|
186
|
+
date,
|
|
187
|
+
migrationClassName
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
files = files.sort((migration1, migration2) => migration1.date - migration2.date)
|
|
192
|
+
|
|
193
|
+
await this.configuration.ensureConnections({name: "Database migrator: migrate require-context files"}, async () => {
|
|
194
|
+
for (const migration of files) {
|
|
195
|
+
await this.runMigrationFile({
|
|
196
|
+
migration,
|
|
197
|
+
requireMigration: async () => requireContext(migration.file).default
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
await this._afterMigrations()
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Runs after migrations.
|
|
207
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
208
|
+
*/
|
|
209
|
+
async _afterMigrations() {
|
|
210
|
+
const environmentHandler = this.configuration.getEnvironmentHandler()
|
|
211
|
+
const dbs = await this.configuration.getCurrentConnections()
|
|
212
|
+
const filteredDbs = Object.fromEntries(
|
|
213
|
+
Object.entries(dbs).filter(([dbIdentifier]) => this.handlesDatabaseIdentifier(dbIdentifier))
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
if (!environmentHandler || Object.keys(filteredDbs).length == 0) return
|
|
217
|
+
|
|
218
|
+
await environmentHandler.afterMigrations({dbs: filteredDbs})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Runs load migrations versions.
|
|
223
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
224
|
+
*/
|
|
225
|
+
async loadMigrationsVersions() {
|
|
226
|
+
this.migrationsVersions = {}
|
|
227
|
+
|
|
228
|
+
const dbs = await this.configuration.getCurrentConnections()
|
|
229
|
+
|
|
230
|
+
for (const dbIdentifier in dbs) {
|
|
231
|
+
if (!this.handlesDatabaseIdentifier(dbIdentifier)) continue
|
|
232
|
+
|
|
233
|
+
await this.loadMigrationsVersionsForDatabase({dbIdentifier, db: dbs[dbIdentifier]})
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Runs load migrations versions for database.
|
|
239
|
+
* @param {object} args - Options object.
|
|
240
|
+
* @param {string} args.dbIdentifier - Database identifier.
|
|
241
|
+
* @param {import("./drivers/base.js").default} args.db - Database connection.
|
|
242
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
243
|
+
*/
|
|
244
|
+
async loadMigrationsVersionsForDatabase({dbIdentifier, db}) {
|
|
245
|
+
const databaseConfiguration = this.configuration.getDatabaseIdentifier(dbIdentifier)
|
|
246
|
+
|
|
247
|
+
if (!databaseConfiguration.migrations) {
|
|
248
|
+
this.logger.debug(`${dbIdentifier} isn't configured for migrations - skipping loading migrations versions for it`)
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!await this.migrationsTableExist(db)) {
|
|
253
|
+
this.logger.info(`Migration table does not exist for ${dbIdentifier} - skipping loading migrations versions for it`)
|
|
254
|
+
delete this.migrationsVersions[dbIdentifier]
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const rows = await db.select("schema_migrations")
|
|
259
|
+
|
|
260
|
+
this.migrationsVersions[dbIdentifier] = {}
|
|
261
|
+
|
|
262
|
+
for (const row of rows) {
|
|
263
|
+
const version = digg(row, "version")
|
|
264
|
+
|
|
265
|
+
this.migrationsVersions[dbIdentifier][version] = true
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Runs migrations table exist.
|
|
271
|
+
* @param {import("./drivers/base.js").default} db - Database connection.
|
|
272
|
+
* @returns {Promise<boolean>} - Resolves with Whether migrations table exist.
|
|
273
|
+
*/
|
|
274
|
+
async migrationsTableExist(db) {
|
|
275
|
+
const schemaTable = await db.getTableByName("schema_migrations", {throwError: false})
|
|
276
|
+
|
|
277
|
+
if (!schemaTable) return false
|
|
278
|
+
|
|
279
|
+
return true
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Runs execute require context.
|
|
284
|
+
* @param {import("./migrator/types.js").RequireMigrationContextType} requireContext - Require context.
|
|
285
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
286
|
+
*/
|
|
287
|
+
async executeRequireContext(requireContext) {
|
|
288
|
+
const migrationFiles = requireContext.keys()
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Files.
|
|
292
|
+
@type {import("./migrator/types.js").MigrationObjectType[]} */
|
|
293
|
+
let files = []
|
|
294
|
+
|
|
295
|
+
for (const file of migrationFiles) {
|
|
296
|
+
const match = file.match(/^(\d{14})-(.+)\.js$/)
|
|
297
|
+
|
|
298
|
+
if (!match) continue
|
|
299
|
+
|
|
300
|
+
const date = parseInt(match[1])
|
|
301
|
+
const migrationName = match[2]
|
|
302
|
+
const migrationClassName = inflection.camelize(migrationName)
|
|
303
|
+
|
|
304
|
+
const migrationObject = /**
|
|
305
|
+
* Narrows the runtime value to the documented type.
|
|
306
|
+
@type {import("./migrator/types.js").MigrationObjectType} */ ({
|
|
307
|
+
file,
|
|
308
|
+
date,
|
|
309
|
+
migrationClassName
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
files.push(migrationObject)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
files = files.sort((migration1, migration2) => migration1.date - migration2.date)
|
|
316
|
+
|
|
317
|
+
for (const migration of files) {
|
|
318
|
+
await this.runMigrationFile({
|
|
319
|
+
migration,
|
|
320
|
+
requireMigration: async () => requireContext(migration.file).default
|
|
321
|
+
})
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Runs reset.
|
|
327
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
328
|
+
*/
|
|
329
|
+
async reset() {
|
|
330
|
+
const dbs = await this.configuration.getCurrentConnections()
|
|
331
|
+
|
|
332
|
+
for (const dbIdentifier in dbs) {
|
|
333
|
+
if (!this.handlesDatabaseIdentifier(dbIdentifier)) continue
|
|
334
|
+
|
|
335
|
+
const db = dbs[dbIdentifier]
|
|
336
|
+
|
|
337
|
+
await db.withDisabledForeignKeys(async () => {
|
|
338
|
+
while (true) {
|
|
339
|
+
const errors = []
|
|
340
|
+
let anyTableDropped = false
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
for (const table of await db.getTables()) {
|
|
344
|
+
this.logger.info(`Dropping table ${table.getName()}`)
|
|
345
|
+
|
|
346
|
+
try {
|
|
347
|
+
await db.dropTable(table.getName(), {cascade: true})
|
|
348
|
+
anyTableDropped = true
|
|
349
|
+
} catch (error) {
|
|
350
|
+
errors.push(error)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
break
|
|
355
|
+
} catch (error) { // eslint-disable-line no-unused-vars
|
|
356
|
+
if (errors.length > 0 && anyTableDropped) {
|
|
357
|
+
// Retry
|
|
358
|
+
} else {
|
|
359
|
+
throw errors[0]
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Runs rollback.
|
|
369
|
+
* @param {import("./migrator/types.js").MigrationObjectType[]} files - Files.
|
|
370
|
+
* @param {import("./migrator/types.js").ImportFullpathCallbackType} importCallback Function to import a file
|
|
371
|
+
* @returns {Promise<void>} - Resolves when complete.
|
|
372
|
+
*/
|
|
373
|
+
async rollback(files, importCallback) {
|
|
374
|
+
const latestMigrationVersion = await this._latestMigrationVersion()
|
|
375
|
+
|
|
376
|
+
if (!latestMigrationVersion) {
|
|
377
|
+
throw new Error("No migrations have been run yet")
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const latestMigrationVersionNumber = parseInt(latestMigrationVersion)
|
|
381
|
+
const migration = files.find((file) => file.date == latestMigrationVersionNumber)
|
|
382
|
+
|
|
383
|
+
if (!migration) {
|
|
384
|
+
throw new Error(`Migration file for version ${latestMigrationVersionNumber} not found`)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
await this.runMigrationFile({
|
|
388
|
+
migration,
|
|
389
|
+
requireMigration: async () => {
|
|
390
|
+
if (!migration.fullPath) throw new Error(`Migration didn't have a fullPath key: ${Object.keys(migration).join(", ")}`)
|
|
391
|
+
|
|
392
|
+
return await importCallback(migration.fullPath)
|
|
393
|
+
},
|
|
394
|
+
direction: "down"
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Runs latest migration version.
|
|
400
|
+
* @returns {Promise<string | undefined>} The latest migration version
|
|
401
|
+
*/
|
|
402
|
+
async _latestMigrationVersion() {
|
|
403
|
+
if (!this.migrationsVersions) await this.loadMigrationsVersions()
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Defines highestVersion.
|
|
407
|
+
@type {string | undefined} */
|
|
408
|
+
let highestVersion
|
|
409
|
+
|
|
410
|
+
for (const dbIdentifier in this.migrationsVersions) {
|
|
411
|
+
for (const migrationVersion in this.migrationsVersions[dbIdentifier]) {
|
|
412
|
+
if (!highestVersion || migrationVersion > highestVersion) {
|
|
413
|
+
highestVersion = migrationVersion
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return highestVersion
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Runs run migration file.
|
|
423
|
+
* @param {object} args - Options object.
|
|
424
|
+
* @param {import("./migrator/types.js").MigrationObjectType} args.migration - Migration.
|
|
425
|
+
* @param {import("./migrator/types.js").RequireMigrationType} args.requireMigration - Require migration.
|
|
426
|
+
* @param {string} [args.direction] - Direction.
|
|
427
|
+
* @returns {Promise<boolean>} - Whether the migration ran on at least one database (false if skipped as already-run everywhere).
|
|
428
|
+
*/
|
|
429
|
+
async runMigrationFile({migration, requireMigration, direction = "up"}) {
|
|
430
|
+
if (!this.configuration) throw new Error("No configuration set")
|
|
431
|
+
if (!this.configuration.isDatabasePoolInitialized()) await this.configuration.initializeDatabasePool()
|
|
432
|
+
if (!this.migrationsVersions) await this.loadMigrationsVersions()
|
|
433
|
+
|
|
434
|
+
let applied = false
|
|
435
|
+
const dbs = await this.configuration.getCurrentConnections()
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Db identifiers needing migration versions.
|
|
439
|
+
@type {string[]} */
|
|
440
|
+
const dbIdentifiersNeedingMigrationVersions = []
|
|
441
|
+
|
|
442
|
+
// migrateFiles() wraps execution in ensureConnections(), so the current
|
|
443
|
+
// async context can expose DB identifiers not loaded by prepare().
|
|
444
|
+
for (const dbIdentifier in dbs) {
|
|
445
|
+
if (!this.handlesDatabaseIdentifier(dbIdentifier)) continue
|
|
446
|
+
|
|
447
|
+
const databaseConfiguration = this.configuration.getDatabaseIdentifier(dbIdentifier)
|
|
448
|
+
|
|
449
|
+
if (!databaseConfiguration.migrations) continue
|
|
450
|
+
if (this.migrationsVersions[dbIdentifier]) continue
|
|
451
|
+
|
|
452
|
+
dbIdentifiersNeedingMigrationVersions.push(dbIdentifier)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
for (const dbIdentifier of dbIdentifiersNeedingMigrationVersions) {
|
|
456
|
+
const db = dbs[dbIdentifier]
|
|
457
|
+
|
|
458
|
+
await this.createMigrationsTableForDatabase({dbIdentifier, db})
|
|
459
|
+
await this.loadMigrationsVersionsForDatabase({dbIdentifier, db})
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const migrationClass = await requireMigration()
|
|
463
|
+
|
|
464
|
+
if (!migrationClass || typeof migrationClass !== "function") {
|
|
465
|
+
throw new Error(`Migration ${migration.file} must export a default migration class. Type: ${typeof migrationClass}`)
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const migrationDatabaseIdentifiers = migrationClass.getDatabaseIdentifiers() || ["default"]
|
|
469
|
+
|
|
470
|
+
for (const dbIdentifier in dbs) {
|
|
471
|
+
if (!this.handlesDatabaseIdentifier(dbIdentifier)) continue
|
|
472
|
+
|
|
473
|
+
const databaseConfiguration = this.configuration.getDatabaseIdentifier(dbIdentifier)
|
|
474
|
+
|
|
475
|
+
if (!databaseConfiguration.migrations) {
|
|
476
|
+
this.logger.debug(`${dbIdentifier} isn't configured for migrations - skipping migration ${digg(migration, "date")}`)
|
|
477
|
+
continue
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (!migrationDatabaseIdentifiers.includes(dbIdentifier)) {
|
|
481
|
+
this.logger.debug(`${dbIdentifier} shouldn't run migration ${migration.file}`, {migrationDatabaseIdentifiers})
|
|
482
|
+
continue
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (direction == "up") {
|
|
486
|
+
if (this.hasRunMigrationVersion(dbIdentifier, migration.date)) {
|
|
487
|
+
this.logger.debug(`${dbIdentifier} has already run migration ${migration.file}`)
|
|
488
|
+
continue
|
|
489
|
+
}
|
|
490
|
+
} else if (direction == "down") {
|
|
491
|
+
if (!this.hasRunMigrationVersion(dbIdentifier, migration.date)) {
|
|
492
|
+
this.logger.debug(`${dbIdentifier} hasn't run migration ${migration.file}`)
|
|
493
|
+
continue
|
|
494
|
+
}
|
|
495
|
+
} else {
|
|
496
|
+
throw new Error(`Unknown direction: ${direction}`)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
this.logger.debug(`Running migration on ${dbIdentifier}: ${migration.file}`, {migrationDatabaseIdentifiers})
|
|
500
|
+
|
|
501
|
+
applied = true
|
|
502
|
+
const db = dbs[dbIdentifier]
|
|
503
|
+
const MigrationClass = migrationClass
|
|
504
|
+
const migrationInstance = new MigrationClass({
|
|
505
|
+
configuration: this.configuration,
|
|
506
|
+
databaseIdentifier: dbIdentifier,
|
|
507
|
+
db
|
|
508
|
+
})
|
|
509
|
+
const dateString = `${digg(migration, "date")}`
|
|
510
|
+
|
|
511
|
+
if (direction == "up") {
|
|
512
|
+
try {
|
|
513
|
+
await migrationInstance.change()
|
|
514
|
+
} catch (changeError) {
|
|
515
|
+
if (changeError instanceof NotImplementedError) {
|
|
516
|
+
try {
|
|
517
|
+
await migrationInstance.up()
|
|
518
|
+
} catch (upError) {
|
|
519
|
+
if (upError instanceof NotImplementedError) {
|
|
520
|
+
throw new Error(`'change' or 'up' didn't exist on migration: ${migration.file}`, {cause: upError})
|
|
521
|
+
} else {
|
|
522
|
+
throw upError
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
} else {
|
|
526
|
+
throw changeError
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const existingSchemaMigrations = await db.newQuery()
|
|
531
|
+
.from("schema_migrations")
|
|
532
|
+
.where({version: dateString})
|
|
533
|
+
.results()
|
|
534
|
+
|
|
535
|
+
if (existingSchemaMigrations.length == 0) {
|
|
536
|
+
await db.insert({tableName: "schema_migrations", data: {version: dateString}})
|
|
537
|
+
}
|
|
538
|
+
} else if (direction == "down") {
|
|
539
|
+
try {
|
|
540
|
+
await migrationInstance.down()
|
|
541
|
+
} catch (downError) {
|
|
542
|
+
if (downError instanceof NotImplementedError) {
|
|
543
|
+
throw new Error(`'down' didn't exist on migration: ${migration.file} or migrating down with a change method isn't currently supported`, {cause: downError})
|
|
544
|
+
} else {
|
|
545
|
+
throw downError
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
await db.delete({tableName: "schema_migrations", conditions: {version: dateString}})
|
|
550
|
+
} else {
|
|
551
|
+
throw new Error(`Unknown direction: ${direction}`)
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
return applied
|
|
556
|
+
}
|
|
557
|
+
}
|