@baasix/baasix 0.1.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/LICENSE.MD +85 -0
- package/README.md +526 -0
- package/assets/banner.jpg +0 -0
- package/assets/banner_small.jpg +0 -0
- package/assets/logo_icon.svg +20 -0
- package/assets/logo_icon_rounded.svg +20 -0
- package/dist/LICENSE.MD +85 -0
- package/dist/README.md +526 -0
- package/dist/app/404/index.html +1 -0
- package/dist/app/404.html +1 -0
- package/dist/app/_next/static/chunks/041e1f03-56ae8a902a7f2fe6.js +24 -0
- package/dist/app/_next/static/chunks/1117-05479929a8da73e3.js +1 -0
- package/dist/app/_next/static/chunks/1299.77cc7b7b76b75cba.js +1 -0
- package/dist/app/_next/static/chunks/1303-35a96e9c9cdeab9d.js +1 -0
- package/dist/app/_next/static/chunks/1509-56ac00cdaaecdf53.js +1 -0
- package/dist/app/_next/static/chunks/1668-e3eabd0f6753c780.js +1 -0
- package/dist/app/_next/static/chunks/1783-d9fb550fd324300c.js +1 -0
- package/dist/app/_next/static/chunks/2117-29b5fa47421595ad.js +2 -0
- package/dist/app/_next/static/chunks/2344.35b46d2179a765b5.js +1 -0
- package/dist/app/_next/static/chunks/257.990da16794a31292.js +1 -0
- package/dist/app/_next/static/chunks/2676-73b0ee7c80073a84.js +1 -0
- package/dist/app/_next/static/chunks/3563-b8842744384391fe.js +1 -0
- package/dist/app/_next/static/chunks/363642f4-933b579ed3c85f60.js +1 -0
- package/dist/app/_next/static/chunks/3817-e20c8f0a0810fc95.js +1 -0
- package/dist/app/_next/static/chunks/3834.84944e390d902509.js +2 -0
- package/dist/app/_next/static/chunks/4043-3a30c8a75896f241.js +1 -0
- package/dist/app/_next/static/chunks/4225-14090c7c0cd9dec6.js +1 -0
- package/dist/app/_next/static/chunks/4438-c9a12ca15b6e9160.js +1 -0
- package/dist/app/_next/static/chunks/4458-679fd0c6884f456a.js +1 -0
- package/dist/app/_next/static/chunks/4475-8bdfbd536fba8c48.js +1 -0
- package/dist/app/_next/static/chunks/4883-8a924721bb21b3b0.js +1 -0
- package/dist/app/_next/static/chunks/489-683ab07188f9df2b.js +1 -0
- package/dist/app/_next/static/chunks/4952-1b97320cf61f3f21.js +1 -0
- package/dist/app/_next/static/chunks/5094-8d53e403235d4ca6.js +1 -0
- package/dist/app/_next/static/chunks/5101-3a146e0625747ad1.js +1 -0
- package/dist/app/_next/static/chunks/54a60aa6-d9747982e0a81f58.js +79 -0
- package/dist/app/_next/static/chunks/5650-f096291df402bfc2.js +1 -0
- package/dist/app/_next/static/chunks/600-539045311240f579.js +1 -0
- package/dist/app/_next/static/chunks/6170-803b82e19d3ade6d.js +89 -0
- package/dist/app/_next/static/chunks/6241-30d7169d1010e5a4.js +1 -0
- package/dist/app/_next/static/chunks/6530-a91e10cffa4200c4.js +1 -0
- package/dist/app/_next/static/chunks/6547-4bbbdb5c399aef1e.js +1 -0
- package/dist/app/_next/static/chunks/6712-781937c53a2c49da.js +1 -0
- package/dist/app/_next/static/chunks/6fcbdc68-90be1a5480b8d353.js +1 -0
- package/dist/app/_next/static/chunks/70e0d97a-aeaf0cdc26ba1a58.js +1 -0
- package/dist/app/_next/static/chunks/7214-5154a89d08d24dde.js +1 -0
- package/dist/app/_next/static/chunks/7324-b53229c59a640880.js +10 -0
- package/dist/app/_next/static/chunks/7636-66424f0b51d350e9.js +1 -0
- package/dist/app/_next/static/chunks/7874-39a3f2541165a675.js +1 -0
- package/dist/app/_next/static/chunks/7982-9da12b83f11e3f5f.js +1 -0
- package/dist/app/_next/static/chunks/8213a2eb-da25a3b3c5521b2b.js +1 -0
- package/dist/app/_next/static/chunks/8473-6598318371eca31b.js +1 -0
- package/dist/app/_next/static/chunks/8640fa6b-72e43370f68e5587.js +1 -0
- package/dist/app/_next/static/chunks/9090-3ef676f29c95f1c7.js +1 -0
- package/dist/app/_next/static/chunks/9124-a02f9e209e6e3cce.js +1 -0
- package/dist/app/_next/static/chunks/926-156f32067d111d6b.js +1 -0
- package/dist/app/_next/static/chunks/9487-b17481605e513b83.js +1 -0
- package/dist/app/_next/static/chunks/9599-a7e572bb88c3392b.js +1 -0
- package/dist/app/_next/static/chunks/9881-419697138376e755.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/all-activity/page-8917930b4d663405.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/email-log/page-b27a6ee32782d7df.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/notifications/page-b7eda523ede2702c.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/page-1cfa62d1caedaed0.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/sessions/page-3e21e20db90aeff7.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/workflow-executions/page-27bcc26b747fb29b.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/workflow-logs/page-9f9e9e952aef436e.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/change-password/page-8d61aa499eabb127.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/dashboard/page-1ceeac9e72997a8a.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/data-browser/page-8cda2b57759dd670.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/file-manager/page-8c6f1b1da66ad7e4.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/layout-f70d225b2759c998.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/migrations/page-aacec8f7cfb40ab2.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/permissions/page-828110cfcde429c6.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/project/page-420e794bb76bd204.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/roles/page-9001d02b28f70708.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/schema/page-899574f35091dd58.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/tasks/page-ad7ab3e27c83f44f.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/templates/edit/page-bd83414cb8c4cb04.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/templates/page-3181447f8772b1d3.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/settings/tenants/page-ef9bfbacef5a1d73.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/users/invites/page-480306b7b2bbac7e.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/users/list/page-74da51254c2606b3.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/users/page-e99c6f0b915001b2.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/users/preferences/page-1a935630ce8f2b12.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/users/user-roles/page-901dfb8ea1f39ca8.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/workflows/detail/page-9a6b839aea688ca4.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/workflows/edit/page-11774efbc2fecae2.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/workflows/execution/page-8ec1aea90412c03d.js +1 -0
- package/dist/app/_next/static/chunks/app/(authenticated)/workflows/page-88bc5b36ccb0a1f7.js +1 -0
- package/dist/app/_next/static/chunks/app/(public)/forgot-password/page-ed263fd46ef81c20.js +1 -0
- package/dist/app/_next/static/chunks/app/(public)/layout-f538977545844af8.js +1 -0
- package/dist/app/_next/static/chunks/app/(public)/login/page-c0a10b137f346096.js +1 -0
- package/dist/app/_next/static/chunks/app/(public)/register/page-4cb7644893efd9b3.js +1 -0
- package/dist/app/_next/static/chunks/app/_not-found/page-653f8815b78256cc.js +1 -0
- package/dist/app/_next/static/chunks/app/layout-591ca7a3e16528a1.js +1 -0
- package/dist/app/_next/static/chunks/app/page-dd19d124b5fa2577.js +1 -0
- package/dist/app/_next/static/chunks/c37d3baf.c2ff165f5b02c692.js +1 -0
- package/dist/app/_next/static/chunks/d0deef33.0379166a4ec23470.js +1 -0
- package/dist/app/_next/static/chunks/fd9d1056-54169f07cd680d6c.js +1 -0
- package/dist/app/_next/static/chunks/framework-8e0e0f4a6b83a956.js +1 -0
- package/dist/app/_next/static/chunks/main-324e91f5a430cddf.js +1 -0
- package/dist/app/_next/static/chunks/main-app-55bcae20c77aaf0e.js +1 -0
- package/dist/app/_next/static/chunks/pages/_app-3c9ca398d360b709.js +1 -0
- package/dist/app/_next/static/chunks/pages/_error-cf5ca766ac8f493f.js +1 -0
- package/dist/app/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/dist/app/_next/static/chunks/webpack-2c306566f7ee1b63.js +1 -0
- package/dist/app/_next/static/css/6c4002bae4e236b2.css +3 -0
- package/dist/app/_next/static/css/a275cc2b185e04f8.css +1 -0
- package/dist/app/_next/static/eCWhKA8XHqmB1zgFcEtN2/_buildManifest.js +1 -0
- package/dist/app/_next/static/eCWhKA8XHqmB1zgFcEtN2/_ssgManifest.js +1 -0
- package/dist/app/activity-log/all-activity/index.html +1 -0
- package/dist/app/activity-log/all-activity/index.txt +14 -0
- package/dist/app/activity-log/email-log/index.html +1 -0
- package/dist/app/activity-log/email-log/index.txt +14 -0
- package/dist/app/activity-log/index.html +1 -0
- package/dist/app/activity-log/index.txt +14 -0
- package/dist/app/activity-log/notifications/index.html +1 -0
- package/dist/app/activity-log/notifications/index.txt +14 -0
- package/dist/app/activity-log/sessions/index.html +1 -0
- package/dist/app/activity-log/sessions/index.txt +14 -0
- package/dist/app/activity-log/workflow-executions/index.html +1 -0
- package/dist/app/activity-log/workflow-executions/index.txt +14 -0
- package/dist/app/activity-log/workflow-logs/index.html +1 -0
- package/dist/app/activity-log/workflow-logs/index.txt +14 -0
- package/dist/app/change-password/index.html +1 -0
- package/dist/app/change-password/index.txt +14 -0
- package/dist/app/dashboard/index.html +1 -0
- package/dist/app/dashboard/index.txt +14 -0
- package/dist/app/data-browser/index.html +1 -0
- package/dist/app/data-browser/index.txt +14 -0
- package/dist/app/file-manager/index.html +1 -0
- package/dist/app/file-manager/index.txt +14 -0
- package/dist/app/forgot-password/index.html +1 -0
- package/dist/app/forgot-password/index.txt +13 -0
- package/dist/app/index.html +1 -0
- package/dist/app/index.txt +9 -0
- package/dist/app/login/index.html +1 -0
- package/dist/app/login/index.txt +13 -0
- package/dist/app/logo-dark.png +0 -0
- package/dist/app/logo-icon.svg +81 -0
- package/dist/app/logo-light.png +0 -0
- package/dist/app/register/index.html +1 -0
- package/dist/app/register/index.txt +13 -0
- package/dist/app/settings/migrations/index.html +1 -0
- package/dist/app/settings/migrations/index.txt +14 -0
- package/dist/app/settings/permissions/index.html +1 -0
- package/dist/app/settings/permissions/index.txt +14 -0
- package/dist/app/settings/project/index.html +1 -0
- package/dist/app/settings/project/index.txt +14 -0
- package/dist/app/settings/roles/index.html +1 -0
- package/dist/app/settings/roles/index.txt +14 -0
- package/dist/app/settings/schema/index.html +1 -0
- package/dist/app/settings/schema/index.txt +14 -0
- package/dist/app/settings/tasks/index.html +1 -0
- package/dist/app/settings/tasks/index.txt +14 -0
- package/dist/app/settings/templates/edit/index.html +1 -0
- package/dist/app/settings/templates/edit/index.txt +14 -0
- package/dist/app/settings/templates/index.html +1 -0
- package/dist/app/settings/templates/index.txt +14 -0
- package/dist/app/settings/tenants/index.html +1 -0
- package/dist/app/settings/tenants/index.txt +14 -0
- package/dist/app/users/index.html +1 -0
- package/dist/app/users/index.txt +14 -0
- package/dist/app/users/invites/index.html +1 -0
- package/dist/app/users/invites/index.txt +14 -0
- package/dist/app/users/list/index.html +1 -0
- package/dist/app/users/list/index.txt +14 -0
- package/dist/app/users/preferences/index.html +1 -0
- package/dist/app/users/preferences/index.txt +14 -0
- package/dist/app/users/user-roles/index.html +1 -0
- package/dist/app/users/user-roles/index.txt +14 -0
- package/dist/app/workflows/detail/index.html +1 -0
- package/dist/app/workflows/detail/index.txt +14 -0
- package/dist/app/workflows/edit/index.html +1 -0
- package/dist/app/workflows/edit/index.txt +14 -0
- package/dist/app/workflows/execution/index.html +1 -0
- package/dist/app/workflows/execution/index.txt +14 -0
- package/dist/app/workflows/index.html +1 -0
- package/dist/app/workflows/index.txt +14 -0
- package/dist/app.d.ts +36 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +546 -0
- package/dist/app.js.map +1 -0
- package/dist/auth/adapters/baasix-adapter.d.ts +12 -0
- package/dist/auth/adapters/baasix-adapter.d.ts.map +1 -0
- package/dist/auth/adapters/baasix-adapter.js +318 -0
- package/dist/auth/adapters/baasix-adapter.js.map +1 -0
- package/dist/auth/adapters/index.d.ts +6 -0
- package/dist/auth/adapters/index.d.ts.map +1 -0
- package/dist/auth/adapters/index.js +5 -0
- package/dist/auth/adapters/index.js.map +1 -0
- package/dist/auth/core.d.ts +73 -0
- package/dist/auth/core.d.ts.map +1 -0
- package/dist/auth/core.js +528 -0
- package/dist/auth/core.js.map +1 -0
- package/dist/auth/index.d.ts +56 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +58 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/oauth2/index.d.ts +5 -0
- package/dist/auth/oauth2/index.d.ts.map +1 -0
- package/dist/auth/oauth2/index.js +5 -0
- package/dist/auth/oauth2/index.js.map +1 -0
- package/dist/auth/oauth2/utils.d.ts +90 -0
- package/dist/auth/oauth2/utils.d.ts.map +1 -0
- package/dist/auth/oauth2/utils.js +167 -0
- package/dist/auth/oauth2/utils.js.map +1 -0
- package/dist/auth/providers/apple.d.ts +28 -0
- package/dist/auth/providers/apple.d.ts.map +1 -0
- package/dist/auth/providers/apple.js +192 -0
- package/dist/auth/providers/apple.js.map +1 -0
- package/dist/auth/providers/credential.d.ts +87 -0
- package/dist/auth/providers/credential.d.ts.map +1 -0
- package/dist/auth/providers/credential.js +162 -0
- package/dist/auth/providers/credential.js.map +1 -0
- package/dist/auth/providers/facebook.d.ts +26 -0
- package/dist/auth/providers/facebook.d.ts.map +1 -0
- package/dist/auth/providers/facebook.js +112 -0
- package/dist/auth/providers/facebook.js.map +1 -0
- package/dist/auth/providers/github.d.ts +29 -0
- package/dist/auth/providers/github.d.ts.map +1 -0
- package/dist/auth/providers/github.js +144 -0
- package/dist/auth/providers/github.js.map +1 -0
- package/dist/auth/providers/google.d.ts +32 -0
- package/dist/auth/providers/google.d.ts.map +1 -0
- package/dist/auth/providers/google.js +145 -0
- package/dist/auth/providers/google.js.map +1 -0
- package/dist/auth/providers/index.d.ts +22 -0
- package/dist/auth/providers/index.d.ts.map +1 -0
- package/dist/auth/providers/index.js +17 -0
- package/dist/auth/providers/index.js.map +1 -0
- package/dist/auth/routes.d.ts +63 -0
- package/dist/auth/routes.d.ts.map +1 -0
- package/dist/auth/routes.js +827 -0
- package/dist/auth/routes.js.map +1 -0
- package/dist/auth/services/index.d.ts +10 -0
- package/dist/auth/services/index.d.ts.map +1 -0
- package/dist/auth/services/index.js +7 -0
- package/dist/auth/services/index.js.map +1 -0
- package/dist/auth/services/session.d.ts +81 -0
- package/dist/auth/services/session.d.ts.map +1 -0
- package/dist/auth/services/session.js +186 -0
- package/dist/auth/services/session.js.map +1 -0
- package/dist/auth/services/token.d.ts +41 -0
- package/dist/auth/services/token.d.ts.map +1 -0
- package/dist/auth/services/token.js +44 -0
- package/dist/auth/services/token.js.map +1 -0
- package/dist/auth/services/verification.d.ts +77 -0
- package/dist/auth/services/verification.d.ts.map +1 -0
- package/dist/auth/services/verification.js +143 -0
- package/dist/auth/services/verification.js.map +1 -0
- package/dist/auth/types.d.ts +318 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +6 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/customTypes/arrays.d.ts +200 -0
- package/dist/customTypes/arrays.d.ts.map +1 -0
- package/dist/customTypes/arrays.js +309 -0
- package/dist/customTypes/arrays.js.map +1 -0
- package/dist/customTypes/index.d.ts +8 -0
- package/dist/customTypes/index.d.ts.map +1 -0
- package/dist/customTypes/index.js +11 -0
- package/dist/customTypes/index.js.map +1 -0
- package/dist/customTypes/postgis.d.ts +146 -0
- package/dist/customTypes/postgis.d.ts.map +1 -0
- package/dist/customTypes/postgis.js +315 -0
- package/dist/customTypes/postgis.js.map +1 -0
- package/dist/customTypes/ranges.d.ts +128 -0
- package/dist/customTypes/ranges.d.ts.map +1 -0
- package/dist/customTypes/ranges.js +257 -0
- package/dist/customTypes/ranges.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/0.1.0-alpha.0_initial_setup.d.ts +29 -0
- package/dist/migrations/0.1.0-alpha.0_initial_setup.d.ts.map +1 -0
- package/dist/migrations/0.1.0-alpha.0_initial_setup.js +72 -0
- package/dist/migrations/0.1.0-alpha.0_initial_setup.js.map +1 -0
- package/dist/migrations/_example_migration.d.ts +31 -0
- package/dist/migrations/_example_migration.d.ts.map +1 -0
- package/dist/migrations/_example_migration.js +75 -0
- package/dist/migrations/_example_migration.js.map +1 -0
- package/dist/plugins/definePlugin.d.ts +49 -0
- package/dist/plugins/definePlugin.d.ts.map +1 -0
- package/dist/plugins/definePlugin.js +131 -0
- package/dist/plugins/definePlugin.js.map +1 -0
- package/dist/plugins/softDelete.d.ts +179 -0
- package/dist/plugins/softDelete.d.ts.map +1 -0
- package/dist/plugins/softDelete.js +235 -0
- package/dist/plugins/softDelete.js.map +1 -0
- package/dist/routes/auth.route.d.ts +14 -0
- package/dist/routes/auth.route.d.ts.map +1 -0
- package/dist/routes/auth.route.js +421 -0
- package/dist/routes/auth.route.js.map +1 -0
- package/dist/routes/file.route.d.ts +7 -0
- package/dist/routes/file.route.d.ts.map +1 -0
- package/dist/routes/file.route.js +274 -0
- package/dist/routes/file.route.js.map +1 -0
- package/dist/routes/items.route.d.ts +7 -0
- package/dist/routes/items.route.d.ts.map +1 -0
- package/dist/routes/items.route.js +369 -0
- package/dist/routes/items.route.js.map +1 -0
- package/dist/routes/migration.route.d.ts +7 -0
- package/dist/routes/migration.route.d.ts.map +1 -0
- package/dist/routes/migration.route.js +225 -0
- package/dist/routes/migration.route.js.map +1 -0
- package/dist/routes/notification.route.d.ts +7 -0
- package/dist/routes/notification.route.d.ts.map +1 -0
- package/dist/routes/notification.route.js +124 -0
- package/dist/routes/notification.route.js.map +1 -0
- package/dist/routes/openapi.route.d.ts +7 -0
- package/dist/routes/openapi.route.d.ts.map +1 -0
- package/dist/routes/openapi.route.js +2169 -0
- package/dist/routes/openapi.route.js.map +1 -0
- package/dist/routes/permission.route.d.ts +7 -0
- package/dist/routes/permission.route.d.ts.map +1 -0
- package/dist/routes/permission.route.js +158 -0
- package/dist/routes/permission.route.js.map +1 -0
- package/dist/routes/realtime.route.d.ts +21 -0
- package/dist/routes/realtime.route.d.ts.map +1 -0
- package/dist/routes/realtime.route.js +243 -0
- package/dist/routes/realtime.route.js.map +1 -0
- package/dist/routes/reports.route.d.ts +7 -0
- package/dist/routes/reports.route.d.ts.map +1 -0
- package/dist/routes/reports.route.js +95 -0
- package/dist/routes/reports.route.js.map +1 -0
- package/dist/routes/schema.route.d.ts +7 -0
- package/dist/routes/schema.route.d.ts.map +1 -0
- package/dist/routes/schema.route.js +1780 -0
- package/dist/routes/schema.route.js.map +1 -0
- package/dist/routes/settings.route.d.ts +7 -0
- package/dist/routes/settings.route.d.ts.map +1 -0
- package/dist/routes/settings.route.js +154 -0
- package/dist/routes/settings.route.js.map +1 -0
- package/dist/routes/templates.route.d.ts +7 -0
- package/dist/routes/templates.route.d.ts.map +1 -0
- package/dist/routes/templates.route.js +91 -0
- package/dist/routes/templates.route.js.map +1 -0
- package/dist/routes/utils.route.d.ts +7 -0
- package/dist/routes/utils.route.d.ts.map +1 -0
- package/dist/routes/utils.route.js +33 -0
- package/dist/routes/utils.route.js.map +1 -0
- package/dist/routes/workflow.route.d.ts +7 -0
- package/dist/routes/workflow.route.d.ts.map +1 -0
- package/dist/routes/workflow.route.js +787 -0
- package/dist/routes/workflow.route.js.map +1 -0
- package/dist/services/AssetsService.d.ts +39 -0
- package/dist/services/AssetsService.d.ts.map +1 -0
- package/dist/services/AssetsService.js +255 -0
- package/dist/services/AssetsService.js.map +1 -0
- package/dist/services/CacheService.d.ts +169 -0
- package/dist/services/CacheService.d.ts.map +1 -0
- package/dist/services/CacheService.js +722 -0
- package/dist/services/CacheService.js.map +1 -0
- package/dist/services/FilesService.d.ts +30 -0
- package/dist/services/FilesService.d.ts.map +1 -0
- package/dist/services/FilesService.js +268 -0
- package/dist/services/FilesService.js.map +1 -0
- package/dist/services/HooksManager.d.ts +38 -0
- package/dist/services/HooksManager.d.ts.map +1 -0
- package/dist/services/HooksManager.js +165 -0
- package/dist/services/HooksManager.js.map +1 -0
- package/dist/services/ItemsService.d.ts +273 -0
- package/dist/services/ItemsService.d.ts.map +1 -0
- package/dist/services/ItemsService.js +2458 -0
- package/dist/services/ItemsService.js.map +1 -0
- package/dist/services/MailService.d.ts +76 -0
- package/dist/services/MailService.d.ts.map +1 -0
- package/dist/services/MailService.js +585 -0
- package/dist/services/MailService.js.map +1 -0
- package/dist/services/MigrationService.d.ts +243 -0
- package/dist/services/MigrationService.d.ts.map +1 -0
- package/dist/services/MigrationService.js +914 -0
- package/dist/services/MigrationService.js.map +1 -0
- package/dist/services/NotificationService.d.ts +35 -0
- package/dist/services/NotificationService.d.ts.map +1 -0
- package/dist/services/NotificationService.js +159 -0
- package/dist/services/NotificationService.js.map +1 -0
- package/dist/services/PermissionService.d.ts +128 -0
- package/dist/services/PermissionService.d.ts.map +1 -0
- package/dist/services/PermissionService.js +373 -0
- package/dist/services/PermissionService.js.map +1 -0
- package/dist/services/PluginManager.d.ts +138 -0
- package/dist/services/PluginManager.d.ts.map +1 -0
- package/dist/services/PluginManager.js +463 -0
- package/dist/services/PluginManager.js.map +1 -0
- package/dist/services/RealtimeService.d.ts +209 -0
- package/dist/services/RealtimeService.d.ts.map +1 -0
- package/dist/services/RealtimeService.js +978 -0
- package/dist/services/RealtimeService.js.map +1 -0
- package/dist/services/ReportService.d.ts +13 -0
- package/dist/services/ReportService.d.ts.map +1 -0
- package/dist/services/ReportService.js +91 -0
- package/dist/services/ReportService.js.map +1 -0
- package/dist/services/SettingsService.d.ts +60 -0
- package/dist/services/SettingsService.d.ts.map +1 -0
- package/dist/services/SettingsService.js +474 -0
- package/dist/services/SettingsService.js.map +1 -0
- package/dist/services/SocketService.d.ts +129 -0
- package/dist/services/SocketService.d.ts.map +1 -0
- package/dist/services/SocketService.js +600 -0
- package/dist/services/SocketService.js.map +1 -0
- package/dist/services/StatsService.d.ts +10 -0
- package/dist/services/StatsService.d.ts.map +1 -0
- package/dist/services/StatsService.js +40 -0
- package/dist/services/StatsService.js.map +1 -0
- package/dist/services/StorageService.d.ts +20 -0
- package/dist/services/StorageService.d.ts.map +1 -0
- package/dist/services/StorageService.js +164 -0
- package/dist/services/StorageService.js.map +1 -0
- package/dist/services/TasksService.d.ts +74 -0
- package/dist/services/TasksService.d.ts.map +1 -0
- package/dist/services/TasksService.js +404 -0
- package/dist/services/TasksService.js.map +1 -0
- package/dist/services/WorkflowService.d.ts +305 -0
- package/dist/services/WorkflowService.d.ts.map +1 -0
- package/dist/services/WorkflowService.js +1811 -0
- package/dist/services/WorkflowService.js.map +1 -0
- package/dist/templates/logo/logo.png +0 -0
- package/dist/templates/mails/default.liquid +23 -0
- package/dist/types/aggregation.d.ts +40 -0
- package/dist/types/aggregation.d.ts.map +1 -0
- package/dist/types/aggregation.js +6 -0
- package/dist/types/aggregation.js.map +1 -0
- package/dist/types/assets.d.ts +32 -0
- package/dist/types/assets.d.ts.map +1 -0
- package/dist/types/assets.js +6 -0
- package/dist/types/assets.js.map +1 -0
- package/dist/types/auth.d.ts +50 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +6 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/cache.d.ts +47 -0
- package/dist/types/cache.d.ts.map +1 -0
- package/dist/types/cache.js +6 -0
- package/dist/types/cache.js.map +1 -0
- package/dist/types/database.d.ts +16 -0
- package/dist/types/database.d.ts.map +1 -0
- package/dist/types/database.js +6 -0
- package/dist/types/database.js.map +1 -0
- package/dist/types/fields.d.ts +71 -0
- package/dist/types/fields.d.ts.map +1 -0
- package/dist/types/fields.js +6 -0
- package/dist/types/fields.js.map +1 -0
- package/dist/types/files.d.ts +33 -0
- package/dist/types/files.d.ts.map +1 -0
- package/dist/types/files.js +6 -0
- package/dist/types/files.js.map +1 -0
- package/dist/types/hooks.d.ts +29 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/hooks.js +6 -0
- package/dist/types/hooks.js.map +1 -0
- package/dist/types/import-export.d.ts +62 -0
- package/dist/types/import-export.d.ts.map +1 -0
- package/dist/types/import-export.js +6 -0
- package/dist/types/import-export.js.map +1 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +58 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/mail.d.ts +34 -0
- package/dist/types/mail.d.ts.map +1 -0
- package/dist/types/mail.js +6 -0
- package/dist/types/mail.js.map +1 -0
- package/dist/types/notifications.d.ts +16 -0
- package/dist/types/notifications.d.ts.map +1 -0
- package/dist/types/notifications.js +6 -0
- package/dist/types/notifications.js.map +1 -0
- package/dist/types/plugin.d.ts +351 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +8 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/query.d.ts +71 -0
- package/dist/types/query.d.ts.map +1 -0
- package/dist/types/query.js +6 -0
- package/dist/types/query.js.map +1 -0
- package/dist/types/relations.d.ts +111 -0
- package/dist/types/relations.d.ts.map +1 -0
- package/dist/types/relations.js +6 -0
- package/dist/types/relations.js.map +1 -0
- package/dist/types/reports.d.ts +17 -0
- package/dist/types/reports.d.ts.map +1 -0
- package/dist/types/reports.js +6 -0
- package/dist/types/reports.js.map +1 -0
- package/dist/types/schema.d.ts +26 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +6 -0
- package/dist/types/schema.js.map +1 -0
- package/dist/types/seed.d.ts +27 -0
- package/dist/types/seed.d.ts.map +1 -0
- package/dist/types/seed.js +6 -0
- package/dist/types/seed.js.map +1 -0
- package/dist/types/services.d.ts +68 -0
- package/dist/types/services.d.ts.map +1 -0
- package/dist/types/services.js +6 -0
- package/dist/types/services.js.map +1 -0
- package/dist/types/settings.d.ts +36 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/dist/types/settings.js +6 -0
- package/dist/types/settings.js.map +1 -0
- package/dist/types/sockets.d.ts +26 -0
- package/dist/types/sockets.d.ts.map +1 -0
- package/dist/types/sockets.js +6 -0
- package/dist/types/sockets.js.map +1 -0
- package/dist/types/sort.d.ts +25 -0
- package/dist/types/sort.d.ts.map +1 -0
- package/dist/types/sort.js +6 -0
- package/dist/types/sort.js.map +1 -0
- package/dist/types/spatial.d.ts +19 -0
- package/dist/types/spatial.d.ts.map +1 -0
- package/dist/types/spatial.js +6 -0
- package/dist/types/spatial.js.map +1 -0
- package/dist/types/stats.d.ts +21 -0
- package/dist/types/stats.d.ts.map +1 -0
- package/dist/types/stats.js +6 -0
- package/dist/types/stats.js.map +1 -0
- package/dist/types/storage.d.ts +19 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +6 -0
- package/dist/types/storage.js.map +1 -0
- package/dist/types/tasks.d.ts +14 -0
- package/dist/types/tasks.d.ts.map +1 -0
- package/dist/types/tasks.js +6 -0
- package/dist/types/tasks.js.map +1 -0
- package/dist/types/utils.d.ts +54 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +6 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types/workflow.d.ts +17 -0
- package/dist/types/workflow.d.ts.map +1 -0
- package/dist/types/workflow.js +6 -0
- package/dist/types/workflow.js.map +1 -0
- package/dist/utils/aggregationUtils.d.ts +192 -0
- package/dist/utils/aggregationUtils.d.ts.map +1 -0
- package/dist/utils/aggregationUtils.js +450 -0
- package/dist/utils/aggregationUtils.js.map +1 -0
- package/dist/utils/auth.d.ts +93 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +557 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/cache.d.ts +64 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +464 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/common.d.ts +53 -0
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +162 -0
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/db.d.ts +101 -0
- package/dist/utils/db.d.ts.map +1 -0
- package/dist/utils/db.js +413 -0
- package/dist/utils/db.js.map +1 -0
- package/dist/utils/dirname.d.ts +30 -0
- package/dist/utils/dirname.d.ts.map +1 -0
- package/dist/utils/dirname.js +95 -0
- package/dist/utils/dirname.js.map +1 -0
- package/dist/utils/dynamicVariableResolver.d.ts +17 -0
- package/dist/utils/dynamicVariableResolver.d.ts.map +1 -0
- package/dist/utils/dynamicVariableResolver.js +262 -0
- package/dist/utils/dynamicVariableResolver.js.map +1 -0
- package/dist/utils/env.d.ts +38 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +80 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/errorHandler.d.ts +14 -0
- package/dist/utils/errorHandler.d.ts.map +1 -0
- package/dist/utils/errorHandler.js +79 -0
- package/dist/utils/errorHandler.js.map +1 -0
- package/dist/utils/fieldExpansion.d.ts +30 -0
- package/dist/utils/fieldExpansion.d.ts.map +1 -0
- package/dist/utils/fieldExpansion.js +145 -0
- package/dist/utils/fieldExpansion.js.map +1 -0
- package/dist/utils/fieldUtils.d.ts +179 -0
- package/dist/utils/fieldUtils.d.ts.map +1 -0
- package/dist/utils/fieldUtils.js +424 -0
- package/dist/utils/fieldUtils.js.map +1 -0
- package/dist/utils/filterOperators.d.ts +472 -0
- package/dist/utils/filterOperators.d.ts.map +1 -0
- package/dist/utils/filterOperators.js +1229 -0
- package/dist/utils/filterOperators.js.map +1 -0
- package/dist/utils/importUtils.d.ts +127 -0
- package/dist/utils/importUtils.d.ts.map +1 -0
- package/dist/utils/importUtils.js +437 -0
- package/dist/utils/importUtils.js.map +1 -0
- package/dist/utils/index.d.ts +75 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +101 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +41 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +217 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/orderUtils.d.ts +117 -0
- package/dist/utils/orderUtils.d.ts.map +1 -0
- package/dist/utils/orderUtils.js +249 -0
- package/dist/utils/orderUtils.js.map +1 -0
- package/dist/utils/queryBuilder.d.ts +118 -0
- package/dist/utils/queryBuilder.d.ts.map +1 -0
- package/dist/utils/queryBuilder.js +489 -0
- package/dist/utils/queryBuilder.js.map +1 -0
- package/dist/utils/relationLoader.d.ts +65 -0
- package/dist/utils/relationLoader.d.ts.map +1 -0
- package/dist/utils/relationLoader.js +1081 -0
- package/dist/utils/relationLoader.js.map +1 -0
- package/dist/utils/relationPathResolver.d.ts +30 -0
- package/dist/utils/relationPathResolver.d.ts.map +1 -0
- package/dist/utils/relationPathResolver.js +173 -0
- package/dist/utils/relationPathResolver.js.map +1 -0
- package/dist/utils/relationUtils.d.ts +139 -0
- package/dist/utils/relationUtils.d.ts.map +1 -0
- package/dist/utils/relationUtils.js +711 -0
- package/dist/utils/relationUtils.js.map +1 -0
- package/dist/utils/router.d.ts +6 -0
- package/dist/utils/router.d.ts.map +1 -0
- package/dist/utils/router.js +95 -0
- package/dist/utils/router.js.map +1 -0
- package/dist/utils/schema.d.ts +88 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +24 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/schemaManager.d.ts +238 -0
- package/dist/utils/schemaManager.d.ts.map +1 -0
- package/dist/utils/schemaManager.js +1992 -0
- package/dist/utils/schemaManager.js.map +1 -0
- package/dist/utils/schemaValidator.d.ts +83 -0
- package/dist/utils/schemaValidator.d.ts.map +1 -0
- package/dist/utils/schemaValidator.js +491 -0
- package/dist/utils/schemaValidator.js.map +1 -0
- package/dist/utils/seed.d.ts +45 -0
- package/dist/utils/seed.d.ts.map +1 -0
- package/dist/utils/seed.js +248 -0
- package/dist/utils/seed.js.map +1 -0
- package/dist/utils/sessionCleanup.d.ts +10 -0
- package/dist/utils/sessionCleanup.d.ts.map +1 -0
- package/dist/utils/sessionCleanup.js +49 -0
- package/dist/utils/sessionCleanup.js.map +1 -0
- package/dist/utils/sortUtils.d.ts +117 -0
- package/dist/utils/sortUtils.d.ts.map +1 -0
- package/dist/utils/sortUtils.js +232 -0
- package/dist/utils/sortUtils.js.map +1 -0
- package/dist/utils/spatialUtils.d.ts +244 -0
- package/dist/utils/spatialUtils.d.ts.map +1 -0
- package/dist/utils/spatialUtils.js +359 -0
- package/dist/utils/spatialUtils.js.map +1 -0
- package/dist/utils/systemschema.d.ts +11040 -0
- package/dist/utils/systemschema.d.ts.map +1 -0
- package/dist/utils/systemschema.js +1777 -0
- package/dist/utils/systemschema.js.map +1 -0
- package/dist/utils/tenantUtils.d.ts +34 -0
- package/dist/utils/tenantUtils.d.ts.map +1 -0
- package/dist/utils/tenantUtils.js +124 -0
- package/dist/utils/tenantUtils.js.map +1 -0
- package/dist/utils/typeMapper.d.ts +25 -0
- package/dist/utils/typeMapper.d.ts.map +1 -0
- package/dist/utils/typeMapper.js +282 -0
- package/dist/utils/typeMapper.js.map +1 -0
- package/dist/utils/valueValidator.d.ts +60 -0
- package/dist/utils/valueValidator.d.ts.map +1 -0
- package/dist/utils/valueValidator.js +303 -0
- package/dist/utils/valueValidator.js.map +1 -0
- package/dist/utils/workflow.d.ts +87 -0
- package/dist/utils/workflow.d.ts.map +1 -0
- package/dist/utils/workflow.js +205 -0
- package/dist/utils/workflow.js.map +1 -0
- package/package.json +115 -0
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
import { getDatabase, getSqlClient } from "../utils/db.js";
|
|
2
|
+
import { schemaManager } from "../utils/schemaManager.js";
|
|
3
|
+
import { eq, desc, and, sql } from "drizzle-orm";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs/promises";
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
import env from "../utils/env.js";
|
|
8
|
+
import { getBaasixPath, getProjectPath, toFileURL } from "../utils/dirname.js";
|
|
9
|
+
/**
|
|
10
|
+
* MigrationService - Handles database migration execution and tracking
|
|
11
|
+
*/
|
|
12
|
+
class MigrationService {
|
|
13
|
+
initialized = false;
|
|
14
|
+
migrationsDir = "";
|
|
15
|
+
systemMigrationsDir = "";
|
|
16
|
+
logs = [];
|
|
17
|
+
isUpgradeFromSequelize = false;
|
|
18
|
+
constructor() {
|
|
19
|
+
// User migrations directory - in user's project
|
|
20
|
+
this.migrationsDir = env.get("MIGRATIONS_DIR") || getProjectPath("migrations");
|
|
21
|
+
// System migrations directory - bundled with package
|
|
22
|
+
this.systemMigrationsDir = getBaasixPath("migrations");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Detect if this is an upgrade from Sequelize version
|
|
26
|
+
* MUST be called BEFORE schemaManager.initialize() because that creates the migration table
|
|
27
|
+
*
|
|
28
|
+
* Detection logic:
|
|
29
|
+
* - If baasix_User exists but baasix_Migration does NOT exist → Sequelize upgrade
|
|
30
|
+
* - If neither exists → Fresh installation
|
|
31
|
+
* - If both exist → Already on Drizzle version
|
|
32
|
+
*/
|
|
33
|
+
async detectUpgradeBeforeSchemaInit() {
|
|
34
|
+
const sqlClient = getSqlClient();
|
|
35
|
+
try {
|
|
36
|
+
// Check if baasix_Migration table exists (new in Drizzle version)
|
|
37
|
+
const migrationTableExists = await sqlClient `
|
|
38
|
+
SELECT EXISTS (
|
|
39
|
+
SELECT FROM information_schema.tables
|
|
40
|
+
WHERE table_name = 'baasix_Migration'
|
|
41
|
+
)
|
|
42
|
+
`;
|
|
43
|
+
if (migrationTableExists[0]?.exists) {
|
|
44
|
+
// Migration table exists - this is already running Drizzle version
|
|
45
|
+
console.info("MigrationService: baasix_Migration table found - already on Drizzle version");
|
|
46
|
+
this.isUpgradeFromSequelize = false;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
// Migration table doesn't exist - check if this is an existing Sequelize database
|
|
50
|
+
// by looking for baasix_User table (present in both versions)
|
|
51
|
+
const userTableExists = await sqlClient `
|
|
52
|
+
SELECT EXISTS (
|
|
53
|
+
SELECT FROM information_schema.tables
|
|
54
|
+
WHERE table_name = 'baasix_User'
|
|
55
|
+
)
|
|
56
|
+
`;
|
|
57
|
+
if (!userTableExists[0]?.exists) {
|
|
58
|
+
// No user table either - this is a fresh installation
|
|
59
|
+
console.info("MigrationService: Fresh installation detected (no existing tables)");
|
|
60
|
+
this.isUpgradeFromSequelize = false;
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
// User table exists but Migration table doesn't - SEQUELIZE UPGRADE!
|
|
64
|
+
console.info("MigrationService: ⚠️ SEQUELIZE TO DRIZZLE UPGRADE DETECTED!");
|
|
65
|
+
console.info("MigrationService: Found baasix_User table but no baasix_Migration table");
|
|
66
|
+
this.isUpgradeFromSequelize = true;
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.warn("MigrationService: Error during upgrade detection:", error);
|
|
71
|
+
this.isUpgradeFromSequelize = false;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Initialize the migration service
|
|
77
|
+
* @param isUpgradeFromSequelize - Pass true if detectUpgradeBeforeSchemaInit() returned true
|
|
78
|
+
*/
|
|
79
|
+
async init(isUpgradeFromSequelize) {
|
|
80
|
+
if (this.initialized) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
console.info("MigrationService: Initializing...");
|
|
84
|
+
// Use passed value or previously detected value
|
|
85
|
+
if (isUpgradeFromSequelize !== undefined) {
|
|
86
|
+
this.isUpgradeFromSequelize = isUpgradeFromSequelize;
|
|
87
|
+
}
|
|
88
|
+
// Ensure migrations table exists (handled by schemaManager)
|
|
89
|
+
// Just verify we can access it
|
|
90
|
+
try {
|
|
91
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
92
|
+
if (!table) {
|
|
93
|
+
console.warn("MigrationService: baasix_Migration table not found, will be created on first use");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.warn("MigrationService: Could not access migration table:", error);
|
|
98
|
+
}
|
|
99
|
+
// Ensure migrations directories exist
|
|
100
|
+
await this.ensureMigrationDirs();
|
|
101
|
+
this.initialized = true;
|
|
102
|
+
console.info("MigrationService: Initialized successfully");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if this instance is an upgrade from Sequelize
|
|
106
|
+
*/
|
|
107
|
+
isSequelizeUpgrade() {
|
|
108
|
+
return this.isUpgradeFromSequelize;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Ensure migration directories exist
|
|
112
|
+
*/
|
|
113
|
+
async ensureMigrationDirs() {
|
|
114
|
+
try {
|
|
115
|
+
await fs.mkdir(this.migrationsDir, { recursive: true });
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Ignore if directory already exists
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
await fs.mkdir(this.systemMigrationsDir, { recursive: true });
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Ignore if directory already exists
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get all recorded migrations from database
|
|
129
|
+
*/
|
|
130
|
+
async getMigrations(options) {
|
|
131
|
+
const db = getDatabase();
|
|
132
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
133
|
+
if (!table) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
const conditions = [];
|
|
137
|
+
if (options?.status) {
|
|
138
|
+
conditions.push(eq(table.status, options.status));
|
|
139
|
+
}
|
|
140
|
+
if (options?.type) {
|
|
141
|
+
conditions.push(eq(table.type, options.type));
|
|
142
|
+
}
|
|
143
|
+
let results;
|
|
144
|
+
if (conditions.length > 0) {
|
|
145
|
+
results = await db.select().from(table).where(and(...conditions)).orderBy(desc(table.executedAt));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
results = await db.select().from(table).orderBy(desc(table.executedAt));
|
|
149
|
+
}
|
|
150
|
+
return results;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the last executed migration
|
|
154
|
+
*/
|
|
155
|
+
async getLastMigration() {
|
|
156
|
+
const db = getDatabase();
|
|
157
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
158
|
+
if (!table) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const results = await db
|
|
162
|
+
.select()
|
|
163
|
+
.from(table)
|
|
164
|
+
.where(eq(table.status, "completed"))
|
|
165
|
+
.orderBy(desc(table.executedAt))
|
|
166
|
+
.limit(1);
|
|
167
|
+
return results[0] || null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get migration by version
|
|
171
|
+
*/
|
|
172
|
+
async getMigrationByVersion(version) {
|
|
173
|
+
const db = getDatabase();
|
|
174
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
175
|
+
if (!table) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const results = await db
|
|
179
|
+
.select()
|
|
180
|
+
.from(table)
|
|
181
|
+
.where(eq(table.version, version))
|
|
182
|
+
.limit(1);
|
|
183
|
+
return results[0] || null;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get pending migrations (scripts that haven't been executed)
|
|
187
|
+
*/
|
|
188
|
+
async getPendingMigrations() {
|
|
189
|
+
// Get all executed migration versions
|
|
190
|
+
const executedMigrations = await this.getMigrations({ status: "completed" });
|
|
191
|
+
const executedVersions = new Set(executedMigrations.map(m => m.version));
|
|
192
|
+
// Get all migration scripts
|
|
193
|
+
const allScripts = await this.loadMigrationScripts();
|
|
194
|
+
// Filter to only pending ones
|
|
195
|
+
return allScripts.filter(script => !executedVersions.has(script.version));
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Load migration scripts from directory
|
|
199
|
+
*/
|
|
200
|
+
async loadMigrationScripts(directory) {
|
|
201
|
+
const scripts = [];
|
|
202
|
+
// Load system migrations first
|
|
203
|
+
const systemScripts = await this.loadScriptsFromDir(this.systemMigrationsDir);
|
|
204
|
+
scripts.push(...systemScripts);
|
|
205
|
+
// Load user migrations
|
|
206
|
+
const userScripts = await this.loadScriptsFromDir(directory || this.migrationsDir);
|
|
207
|
+
scripts.push(...userScripts);
|
|
208
|
+
// Sort by version (semantic versioning or timestamp-based)
|
|
209
|
+
scripts.sort((a, b) => this.compareVersions(a.version, b.version));
|
|
210
|
+
return scripts;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Load scripts from a specific directory
|
|
214
|
+
*/
|
|
215
|
+
async loadScriptsFromDir(dir) {
|
|
216
|
+
const scripts = [];
|
|
217
|
+
try {
|
|
218
|
+
const files = await fs.readdir(dir);
|
|
219
|
+
const migrationFiles = files.filter(f => (f.endsWith(".js") || f.endsWith(".ts")) &&
|
|
220
|
+
!f.endsWith(".d.ts") &&
|
|
221
|
+
!f.startsWith("_"));
|
|
222
|
+
for (const file of migrationFiles) {
|
|
223
|
+
try {
|
|
224
|
+
const filePath = path.join(dir, file);
|
|
225
|
+
// Convert to file:// URL for Windows compatibility
|
|
226
|
+
const module = await import(toFileURL(filePath));
|
|
227
|
+
// Support both default export and named export
|
|
228
|
+
const migration = module.default || module.migration || module;
|
|
229
|
+
if (migration && typeof migration.up === "function" && migration.version) {
|
|
230
|
+
scripts.push({
|
|
231
|
+
version: migration.version,
|
|
232
|
+
name: migration.name || file.replace(/\.(js|ts)$/, ""),
|
|
233
|
+
description: migration.description,
|
|
234
|
+
type: migration.type || "custom",
|
|
235
|
+
canRollback: typeof migration.down === "function",
|
|
236
|
+
up: migration.up,
|
|
237
|
+
down: migration.down,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
console.warn(`MigrationService: Invalid migration file ${file} - missing version or up function`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
console.error(`MigrationService: Error loading migration ${file}:`, error);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
if (error.code !== "ENOENT") {
|
|
251
|
+
console.error(`MigrationService: Error reading migrations directory ${dir}:`, error);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return scripts;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Compare two version strings
|
|
258
|
+
* Supports semver (1.0.0, 1.0.0-alpha.1) and timestamp (20240101_001) formats
|
|
259
|
+
*/
|
|
260
|
+
compareVersions(a, b) {
|
|
261
|
+
// Check if both are semver-like
|
|
262
|
+
const semverRegex = /^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/;
|
|
263
|
+
const matchA = a.match(semverRegex);
|
|
264
|
+
const matchB = b.match(semverRegex);
|
|
265
|
+
if (matchA && matchB) {
|
|
266
|
+
// Compare major.minor.patch
|
|
267
|
+
for (let i = 1; i <= 3; i++) {
|
|
268
|
+
const diff = parseInt(matchA[i]) - parseInt(matchB[i]);
|
|
269
|
+
if (diff !== 0)
|
|
270
|
+
return diff;
|
|
271
|
+
}
|
|
272
|
+
// Compare prerelease
|
|
273
|
+
if (matchA[4] && matchB[4]) {
|
|
274
|
+
return matchA[4].localeCompare(matchB[4]);
|
|
275
|
+
}
|
|
276
|
+
if (matchA[4])
|
|
277
|
+
return -1; // a has prerelease, b doesn't
|
|
278
|
+
if (matchB[4])
|
|
279
|
+
return 1; // b has prerelease, a doesn't
|
|
280
|
+
return 0;
|
|
281
|
+
}
|
|
282
|
+
// Fallback to string comparison
|
|
283
|
+
return a.localeCompare(b);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Calculate checksum for a migration script
|
|
287
|
+
*/
|
|
288
|
+
async calculateChecksum(script) {
|
|
289
|
+
const content = script.up.toString() + (script.down?.toString() || "");
|
|
290
|
+
return crypto.createHash("md5").update(content).digest("hex");
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Run pending migrations
|
|
294
|
+
*/
|
|
295
|
+
async runPendingMigrations(options) {
|
|
296
|
+
await this.init();
|
|
297
|
+
const pendingScripts = await this.getPendingMigrations();
|
|
298
|
+
if (pendingScripts.length === 0) {
|
|
299
|
+
console.info("MigrationService: No pending migrations to run");
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
console.info(`MigrationService: Found ${pendingScripts.length} pending migration(s)`);
|
|
303
|
+
let scriptsToRun = pendingScripts;
|
|
304
|
+
// Apply options
|
|
305
|
+
if (options?.version) {
|
|
306
|
+
scriptsToRun = scriptsToRun.filter(s => s.version === options.version);
|
|
307
|
+
}
|
|
308
|
+
else if (options?.toVersion) {
|
|
309
|
+
scriptsToRun = scriptsToRun.filter(s => this.compareVersions(s.version, options.toVersion) <= 0);
|
|
310
|
+
}
|
|
311
|
+
if (options?.step && options.step > 0) {
|
|
312
|
+
scriptsToRun = scriptsToRun.slice(0, options.step);
|
|
313
|
+
}
|
|
314
|
+
if (scriptsToRun.length === 0) {
|
|
315
|
+
console.info("MigrationService: No migrations match the specified criteria");
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
// Get next batch number
|
|
319
|
+
const batch = await this.getNextBatchNumber();
|
|
320
|
+
const results = [];
|
|
321
|
+
for (const script of scriptsToRun) {
|
|
322
|
+
const result = await this.runMigration(script, batch, options?.dryRun);
|
|
323
|
+
results.push(result);
|
|
324
|
+
// Stop on failure
|
|
325
|
+
if (result.status === "failed") {
|
|
326
|
+
console.error(`MigrationService: Migration ${script.version} failed, stopping`);
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return results;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Run a single migration
|
|
334
|
+
*/
|
|
335
|
+
async runMigration(script, batch, dryRun = false) {
|
|
336
|
+
const db = getDatabase();
|
|
337
|
+
const sqlClient = getSqlClient();
|
|
338
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
339
|
+
this.logs = [];
|
|
340
|
+
const log = (message) => {
|
|
341
|
+
this.logs.push(`[${new Date().toISOString()}] ${message}`);
|
|
342
|
+
console.info(`MigrationService: ${message}`);
|
|
343
|
+
};
|
|
344
|
+
log(`Running migration: ${script.version} - ${script.name}`);
|
|
345
|
+
if (dryRun) {
|
|
346
|
+
log("DRY RUN - Migration will not be executed");
|
|
347
|
+
return {
|
|
348
|
+
version: script.version,
|
|
349
|
+
name: script.name,
|
|
350
|
+
description: script.description,
|
|
351
|
+
type: script.type || "custom",
|
|
352
|
+
status: "pending",
|
|
353
|
+
metadata: { dryRun: true },
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
const checksum = await this.calculateChecksum(script);
|
|
357
|
+
const startTime = Date.now();
|
|
358
|
+
// Create migration record with running status
|
|
359
|
+
const migrationRecord = {
|
|
360
|
+
version: script.version,
|
|
361
|
+
name: script.name,
|
|
362
|
+
description: script.description,
|
|
363
|
+
type: script.type || "custom",
|
|
364
|
+
status: "running",
|
|
365
|
+
batch: batch || await this.getNextBatchNumber(),
|
|
366
|
+
checksum,
|
|
367
|
+
canRollback: !!script.down,
|
|
368
|
+
metadata: { logs: [] },
|
|
369
|
+
};
|
|
370
|
+
// Insert the record
|
|
371
|
+
if (table) {
|
|
372
|
+
await db.insert(table).values(migrationRecord);
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
// Execute the migration
|
|
376
|
+
const context = {
|
|
377
|
+
db,
|
|
378
|
+
sql: sqlClient,
|
|
379
|
+
schemaManager,
|
|
380
|
+
env,
|
|
381
|
+
log,
|
|
382
|
+
};
|
|
383
|
+
const result = await script.up(context);
|
|
384
|
+
const executionTimeMs = Date.now() - startTime;
|
|
385
|
+
// Update record with success
|
|
386
|
+
const updatedRecord = {
|
|
387
|
+
status: "completed",
|
|
388
|
+
executedAt: new Date(),
|
|
389
|
+
executionTimeMs,
|
|
390
|
+
metadata: {
|
|
391
|
+
...result.metadata,
|
|
392
|
+
logs: this.logs,
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
if (table) {
|
|
396
|
+
await db
|
|
397
|
+
.update(table)
|
|
398
|
+
.set(updatedRecord)
|
|
399
|
+
.where(eq(table.version, script.version));
|
|
400
|
+
}
|
|
401
|
+
log(`Migration ${script.version} completed in ${executionTimeMs}ms`);
|
|
402
|
+
return {
|
|
403
|
+
...migrationRecord,
|
|
404
|
+
...updatedRecord,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
const executionTimeMs = Date.now() - startTime;
|
|
409
|
+
// Update record with failure
|
|
410
|
+
const updatedRecord = {
|
|
411
|
+
status: "failed",
|
|
412
|
+
errorMessage: error.message,
|
|
413
|
+
errorStack: error.stack,
|
|
414
|
+
executionTimeMs,
|
|
415
|
+
metadata: {
|
|
416
|
+
logs: this.logs,
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
if (table) {
|
|
420
|
+
await db
|
|
421
|
+
.update(table)
|
|
422
|
+
.set(updatedRecord)
|
|
423
|
+
.where(eq(table.version, script.version));
|
|
424
|
+
}
|
|
425
|
+
console.error(`MigrationService: Migration ${script.version} failed:`, error);
|
|
426
|
+
return {
|
|
427
|
+
...migrationRecord,
|
|
428
|
+
...updatedRecord,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Rollback a migration
|
|
434
|
+
*/
|
|
435
|
+
async rollbackMigration(version) {
|
|
436
|
+
const db = getDatabase();
|
|
437
|
+
const sqlClient = getSqlClient();
|
|
438
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
439
|
+
// Get the migration record
|
|
440
|
+
const migration = await this.getMigrationByVersion(version);
|
|
441
|
+
if (!migration) {
|
|
442
|
+
console.error(`MigrationService: Migration ${version} not found`);
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
if (migration.status !== "completed") {
|
|
446
|
+
console.error(`MigrationService: Migration ${version} is not completed, cannot rollback`);
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
if (!migration.canRollback) {
|
|
450
|
+
console.error(`MigrationService: Migration ${version} does not support rollback`);
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
// Load the script
|
|
454
|
+
const scripts = await this.loadMigrationScripts();
|
|
455
|
+
const script = scripts.find(s => s.version === version);
|
|
456
|
+
if (!script || !script.down) {
|
|
457
|
+
console.error(`MigrationService: Rollback function not found for migration ${version}`);
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
this.logs = [];
|
|
461
|
+
const log = (message) => {
|
|
462
|
+
this.logs.push(`[${new Date().toISOString()}] ${message}`);
|
|
463
|
+
console.info(`MigrationService: ${message}`);
|
|
464
|
+
};
|
|
465
|
+
log(`Rolling back migration: ${version}`);
|
|
466
|
+
const startTime = Date.now();
|
|
467
|
+
try {
|
|
468
|
+
// Execute the rollback
|
|
469
|
+
const context = {
|
|
470
|
+
db,
|
|
471
|
+
sql: sqlClient,
|
|
472
|
+
schemaManager,
|
|
473
|
+
env,
|
|
474
|
+
log,
|
|
475
|
+
};
|
|
476
|
+
await script.down(context);
|
|
477
|
+
const executionTimeMs = Date.now() - startTime;
|
|
478
|
+
// Update record
|
|
479
|
+
if (table) {
|
|
480
|
+
await db
|
|
481
|
+
.update(table)
|
|
482
|
+
.set({
|
|
483
|
+
status: "rolled_back",
|
|
484
|
+
rolledBackAt: new Date(),
|
|
485
|
+
metadata: {
|
|
486
|
+
...migration.metadata,
|
|
487
|
+
rollbackLogs: this.logs,
|
|
488
|
+
rollbackExecutionTimeMs: executionTimeMs,
|
|
489
|
+
},
|
|
490
|
+
})
|
|
491
|
+
.where(eq(table.version, version));
|
|
492
|
+
}
|
|
493
|
+
log(`Migration ${version} rolled back in ${executionTimeMs}ms`);
|
|
494
|
+
return {
|
|
495
|
+
...migration,
|
|
496
|
+
status: "rolled_back",
|
|
497
|
+
rolledBackAt: new Date(),
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
console.error(`MigrationService: Rollback of ${version} failed:`, error);
|
|
502
|
+
if (table) {
|
|
503
|
+
await db
|
|
504
|
+
.update(table)
|
|
505
|
+
.set({
|
|
506
|
+
metadata: {
|
|
507
|
+
...migration.metadata,
|
|
508
|
+
rollbackError: error.message,
|
|
509
|
+
rollbackErrorStack: error.stack,
|
|
510
|
+
},
|
|
511
|
+
})
|
|
512
|
+
.where(eq(table.version, version));
|
|
513
|
+
}
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Rollback the last batch of migrations
|
|
519
|
+
*/
|
|
520
|
+
async rollbackLastBatch() {
|
|
521
|
+
const db = getDatabase();
|
|
522
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
523
|
+
if (!table) {
|
|
524
|
+
return [];
|
|
525
|
+
}
|
|
526
|
+
// Get the last batch number
|
|
527
|
+
const lastBatchResult = await db
|
|
528
|
+
.select({ batch: table.batch })
|
|
529
|
+
.from(table)
|
|
530
|
+
.where(eq(table.status, "completed"))
|
|
531
|
+
.orderBy(desc(table.batch))
|
|
532
|
+
.limit(1);
|
|
533
|
+
if (!lastBatchResult[0]?.batch) {
|
|
534
|
+
console.info("MigrationService: No migrations to rollback");
|
|
535
|
+
return [];
|
|
536
|
+
}
|
|
537
|
+
const lastBatch = lastBatchResult[0].batch;
|
|
538
|
+
// Get all migrations from the last batch
|
|
539
|
+
const migrations = await db
|
|
540
|
+
.select()
|
|
541
|
+
.from(table)
|
|
542
|
+
.where(and(eq(table.status, "completed"), eq(table.batch, lastBatch)))
|
|
543
|
+
.orderBy(desc(table.executedAt));
|
|
544
|
+
const results = [];
|
|
545
|
+
for (const migration of migrations) {
|
|
546
|
+
const result = await this.rollbackMigration(migration.version);
|
|
547
|
+
if (result) {
|
|
548
|
+
results.push(result);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return results;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Get the next batch number
|
|
555
|
+
*/
|
|
556
|
+
async getNextBatchNumber() {
|
|
557
|
+
const db = getDatabase();
|
|
558
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
559
|
+
if (!table) {
|
|
560
|
+
return 1;
|
|
561
|
+
}
|
|
562
|
+
const result = await db
|
|
563
|
+
.select({ maxBatch: sql `COALESCE(MAX(${table.batch}), 0)` })
|
|
564
|
+
.from(table);
|
|
565
|
+
return (result[0]?.maxBatch || 0) + 1;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Get migration status summary
|
|
569
|
+
*/
|
|
570
|
+
async getStatus() {
|
|
571
|
+
await this.init();
|
|
572
|
+
const [lastMigration, pendingMigrations, allMigrations] = await Promise.all([
|
|
573
|
+
this.getLastMigration(),
|
|
574
|
+
this.getPendingMigrations(),
|
|
575
|
+
this.getMigrations(),
|
|
576
|
+
]);
|
|
577
|
+
return {
|
|
578
|
+
lastMigration,
|
|
579
|
+
pendingCount: pendingMigrations.length,
|
|
580
|
+
completedCount: allMigrations.filter(m => m.status === "completed").length,
|
|
581
|
+
failedCount: allMigrations.filter(m => m.status === "failed").length,
|
|
582
|
+
pending: pendingMigrations,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Create a new migration file
|
|
587
|
+
*/
|
|
588
|
+
async createMigration(name, options) {
|
|
589
|
+
await this.init();
|
|
590
|
+
// Generate version based on timestamp if not provided
|
|
591
|
+
const timestamp = new Date().toISOString().replace(/[-:T]/g, "").slice(0, 14);
|
|
592
|
+
const version = options?.version || `${timestamp}_${name.toLowerCase().replace(/\s+/g, "_")}`;
|
|
593
|
+
const filename = `${version}.ts`;
|
|
594
|
+
const filepath = path.join(this.migrationsDir, filename);
|
|
595
|
+
const template = `/**
|
|
596
|
+
* Migration: ${name}
|
|
597
|
+
* Version: ${version}
|
|
598
|
+
* Type: ${options?.type || "custom"}
|
|
599
|
+
* Description: ${options?.description || ""}
|
|
600
|
+
*
|
|
601
|
+
* Created: ${new Date().toISOString()}
|
|
602
|
+
*/
|
|
603
|
+
|
|
604
|
+
import type { MigrationContext, MigrationResult } from "@baasix/baasix";
|
|
605
|
+
|
|
606
|
+
export const version = "${version}";
|
|
607
|
+
export const name = "${name}";
|
|
608
|
+
export const description = "${options?.description || ""}";
|
|
609
|
+
export const type = "${options?.type || "custom"}";
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Run the migration
|
|
613
|
+
*/
|
|
614
|
+
export async function up(context: MigrationContext): Promise<MigrationResult> {
|
|
615
|
+
const { db, sql, schemaManager, log } = context;
|
|
616
|
+
|
|
617
|
+
log("Starting migration...");
|
|
618
|
+
|
|
619
|
+
// TODO: Add your migration logic here
|
|
620
|
+
// Example: Add a new column
|
|
621
|
+
// await sql\`ALTER TABLE "my_table" ADD COLUMN "new_column" TEXT\`;
|
|
622
|
+
|
|
623
|
+
// Example: Create a new table
|
|
624
|
+
// await sql\`CREATE TABLE IF NOT EXISTS "new_table" (
|
|
625
|
+
// id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
626
|
+
// name TEXT NOT NULL
|
|
627
|
+
// )\`;
|
|
628
|
+
|
|
629
|
+
// Example: Update data
|
|
630
|
+
// await db.update(someTable).set({ field: "value" }).where(condition);
|
|
631
|
+
|
|
632
|
+
log("Migration completed successfully");
|
|
633
|
+
|
|
634
|
+
return {
|
|
635
|
+
success: true,
|
|
636
|
+
message: "Migration completed",
|
|
637
|
+
metadata: {
|
|
638
|
+
// Add any relevant metadata about what was changed
|
|
639
|
+
},
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Rollback the migration (optional)
|
|
645
|
+
*/
|
|
646
|
+
export async function down(context: MigrationContext): Promise<MigrationResult> {
|
|
647
|
+
const { db, sql, log } = context;
|
|
648
|
+
|
|
649
|
+
log("Rolling back migration...");
|
|
650
|
+
|
|
651
|
+
// TODO: Add your rollback logic here
|
|
652
|
+
// This should undo everything done in the up function
|
|
653
|
+
|
|
654
|
+
log("Rollback completed successfully");
|
|
655
|
+
|
|
656
|
+
return {
|
|
657
|
+
success: true,
|
|
658
|
+
message: "Rollback completed",
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
export default { version, name, description, type, up, down };
|
|
663
|
+
`;
|
|
664
|
+
await fs.writeFile(filepath, template, "utf-8");
|
|
665
|
+
console.info(`MigrationService: Created migration file ${filepath}`);
|
|
666
|
+
return filepath;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Check and run migrations on startup if enabled
|
|
670
|
+
* This should be called during app initialization
|
|
671
|
+
*/
|
|
672
|
+
async runStartupMigrations() {
|
|
673
|
+
const autoRun = env.get("MIGRATIONS_AUTO_RUN") === "true";
|
|
674
|
+
// Handle upgrade from Sequelize version
|
|
675
|
+
if (this.isUpgradeFromSequelize) {
|
|
676
|
+
console.info("MigrationService: ========================================");
|
|
677
|
+
console.info("MigrationService: SEQUELIZE TO DRIZZLE UPGRADE DETECTED");
|
|
678
|
+
console.info("MigrationService: ========================================");
|
|
679
|
+
await this.handleSequelizeUpgrade();
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
if (!autoRun) {
|
|
683
|
+
console.info("MigrationService: Auto-run disabled (set MIGRATIONS_AUTO_RUN=true to enable)");
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
console.info("MigrationService: Running startup migrations...");
|
|
687
|
+
try {
|
|
688
|
+
const results = await this.runPendingMigrations();
|
|
689
|
+
if (results.length > 0) {
|
|
690
|
+
const completed = results.filter(r => r.status === "completed").length;
|
|
691
|
+
const failed = results.filter(r => r.status === "failed").length;
|
|
692
|
+
console.info(`MigrationService: Startup migrations completed. Success: ${completed}, Failed: ${failed}`);
|
|
693
|
+
if (failed > 0) {
|
|
694
|
+
console.error("MigrationService: Some migrations failed. Check the baasix_Migration table for details.");
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
catch (error) {
|
|
699
|
+
console.error("MigrationService: Error running startup migrations:", error);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Handle upgrade from Sequelize version
|
|
704
|
+
* This runs the baseline migration (to handle fullName, etc.) and marks
|
|
705
|
+
* all other migrations up to the upgrade baseline as completed
|
|
706
|
+
*/
|
|
707
|
+
async handleSequelizeUpgrade() {
|
|
708
|
+
const baselineVersion = env.get("MIGRATIONS_UPGRADE_BASELINE") || await this.getCurrentBaasixVersion();
|
|
709
|
+
console.info(`MigrationService: Setting migration baseline to version: ${baselineVersion}`);
|
|
710
|
+
console.info("MigrationService: Running baseline migration and marking others as completed");
|
|
711
|
+
try {
|
|
712
|
+
// Get all pending migrations
|
|
713
|
+
const pendingScripts = await this.getPendingMigrations();
|
|
714
|
+
// Find the initial/baseline migration (0.1.0-alpha.0) - this one should RUN
|
|
715
|
+
// because it handles the fullName virtual field conversion
|
|
716
|
+
const baselineMigration = pendingScripts.find(s => s.version === "0.1.0-alpha.0");
|
|
717
|
+
// Get migrations that should be marked as completed (not run)
|
|
718
|
+
const migrationsToMark = pendingScripts.filter(s => s.version !== "0.1.0-alpha.0" &&
|
|
719
|
+
this.compareVersions(s.version, baselineVersion) <= 0);
|
|
720
|
+
// Run the baseline migration first (if exists and pending)
|
|
721
|
+
if (baselineMigration) {
|
|
722
|
+
console.info("MigrationService: Running baseline migration (handles Sequelize virtual fields)...");
|
|
723
|
+
const batch = await this.getNextBatchNumber();
|
|
724
|
+
const result = await this.runMigration(baselineMigration, batch);
|
|
725
|
+
if (result.status === "failed") {
|
|
726
|
+
console.error("MigrationService: Baseline migration failed:", result.errorMessage);
|
|
727
|
+
throw new Error(`Baseline migration failed: ${result.errorMessage}`);
|
|
728
|
+
}
|
|
729
|
+
console.info("MigrationService: Baseline migration completed successfully");
|
|
730
|
+
}
|
|
731
|
+
// Mark other migrations as completed (without running them)
|
|
732
|
+
if (migrationsToMark.length > 0) {
|
|
733
|
+
console.info(`MigrationService: Marking ${migrationsToMark.length} migration(s) as completed...`);
|
|
734
|
+
for (const script of migrationsToMark) {
|
|
735
|
+
await this.markAsCompleted(script.version, {
|
|
736
|
+
metadata: {
|
|
737
|
+
sequelizeUpgrade: true,
|
|
738
|
+
skippedExecution: true,
|
|
739
|
+
},
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
// Now run any migrations AFTER the baseline (if auto-run is enabled)
|
|
744
|
+
const autoRun = env.get("MIGRATIONS_AUTO_RUN") === "true";
|
|
745
|
+
if (autoRun) {
|
|
746
|
+
const pending = await this.getPendingMigrations();
|
|
747
|
+
if (pending.length > 0) {
|
|
748
|
+
console.info(`MigrationService: Running ${pending.length} pending migration(s) after baseline...`);
|
|
749
|
+
const results = await this.runPendingMigrations();
|
|
750
|
+
const completed = results.filter(r => r.status === "completed").length;
|
|
751
|
+
const failed = results.filter(r => r.status === "failed").length;
|
|
752
|
+
console.info(`MigrationService: Post-upgrade migrations completed. Success: ${completed}, Failed: ${failed}`);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
console.info("MigrationService: ========================================");
|
|
756
|
+
console.info("MigrationService: UPGRADE COMPLETE");
|
|
757
|
+
console.info("MigrationService: ========================================");
|
|
758
|
+
// Clear the flag so it doesn't run again
|
|
759
|
+
this.isUpgradeFromSequelize = false;
|
|
760
|
+
}
|
|
761
|
+
catch (error) {
|
|
762
|
+
console.error("MigrationService: Error handling Sequelize upgrade:", error);
|
|
763
|
+
throw error;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Set the user migrations directory
|
|
768
|
+
*/
|
|
769
|
+
setMigrationsDir(dir) {
|
|
770
|
+
this.migrationsDir = dir;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Get the current migrations directory
|
|
774
|
+
*/
|
|
775
|
+
getMigrationsDir() {
|
|
776
|
+
return this.migrationsDir;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Mark a migration as completed without running it
|
|
780
|
+
* Useful for existing installations that already have the changes
|
|
781
|
+
*/
|
|
782
|
+
async markAsCompleted(version, options) {
|
|
783
|
+
await this.init();
|
|
784
|
+
const db = getDatabase();
|
|
785
|
+
const table = schemaManager.getTable("baasix_Migration");
|
|
786
|
+
if (!table) {
|
|
787
|
+
console.error("MigrationService: Migration table not available");
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
// Check if migration already exists
|
|
791
|
+
const existing = await this.getMigrationByVersion(version);
|
|
792
|
+
if (existing) {
|
|
793
|
+
if (existing.status === "completed") {
|
|
794
|
+
console.info(`MigrationService: Migration ${version} is already completed`);
|
|
795
|
+
return existing;
|
|
796
|
+
}
|
|
797
|
+
// Update existing record
|
|
798
|
+
await db
|
|
799
|
+
.update(table)
|
|
800
|
+
.set({
|
|
801
|
+
status: "completed",
|
|
802
|
+
executedAt: new Date(),
|
|
803
|
+
metadata: {
|
|
804
|
+
...existing.metadata,
|
|
805
|
+
...options?.metadata,
|
|
806
|
+
markedAsCompleted: true,
|
|
807
|
+
},
|
|
808
|
+
})
|
|
809
|
+
.where(eq(table.version, version));
|
|
810
|
+
return {
|
|
811
|
+
...existing,
|
|
812
|
+
status: "completed",
|
|
813
|
+
executedAt: new Date(),
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
// Load the script to get metadata
|
|
817
|
+
const scripts = await this.loadMigrationScripts();
|
|
818
|
+
const script = scripts.find(s => s.version === version);
|
|
819
|
+
if (!script) {
|
|
820
|
+
console.error(`MigrationService: Migration script ${version} not found`);
|
|
821
|
+
return null;
|
|
822
|
+
}
|
|
823
|
+
// Create new record marked as completed
|
|
824
|
+
const checksum = await this.calculateChecksum(script);
|
|
825
|
+
const batch = await this.getNextBatchNumber();
|
|
826
|
+
const record = {
|
|
827
|
+
version: script.version,
|
|
828
|
+
name: script.name,
|
|
829
|
+
description: script.description,
|
|
830
|
+
type: script.type || "custom",
|
|
831
|
+
status: "completed",
|
|
832
|
+
batch,
|
|
833
|
+
executedAt: new Date(),
|
|
834
|
+
checksum,
|
|
835
|
+
canRollback: !!script.down,
|
|
836
|
+
metadata: {
|
|
837
|
+
...options?.metadata,
|
|
838
|
+
markedAsCompleted: true,
|
|
839
|
+
skippedExecution: true,
|
|
840
|
+
},
|
|
841
|
+
};
|
|
842
|
+
await db.insert(table).values(record);
|
|
843
|
+
console.info(`MigrationService: Migration ${version} marked as completed`);
|
|
844
|
+
return record;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Mark all migrations up to a version as completed
|
|
848
|
+
* Useful for bringing an existing database up to date without running migrations
|
|
849
|
+
*/
|
|
850
|
+
async markAllAsCompleted(toVersion) {
|
|
851
|
+
await this.init();
|
|
852
|
+
const pendingScripts = await this.getPendingMigrations();
|
|
853
|
+
let scriptsToMark = pendingScripts;
|
|
854
|
+
if (toVersion) {
|
|
855
|
+
scriptsToMark = scriptsToMark.filter(s => this.compareVersions(s.version, toVersion) <= 0);
|
|
856
|
+
}
|
|
857
|
+
const results = [];
|
|
858
|
+
for (const script of scriptsToMark) {
|
|
859
|
+
const result = await this.markAsCompleted(script.version, {
|
|
860
|
+
metadata: { bulkMarked: true },
|
|
861
|
+
});
|
|
862
|
+
if (result) {
|
|
863
|
+
results.push(result);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
console.info(`MigrationService: Marked ${results.length} migration(s) as completed`);
|
|
867
|
+
return results;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Get the current Baasix version from package.json
|
|
871
|
+
*/
|
|
872
|
+
async getCurrentBaasixVersion() {
|
|
873
|
+
try {
|
|
874
|
+
const packagePath = getProjectPath("node_modules", "@baasix", "baasix", "package.json");
|
|
875
|
+
const packageJson = JSON.parse(await fs.readFile(packagePath, "utf-8"));
|
|
876
|
+
return packageJson.version;
|
|
877
|
+
}
|
|
878
|
+
catch {
|
|
879
|
+
// Try direct package.json if running from source
|
|
880
|
+
try {
|
|
881
|
+
const packagePath = getBaasixPath("package.json");
|
|
882
|
+
const packageJson = JSON.parse(await fs.readFile(packagePath, "utf-8"));
|
|
883
|
+
return packageJson.version;
|
|
884
|
+
}
|
|
885
|
+
catch {
|
|
886
|
+
return "unknown";
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Check if database needs migrations based on current version
|
|
892
|
+
*/
|
|
893
|
+
async checkMigrationNeeded() {
|
|
894
|
+
const [lastMigration, pending, currentVersion] = await Promise.all([
|
|
895
|
+
this.getLastMigration(),
|
|
896
|
+
this.getPendingMigrations(),
|
|
897
|
+
this.getCurrentBaasixVersion(),
|
|
898
|
+
]);
|
|
899
|
+
return {
|
|
900
|
+
needed: pending.length > 0,
|
|
901
|
+
lastVersion: lastMigration?.version || null,
|
|
902
|
+
currentVersion,
|
|
903
|
+
pendingCount: pending.length,
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
// Create singleton instance only if it doesn't exist
|
|
908
|
+
if (!globalThis.__baasix_migrationService) {
|
|
909
|
+
globalThis.__baasix_migrationService = new MigrationService();
|
|
910
|
+
}
|
|
911
|
+
const migrationService = globalThis.__baasix_migrationService;
|
|
912
|
+
export default migrationService;
|
|
913
|
+
export { MigrationService };
|
|
914
|
+
//# sourceMappingURL=MigrationService.js.map
|