@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.
Files changed (666) hide show
  1. package/LICENSE.MD +85 -0
  2. package/README.md +526 -0
  3. package/assets/banner.jpg +0 -0
  4. package/assets/banner_small.jpg +0 -0
  5. package/assets/logo_icon.svg +20 -0
  6. package/assets/logo_icon_rounded.svg +20 -0
  7. package/dist/LICENSE.MD +85 -0
  8. package/dist/README.md +526 -0
  9. package/dist/app/404/index.html +1 -0
  10. package/dist/app/404.html +1 -0
  11. package/dist/app/_next/static/chunks/041e1f03-56ae8a902a7f2fe6.js +24 -0
  12. package/dist/app/_next/static/chunks/1117-05479929a8da73e3.js +1 -0
  13. package/dist/app/_next/static/chunks/1299.77cc7b7b76b75cba.js +1 -0
  14. package/dist/app/_next/static/chunks/1303-35a96e9c9cdeab9d.js +1 -0
  15. package/dist/app/_next/static/chunks/1509-56ac00cdaaecdf53.js +1 -0
  16. package/dist/app/_next/static/chunks/1668-e3eabd0f6753c780.js +1 -0
  17. package/dist/app/_next/static/chunks/1783-d9fb550fd324300c.js +1 -0
  18. package/dist/app/_next/static/chunks/2117-29b5fa47421595ad.js +2 -0
  19. package/dist/app/_next/static/chunks/2344.35b46d2179a765b5.js +1 -0
  20. package/dist/app/_next/static/chunks/257.990da16794a31292.js +1 -0
  21. package/dist/app/_next/static/chunks/2676-73b0ee7c80073a84.js +1 -0
  22. package/dist/app/_next/static/chunks/3563-b8842744384391fe.js +1 -0
  23. package/dist/app/_next/static/chunks/363642f4-933b579ed3c85f60.js +1 -0
  24. package/dist/app/_next/static/chunks/3817-e20c8f0a0810fc95.js +1 -0
  25. package/dist/app/_next/static/chunks/3834.84944e390d902509.js +2 -0
  26. package/dist/app/_next/static/chunks/4043-3a30c8a75896f241.js +1 -0
  27. package/dist/app/_next/static/chunks/4225-14090c7c0cd9dec6.js +1 -0
  28. package/dist/app/_next/static/chunks/4438-c9a12ca15b6e9160.js +1 -0
  29. package/dist/app/_next/static/chunks/4458-679fd0c6884f456a.js +1 -0
  30. package/dist/app/_next/static/chunks/4475-8bdfbd536fba8c48.js +1 -0
  31. package/dist/app/_next/static/chunks/4883-8a924721bb21b3b0.js +1 -0
  32. package/dist/app/_next/static/chunks/489-683ab07188f9df2b.js +1 -0
  33. package/dist/app/_next/static/chunks/4952-1b97320cf61f3f21.js +1 -0
  34. package/dist/app/_next/static/chunks/5094-8d53e403235d4ca6.js +1 -0
  35. package/dist/app/_next/static/chunks/5101-3a146e0625747ad1.js +1 -0
  36. package/dist/app/_next/static/chunks/54a60aa6-d9747982e0a81f58.js +79 -0
  37. package/dist/app/_next/static/chunks/5650-f096291df402bfc2.js +1 -0
  38. package/dist/app/_next/static/chunks/600-539045311240f579.js +1 -0
  39. package/dist/app/_next/static/chunks/6170-803b82e19d3ade6d.js +89 -0
  40. package/dist/app/_next/static/chunks/6241-30d7169d1010e5a4.js +1 -0
  41. package/dist/app/_next/static/chunks/6530-a91e10cffa4200c4.js +1 -0
  42. package/dist/app/_next/static/chunks/6547-4bbbdb5c399aef1e.js +1 -0
  43. package/dist/app/_next/static/chunks/6712-781937c53a2c49da.js +1 -0
  44. package/dist/app/_next/static/chunks/6fcbdc68-90be1a5480b8d353.js +1 -0
  45. package/dist/app/_next/static/chunks/70e0d97a-aeaf0cdc26ba1a58.js +1 -0
  46. package/dist/app/_next/static/chunks/7214-5154a89d08d24dde.js +1 -0
  47. package/dist/app/_next/static/chunks/7324-b53229c59a640880.js +10 -0
  48. package/dist/app/_next/static/chunks/7636-66424f0b51d350e9.js +1 -0
  49. package/dist/app/_next/static/chunks/7874-39a3f2541165a675.js +1 -0
  50. package/dist/app/_next/static/chunks/7982-9da12b83f11e3f5f.js +1 -0
  51. package/dist/app/_next/static/chunks/8213a2eb-da25a3b3c5521b2b.js +1 -0
  52. package/dist/app/_next/static/chunks/8473-6598318371eca31b.js +1 -0
  53. package/dist/app/_next/static/chunks/8640fa6b-72e43370f68e5587.js +1 -0
  54. package/dist/app/_next/static/chunks/9090-3ef676f29c95f1c7.js +1 -0
  55. package/dist/app/_next/static/chunks/9124-a02f9e209e6e3cce.js +1 -0
  56. package/dist/app/_next/static/chunks/926-156f32067d111d6b.js +1 -0
  57. package/dist/app/_next/static/chunks/9487-b17481605e513b83.js +1 -0
  58. package/dist/app/_next/static/chunks/9599-a7e572bb88c3392b.js +1 -0
  59. package/dist/app/_next/static/chunks/9881-419697138376e755.js +1 -0
  60. package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/all-activity/page-8917930b4d663405.js +1 -0
  61. package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/email-log/page-b27a6ee32782d7df.js +1 -0
  62. package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/notifications/page-b7eda523ede2702c.js +1 -0
  63. package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/page-1cfa62d1caedaed0.js +1 -0
  64. package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/sessions/page-3e21e20db90aeff7.js +1 -0
  65. package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/workflow-executions/page-27bcc26b747fb29b.js +1 -0
  66. package/dist/app/_next/static/chunks/app/(authenticated)/activity-log/workflow-logs/page-9f9e9e952aef436e.js +1 -0
  67. package/dist/app/_next/static/chunks/app/(authenticated)/change-password/page-8d61aa499eabb127.js +1 -0
  68. package/dist/app/_next/static/chunks/app/(authenticated)/dashboard/page-1ceeac9e72997a8a.js +1 -0
  69. package/dist/app/_next/static/chunks/app/(authenticated)/data-browser/page-8cda2b57759dd670.js +1 -0
  70. package/dist/app/_next/static/chunks/app/(authenticated)/file-manager/page-8c6f1b1da66ad7e4.js +1 -0
  71. package/dist/app/_next/static/chunks/app/(authenticated)/layout-f70d225b2759c998.js +1 -0
  72. package/dist/app/_next/static/chunks/app/(authenticated)/settings/migrations/page-aacec8f7cfb40ab2.js +1 -0
  73. package/dist/app/_next/static/chunks/app/(authenticated)/settings/permissions/page-828110cfcde429c6.js +1 -0
  74. package/dist/app/_next/static/chunks/app/(authenticated)/settings/project/page-420e794bb76bd204.js +1 -0
  75. package/dist/app/_next/static/chunks/app/(authenticated)/settings/roles/page-9001d02b28f70708.js +1 -0
  76. package/dist/app/_next/static/chunks/app/(authenticated)/settings/schema/page-899574f35091dd58.js +1 -0
  77. package/dist/app/_next/static/chunks/app/(authenticated)/settings/tasks/page-ad7ab3e27c83f44f.js +1 -0
  78. package/dist/app/_next/static/chunks/app/(authenticated)/settings/templates/edit/page-bd83414cb8c4cb04.js +1 -0
  79. package/dist/app/_next/static/chunks/app/(authenticated)/settings/templates/page-3181447f8772b1d3.js +1 -0
  80. package/dist/app/_next/static/chunks/app/(authenticated)/settings/tenants/page-ef9bfbacef5a1d73.js +1 -0
  81. package/dist/app/_next/static/chunks/app/(authenticated)/users/invites/page-480306b7b2bbac7e.js +1 -0
  82. package/dist/app/_next/static/chunks/app/(authenticated)/users/list/page-74da51254c2606b3.js +1 -0
  83. package/dist/app/_next/static/chunks/app/(authenticated)/users/page-e99c6f0b915001b2.js +1 -0
  84. package/dist/app/_next/static/chunks/app/(authenticated)/users/preferences/page-1a935630ce8f2b12.js +1 -0
  85. package/dist/app/_next/static/chunks/app/(authenticated)/users/user-roles/page-901dfb8ea1f39ca8.js +1 -0
  86. package/dist/app/_next/static/chunks/app/(authenticated)/workflows/detail/page-9a6b839aea688ca4.js +1 -0
  87. package/dist/app/_next/static/chunks/app/(authenticated)/workflows/edit/page-11774efbc2fecae2.js +1 -0
  88. package/dist/app/_next/static/chunks/app/(authenticated)/workflows/execution/page-8ec1aea90412c03d.js +1 -0
  89. package/dist/app/_next/static/chunks/app/(authenticated)/workflows/page-88bc5b36ccb0a1f7.js +1 -0
  90. package/dist/app/_next/static/chunks/app/(public)/forgot-password/page-ed263fd46ef81c20.js +1 -0
  91. package/dist/app/_next/static/chunks/app/(public)/layout-f538977545844af8.js +1 -0
  92. package/dist/app/_next/static/chunks/app/(public)/login/page-c0a10b137f346096.js +1 -0
  93. package/dist/app/_next/static/chunks/app/(public)/register/page-4cb7644893efd9b3.js +1 -0
  94. package/dist/app/_next/static/chunks/app/_not-found/page-653f8815b78256cc.js +1 -0
  95. package/dist/app/_next/static/chunks/app/layout-591ca7a3e16528a1.js +1 -0
  96. package/dist/app/_next/static/chunks/app/page-dd19d124b5fa2577.js +1 -0
  97. package/dist/app/_next/static/chunks/c37d3baf.c2ff165f5b02c692.js +1 -0
  98. package/dist/app/_next/static/chunks/d0deef33.0379166a4ec23470.js +1 -0
  99. package/dist/app/_next/static/chunks/fd9d1056-54169f07cd680d6c.js +1 -0
  100. package/dist/app/_next/static/chunks/framework-8e0e0f4a6b83a956.js +1 -0
  101. package/dist/app/_next/static/chunks/main-324e91f5a430cddf.js +1 -0
  102. package/dist/app/_next/static/chunks/main-app-55bcae20c77aaf0e.js +1 -0
  103. package/dist/app/_next/static/chunks/pages/_app-3c9ca398d360b709.js +1 -0
  104. package/dist/app/_next/static/chunks/pages/_error-cf5ca766ac8f493f.js +1 -0
  105. package/dist/app/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  106. package/dist/app/_next/static/chunks/webpack-2c306566f7ee1b63.js +1 -0
  107. package/dist/app/_next/static/css/6c4002bae4e236b2.css +3 -0
  108. package/dist/app/_next/static/css/a275cc2b185e04f8.css +1 -0
  109. package/dist/app/_next/static/eCWhKA8XHqmB1zgFcEtN2/_buildManifest.js +1 -0
  110. package/dist/app/_next/static/eCWhKA8XHqmB1zgFcEtN2/_ssgManifest.js +1 -0
  111. package/dist/app/activity-log/all-activity/index.html +1 -0
  112. package/dist/app/activity-log/all-activity/index.txt +14 -0
  113. package/dist/app/activity-log/email-log/index.html +1 -0
  114. package/dist/app/activity-log/email-log/index.txt +14 -0
  115. package/dist/app/activity-log/index.html +1 -0
  116. package/dist/app/activity-log/index.txt +14 -0
  117. package/dist/app/activity-log/notifications/index.html +1 -0
  118. package/dist/app/activity-log/notifications/index.txt +14 -0
  119. package/dist/app/activity-log/sessions/index.html +1 -0
  120. package/dist/app/activity-log/sessions/index.txt +14 -0
  121. package/dist/app/activity-log/workflow-executions/index.html +1 -0
  122. package/dist/app/activity-log/workflow-executions/index.txt +14 -0
  123. package/dist/app/activity-log/workflow-logs/index.html +1 -0
  124. package/dist/app/activity-log/workflow-logs/index.txt +14 -0
  125. package/dist/app/change-password/index.html +1 -0
  126. package/dist/app/change-password/index.txt +14 -0
  127. package/dist/app/dashboard/index.html +1 -0
  128. package/dist/app/dashboard/index.txt +14 -0
  129. package/dist/app/data-browser/index.html +1 -0
  130. package/dist/app/data-browser/index.txt +14 -0
  131. package/dist/app/file-manager/index.html +1 -0
  132. package/dist/app/file-manager/index.txt +14 -0
  133. package/dist/app/forgot-password/index.html +1 -0
  134. package/dist/app/forgot-password/index.txt +13 -0
  135. package/dist/app/index.html +1 -0
  136. package/dist/app/index.txt +9 -0
  137. package/dist/app/login/index.html +1 -0
  138. package/dist/app/login/index.txt +13 -0
  139. package/dist/app/logo-dark.png +0 -0
  140. package/dist/app/logo-icon.svg +81 -0
  141. package/dist/app/logo-light.png +0 -0
  142. package/dist/app/register/index.html +1 -0
  143. package/dist/app/register/index.txt +13 -0
  144. package/dist/app/settings/migrations/index.html +1 -0
  145. package/dist/app/settings/migrations/index.txt +14 -0
  146. package/dist/app/settings/permissions/index.html +1 -0
  147. package/dist/app/settings/permissions/index.txt +14 -0
  148. package/dist/app/settings/project/index.html +1 -0
  149. package/dist/app/settings/project/index.txt +14 -0
  150. package/dist/app/settings/roles/index.html +1 -0
  151. package/dist/app/settings/roles/index.txt +14 -0
  152. package/dist/app/settings/schema/index.html +1 -0
  153. package/dist/app/settings/schema/index.txt +14 -0
  154. package/dist/app/settings/tasks/index.html +1 -0
  155. package/dist/app/settings/tasks/index.txt +14 -0
  156. package/dist/app/settings/templates/edit/index.html +1 -0
  157. package/dist/app/settings/templates/edit/index.txt +14 -0
  158. package/dist/app/settings/templates/index.html +1 -0
  159. package/dist/app/settings/templates/index.txt +14 -0
  160. package/dist/app/settings/tenants/index.html +1 -0
  161. package/dist/app/settings/tenants/index.txt +14 -0
  162. package/dist/app/users/index.html +1 -0
  163. package/dist/app/users/index.txt +14 -0
  164. package/dist/app/users/invites/index.html +1 -0
  165. package/dist/app/users/invites/index.txt +14 -0
  166. package/dist/app/users/list/index.html +1 -0
  167. package/dist/app/users/list/index.txt +14 -0
  168. package/dist/app/users/preferences/index.html +1 -0
  169. package/dist/app/users/preferences/index.txt +14 -0
  170. package/dist/app/users/user-roles/index.html +1 -0
  171. package/dist/app/users/user-roles/index.txt +14 -0
  172. package/dist/app/workflows/detail/index.html +1 -0
  173. package/dist/app/workflows/detail/index.txt +14 -0
  174. package/dist/app/workflows/edit/index.html +1 -0
  175. package/dist/app/workflows/edit/index.txt +14 -0
  176. package/dist/app/workflows/execution/index.html +1 -0
  177. package/dist/app/workflows/execution/index.txt +14 -0
  178. package/dist/app/workflows/index.html +1 -0
  179. package/dist/app/workflows/index.txt +14 -0
  180. package/dist/app.d.ts +36 -0
  181. package/dist/app.d.ts.map +1 -0
  182. package/dist/app.js +546 -0
  183. package/dist/app.js.map +1 -0
  184. package/dist/auth/adapters/baasix-adapter.d.ts +12 -0
  185. package/dist/auth/adapters/baasix-adapter.d.ts.map +1 -0
  186. package/dist/auth/adapters/baasix-adapter.js +318 -0
  187. package/dist/auth/adapters/baasix-adapter.js.map +1 -0
  188. package/dist/auth/adapters/index.d.ts +6 -0
  189. package/dist/auth/adapters/index.d.ts.map +1 -0
  190. package/dist/auth/adapters/index.js +5 -0
  191. package/dist/auth/adapters/index.js.map +1 -0
  192. package/dist/auth/core.d.ts +73 -0
  193. package/dist/auth/core.d.ts.map +1 -0
  194. package/dist/auth/core.js +528 -0
  195. package/dist/auth/core.js.map +1 -0
  196. package/dist/auth/index.d.ts +56 -0
  197. package/dist/auth/index.d.ts.map +1 -0
  198. package/dist/auth/index.js +58 -0
  199. package/dist/auth/index.js.map +1 -0
  200. package/dist/auth/oauth2/index.d.ts +5 -0
  201. package/dist/auth/oauth2/index.d.ts.map +1 -0
  202. package/dist/auth/oauth2/index.js +5 -0
  203. package/dist/auth/oauth2/index.js.map +1 -0
  204. package/dist/auth/oauth2/utils.d.ts +90 -0
  205. package/dist/auth/oauth2/utils.d.ts.map +1 -0
  206. package/dist/auth/oauth2/utils.js +167 -0
  207. package/dist/auth/oauth2/utils.js.map +1 -0
  208. package/dist/auth/providers/apple.d.ts +28 -0
  209. package/dist/auth/providers/apple.d.ts.map +1 -0
  210. package/dist/auth/providers/apple.js +192 -0
  211. package/dist/auth/providers/apple.js.map +1 -0
  212. package/dist/auth/providers/credential.d.ts +87 -0
  213. package/dist/auth/providers/credential.d.ts.map +1 -0
  214. package/dist/auth/providers/credential.js +162 -0
  215. package/dist/auth/providers/credential.js.map +1 -0
  216. package/dist/auth/providers/facebook.d.ts +26 -0
  217. package/dist/auth/providers/facebook.d.ts.map +1 -0
  218. package/dist/auth/providers/facebook.js +112 -0
  219. package/dist/auth/providers/facebook.js.map +1 -0
  220. package/dist/auth/providers/github.d.ts +29 -0
  221. package/dist/auth/providers/github.d.ts.map +1 -0
  222. package/dist/auth/providers/github.js +144 -0
  223. package/dist/auth/providers/github.js.map +1 -0
  224. package/dist/auth/providers/google.d.ts +32 -0
  225. package/dist/auth/providers/google.d.ts.map +1 -0
  226. package/dist/auth/providers/google.js +145 -0
  227. package/dist/auth/providers/google.js.map +1 -0
  228. package/dist/auth/providers/index.d.ts +22 -0
  229. package/dist/auth/providers/index.d.ts.map +1 -0
  230. package/dist/auth/providers/index.js +17 -0
  231. package/dist/auth/providers/index.js.map +1 -0
  232. package/dist/auth/routes.d.ts +63 -0
  233. package/dist/auth/routes.d.ts.map +1 -0
  234. package/dist/auth/routes.js +827 -0
  235. package/dist/auth/routes.js.map +1 -0
  236. package/dist/auth/services/index.d.ts +10 -0
  237. package/dist/auth/services/index.d.ts.map +1 -0
  238. package/dist/auth/services/index.js +7 -0
  239. package/dist/auth/services/index.js.map +1 -0
  240. package/dist/auth/services/session.d.ts +81 -0
  241. package/dist/auth/services/session.d.ts.map +1 -0
  242. package/dist/auth/services/session.js +186 -0
  243. package/dist/auth/services/session.js.map +1 -0
  244. package/dist/auth/services/token.d.ts +41 -0
  245. package/dist/auth/services/token.d.ts.map +1 -0
  246. package/dist/auth/services/token.js +44 -0
  247. package/dist/auth/services/token.js.map +1 -0
  248. package/dist/auth/services/verification.d.ts +77 -0
  249. package/dist/auth/services/verification.d.ts.map +1 -0
  250. package/dist/auth/services/verification.js +143 -0
  251. package/dist/auth/services/verification.js.map +1 -0
  252. package/dist/auth/types.d.ts +318 -0
  253. package/dist/auth/types.d.ts.map +1 -0
  254. package/dist/auth/types.js +6 -0
  255. package/dist/auth/types.js.map +1 -0
  256. package/dist/customTypes/arrays.d.ts +200 -0
  257. package/dist/customTypes/arrays.d.ts.map +1 -0
  258. package/dist/customTypes/arrays.js +309 -0
  259. package/dist/customTypes/arrays.js.map +1 -0
  260. package/dist/customTypes/index.d.ts +8 -0
  261. package/dist/customTypes/index.d.ts.map +1 -0
  262. package/dist/customTypes/index.js +11 -0
  263. package/dist/customTypes/index.js.map +1 -0
  264. package/dist/customTypes/postgis.d.ts +146 -0
  265. package/dist/customTypes/postgis.d.ts.map +1 -0
  266. package/dist/customTypes/postgis.js +315 -0
  267. package/dist/customTypes/postgis.js.map +1 -0
  268. package/dist/customTypes/ranges.d.ts +128 -0
  269. package/dist/customTypes/ranges.d.ts.map +1 -0
  270. package/dist/customTypes/ranges.js +257 -0
  271. package/dist/customTypes/ranges.js.map +1 -0
  272. package/dist/index.d.ts +37 -0
  273. package/dist/index.d.ts.map +1 -0
  274. package/dist/index.js +42 -0
  275. package/dist/index.js.map +1 -0
  276. package/dist/migrations/0.1.0-alpha.0_initial_setup.d.ts +29 -0
  277. package/dist/migrations/0.1.0-alpha.0_initial_setup.d.ts.map +1 -0
  278. package/dist/migrations/0.1.0-alpha.0_initial_setup.js +72 -0
  279. package/dist/migrations/0.1.0-alpha.0_initial_setup.js.map +1 -0
  280. package/dist/migrations/_example_migration.d.ts +31 -0
  281. package/dist/migrations/_example_migration.d.ts.map +1 -0
  282. package/dist/migrations/_example_migration.js +75 -0
  283. package/dist/migrations/_example_migration.js.map +1 -0
  284. package/dist/plugins/definePlugin.d.ts +49 -0
  285. package/dist/plugins/definePlugin.d.ts.map +1 -0
  286. package/dist/plugins/definePlugin.js +131 -0
  287. package/dist/plugins/definePlugin.js.map +1 -0
  288. package/dist/plugins/softDelete.d.ts +179 -0
  289. package/dist/plugins/softDelete.d.ts.map +1 -0
  290. package/dist/plugins/softDelete.js +235 -0
  291. package/dist/plugins/softDelete.js.map +1 -0
  292. package/dist/routes/auth.route.d.ts +14 -0
  293. package/dist/routes/auth.route.d.ts.map +1 -0
  294. package/dist/routes/auth.route.js +421 -0
  295. package/dist/routes/auth.route.js.map +1 -0
  296. package/dist/routes/file.route.d.ts +7 -0
  297. package/dist/routes/file.route.d.ts.map +1 -0
  298. package/dist/routes/file.route.js +274 -0
  299. package/dist/routes/file.route.js.map +1 -0
  300. package/dist/routes/items.route.d.ts +7 -0
  301. package/dist/routes/items.route.d.ts.map +1 -0
  302. package/dist/routes/items.route.js +369 -0
  303. package/dist/routes/items.route.js.map +1 -0
  304. package/dist/routes/migration.route.d.ts +7 -0
  305. package/dist/routes/migration.route.d.ts.map +1 -0
  306. package/dist/routes/migration.route.js +225 -0
  307. package/dist/routes/migration.route.js.map +1 -0
  308. package/dist/routes/notification.route.d.ts +7 -0
  309. package/dist/routes/notification.route.d.ts.map +1 -0
  310. package/dist/routes/notification.route.js +124 -0
  311. package/dist/routes/notification.route.js.map +1 -0
  312. package/dist/routes/openapi.route.d.ts +7 -0
  313. package/dist/routes/openapi.route.d.ts.map +1 -0
  314. package/dist/routes/openapi.route.js +2169 -0
  315. package/dist/routes/openapi.route.js.map +1 -0
  316. package/dist/routes/permission.route.d.ts +7 -0
  317. package/dist/routes/permission.route.d.ts.map +1 -0
  318. package/dist/routes/permission.route.js +158 -0
  319. package/dist/routes/permission.route.js.map +1 -0
  320. package/dist/routes/realtime.route.d.ts +21 -0
  321. package/dist/routes/realtime.route.d.ts.map +1 -0
  322. package/dist/routes/realtime.route.js +243 -0
  323. package/dist/routes/realtime.route.js.map +1 -0
  324. package/dist/routes/reports.route.d.ts +7 -0
  325. package/dist/routes/reports.route.d.ts.map +1 -0
  326. package/dist/routes/reports.route.js +95 -0
  327. package/dist/routes/reports.route.js.map +1 -0
  328. package/dist/routes/schema.route.d.ts +7 -0
  329. package/dist/routes/schema.route.d.ts.map +1 -0
  330. package/dist/routes/schema.route.js +1780 -0
  331. package/dist/routes/schema.route.js.map +1 -0
  332. package/dist/routes/settings.route.d.ts +7 -0
  333. package/dist/routes/settings.route.d.ts.map +1 -0
  334. package/dist/routes/settings.route.js +154 -0
  335. package/dist/routes/settings.route.js.map +1 -0
  336. package/dist/routes/templates.route.d.ts +7 -0
  337. package/dist/routes/templates.route.d.ts.map +1 -0
  338. package/dist/routes/templates.route.js +91 -0
  339. package/dist/routes/templates.route.js.map +1 -0
  340. package/dist/routes/utils.route.d.ts +7 -0
  341. package/dist/routes/utils.route.d.ts.map +1 -0
  342. package/dist/routes/utils.route.js +33 -0
  343. package/dist/routes/utils.route.js.map +1 -0
  344. package/dist/routes/workflow.route.d.ts +7 -0
  345. package/dist/routes/workflow.route.d.ts.map +1 -0
  346. package/dist/routes/workflow.route.js +787 -0
  347. package/dist/routes/workflow.route.js.map +1 -0
  348. package/dist/services/AssetsService.d.ts +39 -0
  349. package/dist/services/AssetsService.d.ts.map +1 -0
  350. package/dist/services/AssetsService.js +255 -0
  351. package/dist/services/AssetsService.js.map +1 -0
  352. package/dist/services/CacheService.d.ts +169 -0
  353. package/dist/services/CacheService.d.ts.map +1 -0
  354. package/dist/services/CacheService.js +722 -0
  355. package/dist/services/CacheService.js.map +1 -0
  356. package/dist/services/FilesService.d.ts +30 -0
  357. package/dist/services/FilesService.d.ts.map +1 -0
  358. package/dist/services/FilesService.js +268 -0
  359. package/dist/services/FilesService.js.map +1 -0
  360. package/dist/services/HooksManager.d.ts +38 -0
  361. package/dist/services/HooksManager.d.ts.map +1 -0
  362. package/dist/services/HooksManager.js +165 -0
  363. package/dist/services/HooksManager.js.map +1 -0
  364. package/dist/services/ItemsService.d.ts +273 -0
  365. package/dist/services/ItemsService.d.ts.map +1 -0
  366. package/dist/services/ItemsService.js +2458 -0
  367. package/dist/services/ItemsService.js.map +1 -0
  368. package/dist/services/MailService.d.ts +76 -0
  369. package/dist/services/MailService.d.ts.map +1 -0
  370. package/dist/services/MailService.js +585 -0
  371. package/dist/services/MailService.js.map +1 -0
  372. package/dist/services/MigrationService.d.ts +243 -0
  373. package/dist/services/MigrationService.d.ts.map +1 -0
  374. package/dist/services/MigrationService.js +914 -0
  375. package/dist/services/MigrationService.js.map +1 -0
  376. package/dist/services/NotificationService.d.ts +35 -0
  377. package/dist/services/NotificationService.d.ts.map +1 -0
  378. package/dist/services/NotificationService.js +159 -0
  379. package/dist/services/NotificationService.js.map +1 -0
  380. package/dist/services/PermissionService.d.ts +128 -0
  381. package/dist/services/PermissionService.d.ts.map +1 -0
  382. package/dist/services/PermissionService.js +373 -0
  383. package/dist/services/PermissionService.js.map +1 -0
  384. package/dist/services/PluginManager.d.ts +138 -0
  385. package/dist/services/PluginManager.d.ts.map +1 -0
  386. package/dist/services/PluginManager.js +463 -0
  387. package/dist/services/PluginManager.js.map +1 -0
  388. package/dist/services/RealtimeService.d.ts +209 -0
  389. package/dist/services/RealtimeService.d.ts.map +1 -0
  390. package/dist/services/RealtimeService.js +978 -0
  391. package/dist/services/RealtimeService.js.map +1 -0
  392. package/dist/services/ReportService.d.ts +13 -0
  393. package/dist/services/ReportService.d.ts.map +1 -0
  394. package/dist/services/ReportService.js +91 -0
  395. package/dist/services/ReportService.js.map +1 -0
  396. package/dist/services/SettingsService.d.ts +60 -0
  397. package/dist/services/SettingsService.d.ts.map +1 -0
  398. package/dist/services/SettingsService.js +474 -0
  399. package/dist/services/SettingsService.js.map +1 -0
  400. package/dist/services/SocketService.d.ts +129 -0
  401. package/dist/services/SocketService.d.ts.map +1 -0
  402. package/dist/services/SocketService.js +600 -0
  403. package/dist/services/SocketService.js.map +1 -0
  404. package/dist/services/StatsService.d.ts +10 -0
  405. package/dist/services/StatsService.d.ts.map +1 -0
  406. package/dist/services/StatsService.js +40 -0
  407. package/dist/services/StatsService.js.map +1 -0
  408. package/dist/services/StorageService.d.ts +20 -0
  409. package/dist/services/StorageService.d.ts.map +1 -0
  410. package/dist/services/StorageService.js +164 -0
  411. package/dist/services/StorageService.js.map +1 -0
  412. package/dist/services/TasksService.d.ts +74 -0
  413. package/dist/services/TasksService.d.ts.map +1 -0
  414. package/dist/services/TasksService.js +404 -0
  415. package/dist/services/TasksService.js.map +1 -0
  416. package/dist/services/WorkflowService.d.ts +305 -0
  417. package/dist/services/WorkflowService.d.ts.map +1 -0
  418. package/dist/services/WorkflowService.js +1811 -0
  419. package/dist/services/WorkflowService.js.map +1 -0
  420. package/dist/templates/logo/logo.png +0 -0
  421. package/dist/templates/mails/default.liquid +23 -0
  422. package/dist/types/aggregation.d.ts +40 -0
  423. package/dist/types/aggregation.d.ts.map +1 -0
  424. package/dist/types/aggregation.js +6 -0
  425. package/dist/types/aggregation.js.map +1 -0
  426. package/dist/types/assets.d.ts +32 -0
  427. package/dist/types/assets.d.ts.map +1 -0
  428. package/dist/types/assets.js +6 -0
  429. package/dist/types/assets.js.map +1 -0
  430. package/dist/types/auth.d.ts +50 -0
  431. package/dist/types/auth.d.ts.map +1 -0
  432. package/dist/types/auth.js +6 -0
  433. package/dist/types/auth.js.map +1 -0
  434. package/dist/types/cache.d.ts +47 -0
  435. package/dist/types/cache.d.ts.map +1 -0
  436. package/dist/types/cache.js +6 -0
  437. package/dist/types/cache.js.map +1 -0
  438. package/dist/types/database.d.ts +16 -0
  439. package/dist/types/database.d.ts.map +1 -0
  440. package/dist/types/database.js +6 -0
  441. package/dist/types/database.js.map +1 -0
  442. package/dist/types/fields.d.ts +71 -0
  443. package/dist/types/fields.d.ts.map +1 -0
  444. package/dist/types/fields.js +6 -0
  445. package/dist/types/fields.js.map +1 -0
  446. package/dist/types/files.d.ts +33 -0
  447. package/dist/types/files.d.ts.map +1 -0
  448. package/dist/types/files.js +6 -0
  449. package/dist/types/files.js.map +1 -0
  450. package/dist/types/hooks.d.ts +29 -0
  451. package/dist/types/hooks.d.ts.map +1 -0
  452. package/dist/types/hooks.js +6 -0
  453. package/dist/types/hooks.js.map +1 -0
  454. package/dist/types/import-export.d.ts +62 -0
  455. package/dist/types/import-export.d.ts.map +1 -0
  456. package/dist/types/import-export.js +6 -0
  457. package/dist/types/import-export.js.map +1 -0
  458. package/dist/types/index.d.ts +31 -0
  459. package/dist/types/index.d.ts.map +1 -0
  460. package/dist/types/index.js +58 -0
  461. package/dist/types/index.js.map +1 -0
  462. package/dist/types/mail.d.ts +34 -0
  463. package/dist/types/mail.d.ts.map +1 -0
  464. package/dist/types/mail.js +6 -0
  465. package/dist/types/mail.js.map +1 -0
  466. package/dist/types/notifications.d.ts +16 -0
  467. package/dist/types/notifications.d.ts.map +1 -0
  468. package/dist/types/notifications.js +6 -0
  469. package/dist/types/notifications.js.map +1 -0
  470. package/dist/types/plugin.d.ts +351 -0
  471. package/dist/types/plugin.d.ts.map +1 -0
  472. package/dist/types/plugin.js +8 -0
  473. package/dist/types/plugin.js.map +1 -0
  474. package/dist/types/query.d.ts +71 -0
  475. package/dist/types/query.d.ts.map +1 -0
  476. package/dist/types/query.js +6 -0
  477. package/dist/types/query.js.map +1 -0
  478. package/dist/types/relations.d.ts +111 -0
  479. package/dist/types/relations.d.ts.map +1 -0
  480. package/dist/types/relations.js +6 -0
  481. package/dist/types/relations.js.map +1 -0
  482. package/dist/types/reports.d.ts +17 -0
  483. package/dist/types/reports.d.ts.map +1 -0
  484. package/dist/types/reports.js +6 -0
  485. package/dist/types/reports.js.map +1 -0
  486. package/dist/types/schema.d.ts +26 -0
  487. package/dist/types/schema.d.ts.map +1 -0
  488. package/dist/types/schema.js +6 -0
  489. package/dist/types/schema.js.map +1 -0
  490. package/dist/types/seed.d.ts +27 -0
  491. package/dist/types/seed.d.ts.map +1 -0
  492. package/dist/types/seed.js +6 -0
  493. package/dist/types/seed.js.map +1 -0
  494. package/dist/types/services.d.ts +68 -0
  495. package/dist/types/services.d.ts.map +1 -0
  496. package/dist/types/services.js +6 -0
  497. package/dist/types/services.js.map +1 -0
  498. package/dist/types/settings.d.ts +36 -0
  499. package/dist/types/settings.d.ts.map +1 -0
  500. package/dist/types/settings.js +6 -0
  501. package/dist/types/settings.js.map +1 -0
  502. package/dist/types/sockets.d.ts +26 -0
  503. package/dist/types/sockets.d.ts.map +1 -0
  504. package/dist/types/sockets.js +6 -0
  505. package/dist/types/sockets.js.map +1 -0
  506. package/dist/types/sort.d.ts +25 -0
  507. package/dist/types/sort.d.ts.map +1 -0
  508. package/dist/types/sort.js +6 -0
  509. package/dist/types/sort.js.map +1 -0
  510. package/dist/types/spatial.d.ts +19 -0
  511. package/dist/types/spatial.d.ts.map +1 -0
  512. package/dist/types/spatial.js +6 -0
  513. package/dist/types/spatial.js.map +1 -0
  514. package/dist/types/stats.d.ts +21 -0
  515. package/dist/types/stats.d.ts.map +1 -0
  516. package/dist/types/stats.js +6 -0
  517. package/dist/types/stats.js.map +1 -0
  518. package/dist/types/storage.d.ts +19 -0
  519. package/dist/types/storage.d.ts.map +1 -0
  520. package/dist/types/storage.js +6 -0
  521. package/dist/types/storage.js.map +1 -0
  522. package/dist/types/tasks.d.ts +14 -0
  523. package/dist/types/tasks.d.ts.map +1 -0
  524. package/dist/types/tasks.js +6 -0
  525. package/dist/types/tasks.js.map +1 -0
  526. package/dist/types/utils.d.ts +54 -0
  527. package/dist/types/utils.d.ts.map +1 -0
  528. package/dist/types/utils.js +6 -0
  529. package/dist/types/utils.js.map +1 -0
  530. package/dist/types/workflow.d.ts +17 -0
  531. package/dist/types/workflow.d.ts.map +1 -0
  532. package/dist/types/workflow.js +6 -0
  533. package/dist/types/workflow.js.map +1 -0
  534. package/dist/utils/aggregationUtils.d.ts +192 -0
  535. package/dist/utils/aggregationUtils.d.ts.map +1 -0
  536. package/dist/utils/aggregationUtils.js +450 -0
  537. package/dist/utils/aggregationUtils.js.map +1 -0
  538. package/dist/utils/auth.d.ts +93 -0
  539. package/dist/utils/auth.d.ts.map +1 -0
  540. package/dist/utils/auth.js +557 -0
  541. package/dist/utils/auth.js.map +1 -0
  542. package/dist/utils/cache.d.ts +64 -0
  543. package/dist/utils/cache.d.ts.map +1 -0
  544. package/dist/utils/cache.js +464 -0
  545. package/dist/utils/cache.js.map +1 -0
  546. package/dist/utils/common.d.ts +53 -0
  547. package/dist/utils/common.d.ts.map +1 -0
  548. package/dist/utils/common.js +162 -0
  549. package/dist/utils/common.js.map +1 -0
  550. package/dist/utils/db.d.ts +101 -0
  551. package/dist/utils/db.d.ts.map +1 -0
  552. package/dist/utils/db.js +413 -0
  553. package/dist/utils/db.js.map +1 -0
  554. package/dist/utils/dirname.d.ts +30 -0
  555. package/dist/utils/dirname.d.ts.map +1 -0
  556. package/dist/utils/dirname.js +95 -0
  557. package/dist/utils/dirname.js.map +1 -0
  558. package/dist/utils/dynamicVariableResolver.d.ts +17 -0
  559. package/dist/utils/dynamicVariableResolver.d.ts.map +1 -0
  560. package/dist/utils/dynamicVariableResolver.js +262 -0
  561. package/dist/utils/dynamicVariableResolver.js.map +1 -0
  562. package/dist/utils/env.d.ts +38 -0
  563. package/dist/utils/env.d.ts.map +1 -0
  564. package/dist/utils/env.js +80 -0
  565. package/dist/utils/env.js.map +1 -0
  566. package/dist/utils/errorHandler.d.ts +14 -0
  567. package/dist/utils/errorHandler.d.ts.map +1 -0
  568. package/dist/utils/errorHandler.js +79 -0
  569. package/dist/utils/errorHandler.js.map +1 -0
  570. package/dist/utils/fieldExpansion.d.ts +30 -0
  571. package/dist/utils/fieldExpansion.d.ts.map +1 -0
  572. package/dist/utils/fieldExpansion.js +145 -0
  573. package/dist/utils/fieldExpansion.js.map +1 -0
  574. package/dist/utils/fieldUtils.d.ts +179 -0
  575. package/dist/utils/fieldUtils.d.ts.map +1 -0
  576. package/dist/utils/fieldUtils.js +424 -0
  577. package/dist/utils/fieldUtils.js.map +1 -0
  578. package/dist/utils/filterOperators.d.ts +472 -0
  579. package/dist/utils/filterOperators.d.ts.map +1 -0
  580. package/dist/utils/filterOperators.js +1229 -0
  581. package/dist/utils/filterOperators.js.map +1 -0
  582. package/dist/utils/importUtils.d.ts +127 -0
  583. package/dist/utils/importUtils.d.ts.map +1 -0
  584. package/dist/utils/importUtils.js +437 -0
  585. package/dist/utils/importUtils.js.map +1 -0
  586. package/dist/utils/index.d.ts +75 -0
  587. package/dist/utils/index.d.ts.map +1 -0
  588. package/dist/utils/index.js +101 -0
  589. package/dist/utils/index.js.map +1 -0
  590. package/dist/utils/logger.d.ts +41 -0
  591. package/dist/utils/logger.d.ts.map +1 -0
  592. package/dist/utils/logger.js +217 -0
  593. package/dist/utils/logger.js.map +1 -0
  594. package/dist/utils/orderUtils.d.ts +117 -0
  595. package/dist/utils/orderUtils.d.ts.map +1 -0
  596. package/dist/utils/orderUtils.js +249 -0
  597. package/dist/utils/orderUtils.js.map +1 -0
  598. package/dist/utils/queryBuilder.d.ts +118 -0
  599. package/dist/utils/queryBuilder.d.ts.map +1 -0
  600. package/dist/utils/queryBuilder.js +489 -0
  601. package/dist/utils/queryBuilder.js.map +1 -0
  602. package/dist/utils/relationLoader.d.ts +65 -0
  603. package/dist/utils/relationLoader.d.ts.map +1 -0
  604. package/dist/utils/relationLoader.js +1081 -0
  605. package/dist/utils/relationLoader.js.map +1 -0
  606. package/dist/utils/relationPathResolver.d.ts +30 -0
  607. package/dist/utils/relationPathResolver.d.ts.map +1 -0
  608. package/dist/utils/relationPathResolver.js +173 -0
  609. package/dist/utils/relationPathResolver.js.map +1 -0
  610. package/dist/utils/relationUtils.d.ts +139 -0
  611. package/dist/utils/relationUtils.d.ts.map +1 -0
  612. package/dist/utils/relationUtils.js +711 -0
  613. package/dist/utils/relationUtils.js.map +1 -0
  614. package/dist/utils/router.d.ts +6 -0
  615. package/dist/utils/router.d.ts.map +1 -0
  616. package/dist/utils/router.js +95 -0
  617. package/dist/utils/router.js.map +1 -0
  618. package/dist/utils/schema.d.ts +88 -0
  619. package/dist/utils/schema.d.ts.map +1 -0
  620. package/dist/utils/schema.js +24 -0
  621. package/dist/utils/schema.js.map +1 -0
  622. package/dist/utils/schemaManager.d.ts +238 -0
  623. package/dist/utils/schemaManager.d.ts.map +1 -0
  624. package/dist/utils/schemaManager.js +1992 -0
  625. package/dist/utils/schemaManager.js.map +1 -0
  626. package/dist/utils/schemaValidator.d.ts +83 -0
  627. package/dist/utils/schemaValidator.d.ts.map +1 -0
  628. package/dist/utils/schemaValidator.js +491 -0
  629. package/dist/utils/schemaValidator.js.map +1 -0
  630. package/dist/utils/seed.d.ts +45 -0
  631. package/dist/utils/seed.d.ts.map +1 -0
  632. package/dist/utils/seed.js +248 -0
  633. package/dist/utils/seed.js.map +1 -0
  634. package/dist/utils/sessionCleanup.d.ts +10 -0
  635. package/dist/utils/sessionCleanup.d.ts.map +1 -0
  636. package/dist/utils/sessionCleanup.js +49 -0
  637. package/dist/utils/sessionCleanup.js.map +1 -0
  638. package/dist/utils/sortUtils.d.ts +117 -0
  639. package/dist/utils/sortUtils.d.ts.map +1 -0
  640. package/dist/utils/sortUtils.js +232 -0
  641. package/dist/utils/sortUtils.js.map +1 -0
  642. package/dist/utils/spatialUtils.d.ts +244 -0
  643. package/dist/utils/spatialUtils.d.ts.map +1 -0
  644. package/dist/utils/spatialUtils.js +359 -0
  645. package/dist/utils/spatialUtils.js.map +1 -0
  646. package/dist/utils/systemschema.d.ts +11040 -0
  647. package/dist/utils/systemschema.d.ts.map +1 -0
  648. package/dist/utils/systemschema.js +1777 -0
  649. package/dist/utils/systemschema.js.map +1 -0
  650. package/dist/utils/tenantUtils.d.ts +34 -0
  651. package/dist/utils/tenantUtils.d.ts.map +1 -0
  652. package/dist/utils/tenantUtils.js +124 -0
  653. package/dist/utils/tenantUtils.js.map +1 -0
  654. package/dist/utils/typeMapper.d.ts +25 -0
  655. package/dist/utils/typeMapper.d.ts.map +1 -0
  656. package/dist/utils/typeMapper.js +282 -0
  657. package/dist/utils/typeMapper.js.map +1 -0
  658. package/dist/utils/valueValidator.d.ts +60 -0
  659. package/dist/utils/valueValidator.d.ts.map +1 -0
  660. package/dist/utils/valueValidator.js +303 -0
  661. package/dist/utils/valueValidator.js.map +1 -0
  662. package/dist/utils/workflow.d.ts +87 -0
  663. package/dist/utils/workflow.d.ts.map +1 -0
  664. package/dist/utils/workflow.js +205 -0
  665. package/dist/utils/workflow.js.map +1 -0
  666. 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