dineway 0.2.0 → 0.2.2

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 (409) hide show
  1. package/README.md +17 -17
  2. package/dist/activity-BDMlkpYY.mjs +79 -0
  3. package/dist/{activity-events-y6eT8UW6.mjs → activity-events-DEYmJhWd.mjs} +1 -77
  4. package/dist/{actor-CrObAPV0.mjs → actor-DA7yL9Yp.mjs} +1 -1
  5. package/dist/{allowed-origins-_oeyP6x-.mjs → allowed-origins-VLgv2PL1.mjs} +1 -1
  6. package/dist/api/route-utils.d.mts +9 -10
  7. package/dist/api/route-utils.mjs +14 -14
  8. package/dist/api/schemas/index.d.mts +2 -2
  9. package/dist/api/schemas/index.mjs +5 -5
  10. package/dist/{api-ByrU2q-Z.mjs → api-DsO87Qak.mjs} +51 -23
  11. package/dist/{api-tokens-CjVMQT-X.mjs → api-tokens-C4K9eocv.mjs} +1 -1
  12. package/dist/{apply-bZswmZPm.mjs → apply-DHT0l398.mjs} +19 -19
  13. package/dist/astro/index.d.mts +10 -11
  14. package/dist/astro/index.mjs +18 -5
  15. package/dist/astro/middleware/auth.d.mts +9 -19
  16. package/dist/astro/middleware/auth.mjs +6 -6
  17. package/dist/astro/middleware/redirect.mjs +5 -5
  18. package/dist/astro/middleware/request-context.mjs +2 -2
  19. package/dist/astro/middleware/seed.d.mts +1 -1
  20. package/dist/astro/middleware/seed.mjs +1 -1
  21. package/dist/astro/middleware/setup.mjs +1 -1
  22. package/dist/astro/middleware.mjs +142 -98
  23. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +6 -6
  24. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +6 -6
  25. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +4 -4
  26. package/dist/astro/routes/api/admin/api-tokens/index.mjs +6 -6
  27. package/dist/astro/routes/api/admin/briefing.mjs +18 -18
  28. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +4 -4
  29. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +9 -9
  30. package/dist/astro/routes/api/admin/byline-fields/index.mjs +9 -9
  31. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +9 -9
  32. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +16 -16
  33. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +16 -16
  34. package/dist/astro/routes/api/admin/bylines/index.mjs +16 -16
  35. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +12 -12
  36. package/dist/astro/routes/api/admin/comments/_id_.mjs +5 -5
  37. package/dist/astro/routes/api/admin/comments/bulk.mjs +10 -10
  38. package/dist/astro/routes/api/admin/comments/counts.mjs +5 -5
  39. package/dist/astro/routes/api/admin/comments/index.mjs +10 -10
  40. package/dist/astro/routes/api/admin/context/_id_/history.mjs +25 -24
  41. package/dist/astro/routes/api/admin/context/_id_/index.mjs +25 -24
  42. package/dist/astro/routes/api/admin/context/_id_/review.mjs +30 -29
  43. package/dist/astro/routes/api/admin/context/_id_/supersede.mjs +30 -29
  44. package/dist/astro/routes/api/admin/context/diff.mjs +29 -28
  45. package/dist/astro/routes/api/admin/context/index.mjs +30 -29
  46. package/dist/astro/routes/api/admin/context/stale.mjs +29 -28
  47. package/dist/astro/routes/api/admin/hitl-requests/_id_/index.mjs +25 -24
  48. package/dist/astro/routes/api/admin/hitl-requests/_id_/resolve.mjs +29 -28
  49. package/dist/astro/routes/api/admin/hitl-requests/index.mjs +29 -28
  50. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +26 -25
  51. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +2 -2
  52. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +6 -6
  53. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +6 -6
  54. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +55 -51
  55. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +55 -51
  56. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +47 -44
  57. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +54 -50
  58. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +54 -50
  59. package/dist/astro/routes/api/admin/plugins/index.mjs +47 -44
  60. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +2 -2
  61. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +47 -44
  62. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +54 -50
  63. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +47 -44
  64. package/dist/astro/routes/api/admin/plugins/updates.mjs +47 -44
  65. package/dist/astro/routes/api/admin/review-requests/_id_/index.mjs +5 -5
  66. package/dist/astro/routes/api/admin/review-requests/_id_/resolve.mjs +30 -65
  67. package/dist/astro/routes/api/admin/review-requests/index.d.mts +2 -1
  68. package/dist/astro/routes/api/admin/review-requests/index.mjs +58 -11
  69. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +47 -44
  70. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +2 -2
  71. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +47 -44
  72. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +2 -2
  73. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +1 -1
  74. package/dist/astro/routes/api/admin/users/_id_/index.mjs +7 -7
  75. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +2 -2
  76. package/dist/astro/routes/api/admin/users/index.mjs +6 -6
  77. package/dist/astro/routes/api/auth/dev-bypass.mjs +4 -4
  78. package/dist/astro/routes/api/auth/invite/accept.mjs +1 -1
  79. package/dist/astro/routes/api/auth/invite/complete.mjs +10 -10
  80. package/dist/astro/routes/api/auth/invite/index.mjs +7 -7
  81. package/dist/astro/routes/api/auth/invite/register-options.mjs +9 -9
  82. package/dist/astro/routes/api/auth/logout.mjs +2 -2
  83. package/dist/astro/routes/api/auth/magic-link/send.mjs +9 -9
  84. package/dist/astro/routes/api/auth/magic-link/verify.mjs +2 -2
  85. package/dist/astro/routes/api/auth/me.mjs +8 -8
  86. package/dist/astro/routes/api/auth/mode.mjs +1 -1
  87. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +2 -2
  88. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
  89. package/dist/astro/routes/api/auth/passkey/_id_.mjs +6 -6
  90. package/dist/astro/routes/api/auth/passkey/index.mjs +1 -1
  91. package/dist/astro/routes/api/auth/passkey/options.mjs +11 -11
  92. package/dist/astro/routes/api/auth/passkey/register/options.mjs +9 -9
  93. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +10 -10
  94. package/dist/astro/routes/api/auth/passkey/verify.mjs +10 -10
  95. package/dist/astro/routes/api/auth/setup-token/index.mjs +5 -5
  96. package/dist/astro/routes/api/auth/setup-token/verify.mjs +2 -2
  97. package/dist/astro/routes/api/auth/signup/complete.mjs +10 -10
  98. package/dist/astro/routes/api/auth/signup/request.mjs +9 -9
  99. package/dist/astro/routes/api/auth/signup/verify.mjs +1 -1
  100. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +13 -13
  101. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +12 -12
  102. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +2 -2
  103. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +6 -5
  104. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +6 -5
  105. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +6 -5
  106. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +10 -10
  107. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +49 -21
  108. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +6 -5
  109. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +2 -2
  110. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +67 -33
  111. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +14 -14
  112. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +2 -2
  113. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +6 -5
  114. package/dist/astro/routes/api/content/_collection_/_id_.mjs +11 -10
  115. package/dist/astro/routes/api/content/_collection_/authors.mjs +2 -2
  116. package/dist/astro/routes/api/content/_collection_/index.mjs +11 -10
  117. package/dist/astro/routes/api/content/_collection_/trash.mjs +7 -7
  118. package/dist/astro/routes/api/dashboard.mjs +8 -8
  119. package/dist/astro/routes/api/dev/emails.mjs +2 -2
  120. package/dist/astro/routes/api/health.mjs +1 -1
  121. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  122. package/dist/astro/routes/api/import/probe.mjs +19 -19
  123. package/dist/astro/routes/api/import/wordpress/analyze.mjs +8 -8
  124. package/dist/astro/routes/api/import/wordpress/execute.d.mts +8 -9
  125. package/dist/astro/routes/api/import/wordpress/execute.mjs +35 -34
  126. package/dist/astro/routes/api/import/wordpress/media.d.mts +8 -9
  127. package/dist/astro/routes/api/import/wordpress/media.mjs +12 -12
  128. package/dist/astro/routes/api/import/wordpress/prepare.mjs +34 -33
  129. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +9 -10
  130. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +31 -30
  131. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  132. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +22 -22
  133. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +8 -9
  134. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +40 -39
  135. package/dist/astro/routes/api/integrations/_provider_.d.mts +8 -0
  136. package/dist/astro/routes/api/integrations/_provider_.mjs +51 -0
  137. package/dist/astro/routes/api/integrations/index.d.mts +7 -0
  138. package/dist/astro/routes/api/integrations/index.mjs +24 -0
  139. package/dist/astro/routes/api/manifest.mjs +4 -4
  140. package/dist/astro/routes/api/mcp.mjs +474 -167
  141. package/dist/astro/routes/api/media/_id_/confirm.mjs +10 -10
  142. package/dist/astro/routes/api/media/_id_.mjs +8 -8
  143. package/dist/astro/routes/api/media/file/_...key_.mjs +1 -1
  144. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +2 -2
  145. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +2 -2
  146. package/dist/astro/routes/api/media/providers/index.mjs +2 -2
  147. package/dist/astro/routes/api/media/upload-url.mjs +11 -11
  148. package/dist/astro/routes/api/media.mjs +14 -14
  149. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +30 -29
  150. package/dist/astro/routes/api/menus/_name_/items.mjs +30 -29
  151. package/dist/astro/routes/api/menus/_name_/reorder.mjs +30 -29
  152. package/dist/astro/routes/api/menus/_name_/translations.mjs +30 -29
  153. package/dist/astro/routes/api/menus/_name_.mjs +30 -29
  154. package/dist/astro/routes/api/menus/index.mjs +30 -29
  155. package/dist/astro/routes/api/oauth/authorize.mjs +7 -7
  156. package/dist/astro/routes/api/oauth/device/authorize.mjs +6 -6
  157. package/dist/astro/routes/api/oauth/device/code.mjs +9 -9
  158. package/dist/astro/routes/api/oauth/device/token.mjs +8 -8
  159. package/dist/astro/routes/api/oauth/register.mjs +4 -4
  160. package/dist/astro/routes/api/oauth/token/refresh.mjs +6 -6
  161. package/dist/astro/routes/api/oauth/token/revoke.mjs +6 -6
  162. package/dist/astro/routes/api/oauth/token.mjs +6 -6
  163. package/dist/astro/routes/api/openapi.json.mjs +4 -4
  164. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +20 -5
  165. package/dist/astro/routes/api/redirects/404s/index.mjs +10 -10
  166. package/dist/astro/routes/api/redirects/404s/summary.mjs +10 -10
  167. package/dist/astro/routes/api/redirects/_id_.mjs +31 -30
  168. package/dist/astro/routes/api/redirects/index.mjs +31 -30
  169. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +2 -2
  170. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +2 -2
  171. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +49 -45
  172. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +49 -45
  173. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +49 -45
  174. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +49 -45
  175. package/dist/astro/routes/api/schema/collections/index.mjs +49 -45
  176. package/dist/astro/routes/api/schema/index.mjs +8 -8
  177. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +47 -44
  178. package/dist/astro/routes/api/schema/orphans/index.mjs +47 -44
  179. package/dist/astro/routes/api/search/enable.mjs +11 -11
  180. package/dist/astro/routes/api/search/index.mjs +10 -10
  181. package/dist/astro/routes/api/search/rebuild.mjs +11 -11
  182. package/dist/astro/routes/api/search/stats.mjs +6 -6
  183. package/dist/astro/routes/api/search/suggest.mjs +10 -10
  184. package/dist/astro/routes/api/sections/_slug_.mjs +30 -29
  185. package/dist/astro/routes/api/sections/index.mjs +30 -29
  186. package/dist/astro/routes/api/settings/email.mjs +3 -3
  187. package/dist/astro/routes/api/settings.mjs +30 -29
  188. package/dist/astro/routes/api/setup/admin-verify.mjs +12 -12
  189. package/dist/astro/routes/api/setup/admin.mjs +10 -10
  190. package/dist/astro/routes/api/setup/dev-bypass.mjs +25 -25
  191. package/dist/astro/routes/api/setup/dev-reset.mjs +1 -1
  192. package/dist/astro/routes/api/setup/index.mjs +27 -27
  193. package/dist/astro/routes/api/setup/status.mjs +3 -3
  194. package/dist/astro/routes/api/snapshot.mjs +6 -6
  195. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +33 -32
  196. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +33 -32
  197. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +33 -32
  198. package/dist/astro/routes/api/taxonomies/index.mjs +33 -32
  199. package/dist/astro/routes/api/themes/preview.mjs +4 -4
  200. package/dist/astro/routes/api/typegen.mjs +4 -4
  201. package/dist/astro/routes/api/well-known/auth.mjs +2 -2
  202. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +3 -3
  203. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +3 -3
  204. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +29 -28
  205. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +30 -29
  206. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +30 -29
  207. package/dist/astro/routes/api/widget-areas/_name_.mjs +27 -26
  208. package/dist/astro/routes/api/widget-areas/index.mjs +30 -29
  209. package/dist/astro/routes/api/widget-components.mjs +2 -2
  210. package/dist/astro/routes/robots.txt.mjs +6 -6
  211. package/dist/astro/routes/sitemap-_collection_.xml.mjs +9 -9
  212. package/dist/astro/routes/sitemap.xml.mjs +7 -7
  213. package/dist/astro/session-driver.d.mts +1 -1
  214. package/dist/astro/session-driver.mjs +2 -2
  215. package/dist/astro/types.d.mts +13 -12
  216. package/dist/{audit-ByVKIwWF.mjs → audit-BzhwRVym.mjs} +1 -1
  217. package/dist/auth/providers/github.d.mts +1 -1
  218. package/dist/auth/providers/google.d.mts +1 -1
  219. package/dist/{auth-control-guard-CqeUmQsv.mjs → auth-control-guard-B_Dx-epW.mjs} +1 -1
  220. package/dist/{authorize-CcBxcHtz.mjs → authorize-D6MkRtPw.mjs} +1 -1
  221. package/dist/{briefing-BJaJI8dm.mjs → briefing-Cl70iEH5.mjs} +1 -1
  222. package/dist/{briefing-CawZ59CY.mjs → briefing-GFhLTLJo.mjs} +7 -7
  223. package/dist/{bundle-7C_DpkEq.mjs → bundle-CIrUlrkQ.mjs} +2 -2
  224. package/dist/{byline-e51-fWRs.mjs → byline-BJa1MyKB.mjs} +6 -6
  225. package/dist/{byline-fields-D-N5qVIG.mjs → byline-fields-BKzA0fJU.mjs} +1 -1
  226. package/dist/{byline-fields-CUvbslGc.d.mts → byline-fields-DxMpdtsZ.d.mts} +57 -47
  227. package/dist/{byline-fields-DOJO16Gm.mjs → byline-fields-yT4herdN.mjs} +10 -4
  228. package/dist/{byline-registry-87nNnYl4.mjs → byline-registry-Ba54M74c.mjs} +2 -2
  229. package/dist/{bylines-CMQNCNFh.mjs → bylines-B53Saxdb.mjs} +3 -3
  230. package/dist/{bylines-y4LO-dTj.mjs → bylines-kixFoaRV.mjs} +5 -5
  231. package/dist/{cache-C-FNTFYK.mjs → cache-fpisdt5Q.mjs} +2 -2
  232. package/dist/{chunks-CxBt-GxR.mjs → chunks-DX_b8_4Z.mjs} +1 -1
  233. package/dist/cli/index.d.mts +29 -1
  234. package/dist/cli/index.mjs +1527 -1222
  235. package/dist/cli/plugin-kit.d.mts +75 -0
  236. package/dist/cli/plugin-kit.mjs +4 -0
  237. package/dist/client/external-auth-headers.d.mts +1 -1
  238. package/dist/client/index.d.mts +27 -52
  239. package/dist/client/index.mjs +34 -7
  240. package/dist/client-factory-DEtHApCc.mjs +323 -0
  241. package/dist/{comment-DlA4iChg.mjs → comment-B88XcvU1.mjs} +1 -1
  242. package/dist/{comment-reaction-DfFao1ST.mjs → comment-reaction-Ckn6vCmB.mjs} +1 -1
  243. package/dist/{comments-DApFGMsP.mjs → comments-BDXsbL7z.mjs} +1 -1
  244. package/dist/{content-Bh4BDjv8.mjs → content-Cbl8HbIR.mjs} +2 -2
  245. package/dist/{content-refresh-CgutSUfO.mjs → content-refresh-BmkilU5M.mjs} +5 -5
  246. package/dist/{context-CK4ym2Sf.mjs → context-AJNd0tcG.mjs} +2 -2
  247. package/dist/{context-C5W3G18y.mjs → context-DT0tIsfw.mjs} +24 -13
  248. package/dist/{context-route-helpers-MASyGgWf.mjs → context-route-helpers-DhP--tTq.mjs} +2 -2
  249. package/dist/{dashboard-DQkVT7Ei.mjs → dashboard-YvDEYbS3.mjs} +4 -4
  250. package/dist/db/index.d.mts +3 -3
  251. package/dist/db/index.mjs +1 -1
  252. package/dist/db/libsql.d.mts +1 -1
  253. package/dist/db/postgres.d.mts +1 -1
  254. package/dist/db/sqlite.d.mts +1 -1
  255. package/dist/{device-flow-BnqRH-T9.mjs → device-flow-BKKeobcV.mjs} +5 -5
  256. package/dist/{enrich-DIFIFA8O.mjs → enrich-Ck9tfMqe.mjs} +1 -1
  257. package/dist/{error-CytFlgcd.mjs → error-BW9f_ynq.mjs} +16 -2
  258. package/dist/{experimental-workflows-BMsUnIAw.mjs → experimental-workflows-CgO73K4e.mjs} +1 -1
  259. package/dist/{field-defs-cache-DRNdhBJv.mjs → field-defs-cache-CiXP3eO3.mjs} +4 -4
  260. package/dist/{fts-manager-Crzypjqu.mjs → fts-manager-Zo9uhGel.mjs} +1 -1
  261. package/dist/{hitl-requests-B4Vbcmaq.mjs → hitl-requests-Bee8Cjj8.mjs} +2 -2
  262. package/dist/{hitl-route-helpers-hEVzvP8l.mjs → hitl-route-helpers-DtHaKGgm.mjs} +5 -5
  263. package/dist/{import-Bh9biJfx.mjs → import-C-zxnT89.mjs} +7 -7
  264. package/dist/{index-D4y6NGiy.d.mts → index-DybFmYtZ.d.mts} +79 -3
  265. package/dist/index.d.mts +15 -17
  266. package/dist/index.mjs +83 -78
  267. package/dist/integration-credentials-D3ZneN0L.mjs +49 -0
  268. package/dist/{jsonld-Dq0gsnOH.d.mts → jsonld-CoTa8I1a.d.mts} +2 -2
  269. package/dist/{load-DmYeniXl.mjs → load-Cuiyh8LT.mjs} +1 -1
  270. package/dist/{loader-CjWqjweO.mjs → loader-WHf22FwU.mjs} +2 -2
  271. package/dist/{manifest-schema-BxVPYMJR.mjs → manifest-schema-DKa3ZaJL.mjs} +6 -2
  272. package/dist/{mcp-reviewed-executor-TwVbMzG6.mjs → mcp-reviewed-executor-DnlF7mIL.mjs} +6 -3
  273. package/dist/media/image-endpoint.mjs +1 -1
  274. package/dist/media/index.d.mts +1 -1
  275. package/dist/media/index.mjs +2 -2
  276. package/dist/media/local-runtime.d.mts +10 -11
  277. package/dist/media/local-runtime.mjs +2 -2
  278. package/dist/{media-DMj0grzC.mjs → media-B4m-cnmj.mjs} +1 -1
  279. package/dist/{media-allowlist-BlVCSzHx.mjs → media-allowlist-BQyIBPzd.mjs} +1 -1
  280. package/dist/{menus-TaW1gKnk.mjs → menus-LYALU2Mf.mjs} +2 -2
  281. package/dist/{menus-xvsnVZXw.mjs → menus-oYfViqfE.mjs} +6 -6
  282. package/dist/{oauth-authorization-DiaGvRVz.mjs → oauth-authorization-CX7aa8Ph.mjs} +5 -5
  283. package/dist/{oauth-clients-Dl9E8dEM.mjs → oauth-clients-D9Gg0WjF.mjs} +2 -2
  284. package/dist/object-cache/memory.d.mts +1 -1
  285. package/dist/output-13u4dvu-.mjs +68 -0
  286. package/dist/page/index.d.mts +9 -3
  287. package/dist/page/index.mjs +1 -1
  288. package/dist/{parse-CbymENaR.mjs → parse-B-Y84oJl.mjs} +1 -1
  289. package/dist/plugin-utils.d.mts +8 -9
  290. package/dist/plugins/adapt-sandbox-entry.d.mts +8 -9
  291. package/dist/plugins/adapt-sandbox-entry.mjs +3 -1
  292. package/dist/{plugins-BolVa-tl.mjs → plugins-B7-4Okii.mjs} +95 -10
  293. package/dist/portable-text-Ehqj3I_y.d.mts +45 -0
  294. package/dist/{preview-vSVg6fwG.mjs → preview-BMIReQGc.mjs} +2 -2
  295. package/dist/{provider-loader-MD8zAbnH.d.mts → provider-loader-BIbIiz0P.d.mts} +1 -1
  296. package/dist/{public-url-gsp3oUbu.d.mts → public-url-DYISdY_R.d.mts} +1 -1
  297. package/dist/publication-authorization-BVQ5rCAF.mjs +985 -0
  298. package/dist/{query-CfRCdaL3.mjs → query-C_m8sn-S.mjs} +13 -13
  299. package/dist/{query-jaAmw8E1.mjs → query-DNczixZr.mjs} +3 -3
  300. package/dist/{rate-limit-ZLdyWoZF.mjs → rate-limit-oUGexQO1.mjs} +2 -2
  301. package/dist/{redirect-BAjt4Z6b.mjs → redirect-DoDgOWIA.mjs} +2 -2
  302. package/dist/{redirects-BTdwpQtE.mjs → redirects-CrP6U4hZ.mjs} +4 -4
  303. package/dist/{redirects-CA-xylPG.mjs → redirects-E_B6hvuz.mjs} +18 -10
  304. package/dist/{registry-CtyVedcN.mjs → registry-SEJqFliS.mjs} +24 -10
  305. package/dist/{request-meta-CUypToDJ.mjs → request-meta-DHFIzWcf.mjs} +1 -1
  306. package/dist/review-payload-BysRWpxS.mjs +111 -0
  307. package/dist/{review-requests-DUyEmtmG.mjs → review-requests-CObSuTYU.mjs} +1 -1
  308. package/dist/review-requests-Cu9051_B.mjs +142 -0
  309. package/dist/review-route-helpers-Dp_7PH8r.mjs +41 -0
  310. package/dist/{runner-1tC2tIRV.d.mts → runner-Bcy5w0vj.d.mts} +1 -1
  311. package/dist/{runner-DB7CRfOF.mjs → runner-BfWbi9YY.mjs} +1166 -447
  312. package/dist/runtime.d.mts +9 -10
  313. package/dist/runtime.mjs +3 -3
  314. package/dist/schema-Dk_N31V4.mjs +8 -0
  315. package/dist/{search-DSaLgEFI.mjs → search-BXEQepxL.mjs} +3 -3
  316. package/dist/{secrets-CDZo2k8L.mjs → secrets-CpGpyGcO.mjs} +1 -1
  317. package/dist/{sections-PVVXHGfp.mjs → sections-DxvEF6Bj.mjs} +2 -2
  318. package/dist/seed/index.d.mts +2 -2
  319. package/dist/seed/index.mjs +19 -19
  320. package/dist/seo/index.d.mts +1 -1
  321. package/dist/seo/index.mjs +1 -1
  322. package/dist/{seo-CQG3GCHQ.mjs → seo-D1RiaooQ.mjs} +1 -1
  323. package/dist/service-CY0aH6eI.mjs +347 -0
  324. package/dist/{service-DiN4ZuPp.mjs → service-QdG0YHws.mjs} +2 -2
  325. package/dist/{settings-i4VPP8bT.mjs → settings-Dje-PHXo.mjs} +2 -2
  326. package/dist/{settings-BbqgHWpU.mjs → settings-SVDAB7_W.mjs} +5 -5
  327. package/dist/{site-activity-Dy3FROs0.mjs → site-activity-BVK40wCy.mjs} +1 -1
  328. package/dist/{site-context-DQiL8Fl5.mjs → site-context-CzaEGizi.mjs} +565 -129
  329. package/dist/stable-hash-DshcXvRE.mjs +19 -0
  330. package/dist/storage/local.d.mts +1 -1
  331. package/dist/storage/local.mjs +1 -1
  332. package/dist/storage/s3.d.mts +1 -1
  333. package/dist/storage/s3.mjs +1 -1
  334. package/dist/store-CCfMD6nw.mjs +262 -0
  335. package/dist/{taxonomies-9s-v03H-.mjs → taxonomies-DuhGjBa8.mjs} +3 -3
  336. package/dist/{taxonomies-DRiixp_E.mjs → taxonomies-WVnFki0o.mjs} +6 -6
  337. package/dist/{taxonomy-Dvsw6BOs.mjs → taxonomy-CCo2plmV.mjs} +2 -2
  338. package/dist/{types-DU0bU2Wu.d.mts → types-BFeoAIHl.d.mts} +596 -2
  339. package/dist/{types-Dq1qT19x.mjs → types-Bshd_6wQ.mjs} +1 -1
  340. package/dist/{runtime-BOeiQsCv.d.mts → types-CJezJeNE.d.mts} +3561 -1355
  341. package/dist/{types-4garmdWa.mjs → types-CK0r-Xq4.mjs} +5 -2
  342. package/dist/{types-C_ly5eTp.d.mts → types-GtwhHAg8.d.mts} +1 -1
  343. package/dist/{types-DW_-sFyz.d.mts → types-ywmuDETA.d.mts} +2 -0
  344. package/dist/ui/server-runtime.d.mts +12 -14
  345. package/dist/ui/server-runtime.mjs +21 -21
  346. package/dist/{user-BIZPzCb9.mjs → user-Bcvr5ihC.mjs} +2 -2
  347. package/dist/{utils-CMDhr5Xd.mjs → utils-B7gemXz5.mjs} +1 -1
  348. package/dist/{validate-CZvb-BKB.d.mts → validate-YiX3rly5.d.mts} +59 -5
  349. package/dist/{validate-DNs0pTSc.mjs → validate-qKzI3BCv.mjs} +2 -2
  350. package/dist/version-DEAV9k58.mjs +6 -0
  351. package/dist/{widgets-f0ibZUIq.mjs → widgets-DyGcotPM.mjs} +3 -3
  352. package/dist/{wordpress-slugs-BhHJX8XE.mjs → wordpress-slugs-D_LfQCan.mjs} +1 -1
  353. package/dist/{zod-generator-B7TMjyFJ.mjs → zod-generator-Cr3SiHsc.mjs} +2 -2
  354. package/package.json +16 -6
  355. package/dist/hitl-Hw1RmWOq.mjs +0 -677
  356. package/dist/review-requests-C9Ff11Vq.mjs +0 -79
  357. package/dist/schema-DXdYj4R3.mjs +0 -8
  358. package/dist/types-C46EvNdc.d.mts +0 -56
  359. package/dist/types-C8XW6L19.d.mts +0 -1468
  360. package/dist/version-BTvfRGc6.mjs +0 -6
  361. /package/dist/{adapters-NVSs4UH7.d.mts → adapters-DnMDRQ4e.d.mts} +0 -0
  362. /package/dist/{api-tokens-2r7OWi_I.mjs → api-tokens-D4tcY8R6.mjs} +0 -0
  363. /package/dist/{challenge-store-Bjlepa2E.mjs → challenge-store-BMkL2kmt.mjs} +0 -0
  364. /package/dist/{components-Bclf98Be.mjs → components-D0w9MzQe.mjs} +0 -0
  365. /package/dist/{context-types-DqTo6C79.mjs → context-types-eBuMDAg-.mjs} +0 -0
  366. /package/dist/{cron-cKcNTix_.mjs → cron-D_c3WUPN.mjs} +0 -0
  367. /package/dist/{default--K40jqm0.mjs → default-BxoI3SoK.mjs} +0 -0
  368. /package/dist/{email-console-ChgKFO8-.mjs → email-console-BEMwuxhV.mjs} +0 -0
  369. /package/dist/{escape-Bd4P_xKg.mjs → escape-smSUOb7u.mjs} +0 -0
  370. /package/dist/{hash-BPmX6P8I.mjs → hash-mxxx2oPW.mjs} +0 -0
  371. /package/dist/{media-url-lEKSrpr9.mjs → media-url-B6d-yVI6.mjs} +0 -0
  372. /package/dist/{mime-CA7Lgovc.mjs → mime-C0vOHFm7.mjs} +0 -0
  373. /package/dist/{mode-C4CIyjtR.mjs → mode-DPC7segX.mjs} +0 -0
  374. /package/dist/{normalize-5ek_z7de.mjs → normalize-Cyt7JdF7.mjs} +0 -0
  375. /package/dist/{oauth-state-store-CNoXafF7.mjs → oauth-state-store-DPVzeoyY.mjs} +0 -0
  376. /package/dist/{oauth-user-lookup-Ygw4bNyt.mjs → oauth-user-lookup-3E5jlXrr.mjs} +0 -0
  377. /package/dist/{parser-C1nYd-81.mjs → parser-DX_c5iG3.mjs} +0 -0
  378. /package/dist/{passkey-config-BUwu8BA3.mjs → passkey-config-DE_0EGEP.mjs} +0 -0
  379. /package/dist/{patterns-BhAvqO0S.mjs → patterns-CoqlXUvk.mjs} +0 -0
  380. /package/dist/{placeholder-uvNRZBX9.d.mts → placeholder-C6ZjZcmJ.d.mts} +0 -0
  381. /package/dist/{portable-text-dA_UlJwW.mjs → portable-text-BASHceim.mjs} +0 -0
  382. /package/dist/{process-cache-7xgAO9JY.mjs → process-cache-CCDgti7j.mjs} +0 -0
  383. /package/dist/{provider-loader-D0w9dqjm.mjs → provider-loader-BeQcnPN1.mjs} +0 -0
  384. /package/dist/{public-url-BEz_sM9n.mjs → public-url-BA-7LKvQ.mjs} +0 -0
  385. /package/dist/{redirect-wphRBv4y.mjs → redirect-CZFAqHLr.mjs} +0 -0
  386. /package/dist/{request-cache-D9GQBxMP.mjs → request-cache-CBFjCwSt.mjs} +0 -0
  387. /package/dist/{resolve-Cb6Dbz-C.mjs → resolve-B6BpqwAR.mjs} +0 -0
  388. /package/dist/{seo-qa7Dn0jK.mjs → seo-BLszyJxd.mjs} +0 -0
  389. /package/dist/{seo-contributions-C1EnikHB.mjs → seo-contributions-Ci8_12_r.mjs} +0 -0
  390. /package/dist/{session-user-CAKImna3.mjs → session-user-BwliEFp0.mjs} +0 -0
  391. /package/dist/{setup-complete-B8fl-mjV.mjs → setup-complete-PvF8I7Oh.mjs} +0 -0
  392. /package/dist/{setup-nonce-CoyjILvW.mjs → setup-nonce-DkpYROqg.mjs} +0 -0
  393. /package/dist/{sidecar-client-C3mqXg4C.mjs → sidecar-client-dt5fv23q.mjs} +0 -0
  394. /package/dist/{site-url-BML3GQYm.mjs → site-url-DfYDZyWl.mjs} +0 -0
  395. /package/dist/{ssrf-DWe8jwAp.mjs → ssrf-BZHvtFEv.mjs} +0 -0
  396. /package/dist/{status-DANd8ERo.mjs → status-BN40hMpr.mjs} +0 -0
  397. /package/dist/{tokens-1RK1n6ED.mjs → tokens-DIzhPT80.mjs} +0 -0
  398. /package/dist/{transaction-C2EOMTJA.mjs → transaction-0LEAAy8R.mjs} +0 -0
  399. /package/dist/{transport-CcJu3Co8.d.mts → transport-BZ3aqdu7.d.mts} +0 -0
  400. /package/dist/{transport-BNmCqLu7.mjs → transport-C46KHLMP.mjs} +0 -0
  401. /package/dist/{trusted-proxy-DTXQ2IMv.mjs → trusted-proxy-czZuby6G.mjs} +0 -0
  402. /package/dist/{types-B3t5cxhU.mjs → types-B7TDDFMG.mjs} +0 -0
  403. /package/dist/{types-CDpH6MA4.d.mts → types-BsTXSvKG.d.mts} +0 -0
  404. /package/dist/{types-DF7ZuGGk.d.mts → types-CDcuRd4z.d.mts} +0 -0
  405. /package/dist/{types-Rc3gQqqw.d.mts → types-S9VIopdY.d.mts} +0 -0
  406. /package/dist/{types-POH8PQZh.d.mts → types-YxFz4lDr.d.mts} +0 -0
  407. /package/dist/{types-C5CVgwsV.mjs → types-gvNBqijt.mjs} +0 -0
  408. /package/dist/{url-CpyFDFpO.mjs → url-D282S1Zw.mjs} +0 -0
  409. /package/dist/{url-Cac7a9QZ.mjs → url-guoXQQcV.mjs} +0 -0
@@ -25,8 +25,8 @@ var __exportAll = (all, no_symbols) => {
25
25
  //#endregion
26
26
  //#region src/database/migrations/001_initial.ts
27
27
  var _001_initial_exports = /* @__PURE__ */ __exportAll({
28
- down: () => down$104,
29
- up: () => up$104
28
+ down: () => down$111,
29
+ up: () => up$111
30
30
  });
31
31
  /**
32
32
  * Initial schema migration
@@ -35,7 +35,7 @@ var _001_initial_exports = /* @__PURE__ */ __exportAll({
35
35
  * by the SchemaRegistry when collections are added via the admin UI.
36
36
  * This migration only creates system tables.
37
37
  */
38
- async function up$104(db) {
38
+ async function up$111(db) {
39
39
  await db.schema.createTable("revisions").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("collection", "text", (col) => col.notNull()).addColumn("entry_id", "text", (col) => col.notNull()).addColumn("data", "text", (col) => col.notNull()).addColumn("author_id", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
40
40
  await db.schema.createIndex("idx_revisions_entry").ifNotExists().on("revisions").columns(["collection", "entry_id"]).execute();
41
41
  await db.schema.createTable("taxonomies").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull()).addColumn("slug", "text", (col) => col.notNull()).addColumn("label", "text", (col) => col.notNull()).addColumn("parent_id", "text").addColumn("data", "text").addUniqueConstraint("taxonomies_name_slug_unique", ["name", "slug"]).addForeignKeyConstraint("taxonomies_parent_fk", ["parent_id"], "taxonomies", ["id"], (cb) => cb.onDelete("set null")).execute();
@@ -55,7 +55,7 @@ async function up$104(db) {
55
55
  await db.schema.createIndex("idx_audit_action").ifNotExists().on("audit_logs").column("action").execute();
56
56
  await db.schema.createIndex("idx_audit_timestamp").ifNotExists().on("audit_logs").column("timestamp").execute();
57
57
  }
58
- async function down$104(db) {
58
+ async function down$111(db) {
59
59
  await db.schema.dropTable("audit_logs").execute();
60
60
  await db.schema.dropTable("options").execute();
61
61
  await db.schema.dropTable("users").execute();
@@ -68,26 +68,26 @@ async function down$104(db) {
68
68
  //#endregion
69
69
  //#region src/database/migrations/002_media_status.ts
70
70
  var _002_media_status_exports = /* @__PURE__ */ __exportAll({
71
- down: () => down$103,
72
- up: () => up$103
71
+ down: () => down$110,
72
+ up: () => up$110
73
73
  });
74
74
  /**
75
75
  * Add status column to media table for tracking upload state.
76
76
  * Status values: 'pending' | 'ready' | 'failed'
77
77
  */
78
- async function up$103(db) {
78
+ async function up$110(db) {
79
79
  await db.schema.alterTable("media").addColumn("status", "text", (col) => col.notNull().defaultTo("ready")).execute();
80
80
  await db.schema.createIndex("idx_media_status").on("media").column("status").execute();
81
81
  }
82
- async function down$103(db) {
82
+ async function down$110(db) {
83
83
  await db.schema.dropIndex("idx_media_status").execute();
84
84
  }
85
85
 
86
86
  //#endregion
87
87
  //#region src/database/migrations/003_schema_registry.ts
88
88
  var _003_schema_registry_exports = /* @__PURE__ */ __exportAll({
89
- down: () => down$102,
90
- up: () => up$102
89
+ down: () => down$109,
90
+ up: () => up$109
91
91
  });
92
92
  /**
93
93
  * Migration: Schema Registry Tables
@@ -95,14 +95,14 @@ var _003_schema_registry_exports = /* @__PURE__ */ __exportAll({
95
95
  * Creates the schema registry tables that store collection and field definitions.
96
96
  * This enables dynamic schema management where the database is the source of truth.
97
97
  */
98
- async function up$102(db) {
98
+ async function up$109(db) {
99
99
  await db.schema.createTable("_dineway_collections").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("label_singular", "text").addColumn("description", "text").addColumn("icon", "text").addColumn("supports", "text").addColumn("source", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
100
100
  await db.schema.createTable("_dineway_fields").addColumn("id", "text", (col) => col.primaryKey()).addColumn("collection_id", "text", (col) => col.notNull()).addColumn("slug", "text", (col) => col.notNull()).addColumn("label", "text", (col) => col.notNull()).addColumn("type", "text", (col) => col.notNull()).addColumn("column_type", "text", (col) => col.notNull()).addColumn("required", "integer", (col) => col.defaultTo(0)).addColumn("unique", "integer", (col) => col.defaultTo(0)).addColumn("default_value", "text").addColumn("validation", "text").addColumn("widget", "text").addColumn("options", "text").addColumn("sort_order", "integer", (col) => col.defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("fields_collection_fk", ["collection_id"], "_dineway_collections", ["id"], (cb) => cb.onDelete("cascade")).execute();
101
101
  await db.schema.createIndex("idx_fields_collection_slug").on("_dineway_fields").columns(["collection_id", "slug"]).unique().execute();
102
102
  await db.schema.createIndex("idx_fields_collection").on("_dineway_fields").column("collection_id").execute();
103
103
  await db.schema.createIndex("idx_fields_sort").on("_dineway_fields").columns(["collection_id", "sort_order"]).execute();
104
104
  }
105
- async function down$102(db) {
105
+ async function down$109(db) {
106
106
  await db.schema.dropTable("_dineway_fields").execute();
107
107
  await db.schema.dropTable("_dineway_collections").execute();
108
108
  }
@@ -110,8 +110,8 @@ async function down$102(db) {
110
110
  //#endregion
111
111
  //#region src/database/migrations/004_plugins.ts
112
112
  var _004_plugins_exports = /* @__PURE__ */ __exportAll({
113
- down: () => down$101,
114
- up: () => up$101
113
+ down: () => down$108,
114
+ up: () => up$108
115
115
  });
116
116
  /**
117
117
  * Migration: Plugin System Tables
@@ -121,7 +121,7 @@ var _004_plugins_exports = /* @__PURE__ */ __exportAll({
121
121
  *
122
122
  * @see PLUGIN-SYSTEM.md § Plugin Storage
123
123
  */
124
- async function up$101(db) {
124
+ async function up$108(db) {
125
125
  await db.schema.createTable("_plugin_storage").addColumn("plugin_id", "text", (col) => col.notNull()).addColumn("collection", "text", (col) => col.notNull()).addColumn("id", "text", (col) => col.notNull()).addColumn("data", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addPrimaryKeyConstraint("pk_plugin_storage", [
126
126
  "plugin_id",
127
127
  "collection",
@@ -139,7 +139,7 @@ async function up$101(db) {
139
139
  "index_name"
140
140
  ]).execute();
141
141
  }
142
- async function down$101(db) {
142
+ async function down$108(db) {
143
143
  await db.schema.dropTable("_plugin_indexes").execute();
144
144
  await db.schema.dropTable("_plugin_state").execute();
145
145
  await db.schema.dropTable("_plugin_storage").execute();
@@ -148,8 +148,8 @@ async function down$101(db) {
148
148
  //#endregion
149
149
  //#region src/database/migrations/005_menus.ts
150
150
  var _005_menus_exports = /* @__PURE__ */ __exportAll({
151
- down: () => down$100,
152
- up: () => up$100
151
+ down: () => down$107,
152
+ up: () => up$107
153
153
  });
154
154
  /**
155
155
  * Navigation Menus migration
@@ -157,13 +157,13 @@ var _005_menus_exports = /* @__PURE__ */ __exportAll({
157
157
  * Creates tables for admin-editable navigation menus.
158
158
  * Menu items can reference content entries, taxonomy terms, or custom URLs.
159
159
  */
160
- async function up$100(db) {
160
+ async function up$107(db) {
161
161
  await db.schema.createTable("_dineway_menus").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
162
162
  await db.schema.createTable("_dineway_menu_items").addColumn("id", "text", (col) => col.primaryKey()).addColumn("menu_id", "text", (col) => col.notNull()).addColumn("parent_id", "text").addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("type", "text", (col) => col.notNull()).addColumn("reference_collection", "text").addColumn("reference_id", "text").addColumn("custom_url", "text").addColumn("label", "text", (col) => col.notNull()).addColumn("title_attr", "text").addColumn("target", "text").addColumn("css_classes", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("menu_items_menu_fk", ["menu_id"], "_dineway_menus", ["id"], (cb) => cb.onDelete("cascade")).addForeignKeyConstraint("menu_items_parent_fk", ["parent_id"], "_dineway_menu_items", ["id"], (cb) => cb.onDelete("cascade")).execute();
163
163
  await db.schema.createIndex("idx_menu_items_menu").on("_dineway_menu_items").columns(["menu_id", "sort_order"]).execute();
164
164
  await db.schema.createIndex("idx_menu_items_parent").on("_dineway_menu_items").column("parent_id").execute();
165
165
  }
166
- async function down$100(db) {
166
+ async function down$107(db) {
167
167
  await db.schema.dropTable("_dineway_menu_items").execute();
168
168
  await db.schema.dropTable("_dineway_menus").execute();
169
169
  }
@@ -171,8 +171,8 @@ async function down$100(db) {
171
171
  //#endregion
172
172
  //#region src/database/migrations/006_taxonomy_defs.ts
173
173
  var _006_taxonomy_defs_exports = /* @__PURE__ */ __exportAll({
174
- down: () => down$99,
175
- up: () => up$99
174
+ down: () => down$106,
175
+ up: () => up$106
176
176
  });
177
177
  /**
178
178
  * Taxonomy definitions migration
@@ -180,7 +180,7 @@ var _006_taxonomy_defs_exports = /* @__PURE__ */ __exportAll({
180
180
  * Adds _dineway_taxonomy_defs table to store taxonomy definitions (category, tag, custom)
181
181
  * and seeds default category and tag taxonomies.
182
182
  */
183
- async function up$99(db) {
183
+ async function up$106(db) {
184
184
  await db.schema.createTable("_dineway_taxonomy_defs").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("label_singular", "text").addColumn("hierarchical", "integer", (col) => col.defaultTo(0)).addColumn("collections", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
185
185
  await db.insertInto("_dineway_taxonomy_defs").values([{
186
186
  id: "taxdef_category",
@@ -198,22 +198,22 @@ async function up$99(db) {
198
198
  collections: JSON.stringify(["posts"])
199
199
  }]).execute();
200
200
  }
201
- async function down$99(db) {
201
+ async function down$106(db) {
202
202
  await db.schema.dropTable("_dineway_taxonomy_defs").execute();
203
203
  }
204
204
 
205
205
  //#endregion
206
206
  //#region src/database/migrations/007_widgets.ts
207
207
  var _007_widgets_exports = /* @__PURE__ */ __exportAll({
208
- down: () => down$98,
209
- up: () => up$98
208
+ down: () => down$105,
209
+ up: () => up$105
210
210
  });
211
- async function up$98(db) {
211
+ async function up$105(db) {
212
212
  await db.schema.createTable("_dineway_widget_areas").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
213
213
  await db.schema.createTable("_dineway_widgets").addColumn("id", "text", (col) => col.primaryKey()).addColumn("area_id", "text", (col) => col.notNull().references("_dineway_widget_areas.id").onDelete("cascade")).addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("type", "text", (col) => col.notNull()).addColumn("title", "text").addColumn("content", "text").addColumn("menu_name", "text").addColumn("component_id", "text").addColumn("component_props", "text").addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
214
214
  await db.schema.createIndex("idx_widgets_area").on("_dineway_widgets").columns(["area_id", "sort_order"]).execute();
215
215
  }
216
- async function down$98(db) {
216
+ async function down$105(db) {
217
217
  await db.schema.dropTable("_dineway_widgets").execute();
218
218
  await db.schema.dropTable("_dineway_widget_areas").execute();
219
219
  }
@@ -221,8 +221,8 @@ async function down$98(db) {
221
221
  //#endregion
222
222
  //#region src/database/migrations/008_auth.ts
223
223
  var _008_auth_exports = /* @__PURE__ */ __exportAll({
224
- down: () => down$97,
225
- up: () => up$97
224
+ down: () => down$104,
225
+ up: () => up$104
226
226
  });
227
227
  /**
228
228
  * Auth migration - passkey-first authentication
@@ -236,7 +236,7 @@ var _008_auth_exports = /* @__PURE__ */ __exportAll({
236
236
  * - Creates oauth_accounts table (external provider links)
237
237
  * - Creates allowed_domains table (self-signup)
238
238
  */
239
- async function up$97(db) {
239
+ async function up$104(db) {
240
240
  await db.schema.createTable("users_new").addColumn("id", "text", (col) => col.primaryKey()).addColumn("email", "text", (col) => col.notNull().unique()).addColumn("name", "text").addColumn("avatar_url", "text").addColumn("role", "integer", (col) => col.notNull().defaultTo(10)).addColumn("email_verified", "integer", (col) => col.notNull().defaultTo(0)).addColumn("data", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
241
241
  await sql`
242
242
  INSERT INTO users_new (id, email, name, role, data, created_at, updated_at)
@@ -269,7 +269,7 @@ async function up$97(db) {
269
269
  await db.schema.createTable("auth_challenges").addColumn("challenge", "text", (col) => col.primaryKey()).addColumn("type", "text", (col) => col.notNull()).addColumn("user_id", "text").addColumn("data", "text").addColumn("expires_at", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
270
270
  await db.schema.createIndex("idx_auth_challenges_expires").on("auth_challenges").column("expires_at").execute();
271
271
  }
272
- async function down$97(db) {
272
+ async function down$104(db) {
273
273
  await db.schema.dropTable("auth_challenges").execute();
274
274
  await db.schema.dropTable("allowed_domains").execute();
275
275
  await db.schema.dropTable("oauth_accounts").execute();
@@ -302,8 +302,8 @@ async function down$97(db) {
302
302
  //#endregion
303
303
  //#region src/database/migrations/009_user_disabled.ts
304
304
  var _009_user_disabled_exports = /* @__PURE__ */ __exportAll({
305
- down: () => down$96,
306
- up: () => up$96
305
+ down: () => down$103,
306
+ up: () => up$103
307
307
  });
308
308
  /**
309
309
  * User disabled column - for soft-disabling users
@@ -312,19 +312,19 @@ var _009_user_disabled_exports = /* @__PURE__ */ __exportAll({
312
312
  * - Adds disabled column to users table (INTEGER, default 0)
313
313
  * - Disabled users cannot log in
314
314
  */
315
- async function up$96(db) {
315
+ async function up$103(db) {
316
316
  await sql`ALTER TABLE users ADD COLUMN disabled INTEGER NOT NULL DEFAULT 0`.execute(db);
317
317
  await db.schema.createIndex("idx_users_disabled").on("users").column("disabled").execute();
318
318
  }
319
- async function down$96(db) {
319
+ async function down$103(db) {
320
320
  await db.schema.dropIndex("idx_users_disabled").execute();
321
321
  }
322
322
 
323
323
  //#endregion
324
324
  //#region src/database/migrations/011_sections.ts
325
325
  var _011_sections_exports = /* @__PURE__ */ __exportAll({
326
- down: () => down$95,
327
- up: () => up$95
326
+ down: () => down$102,
327
+ up: () => up$102
328
328
  });
329
329
  /**
330
330
  * Migration: Add sections tables and performance indexes
@@ -333,13 +333,13 @@ var _011_sections_exports = /* @__PURE__ */ __exportAll({
333
333
  * They provide a library of pre-built page sections (heroes, CTAs, testimonials, etc.)
334
334
  * that content authors can browse and insert with a single click.
335
335
  */
336
- async function up$95(db) {
336
+ async function up$102(db) {
337
337
  await db.schema.createTable("_dineway_section_categories").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("sort_order", "integer", (col) => col.defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
338
338
  await db.schema.createTable("_dineway_sections").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("title", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("category_id", "text", (col) => col.references("_dineway_section_categories.id").onDelete("set null")).addColumn("keywords", "text").addColumn("content", "text", (col) => col.notNull()).addColumn("preview_media_id", "text").addColumn("source", "text", (col) => col.notNull().defaultTo("user")).addColumn("theme_id", "text").addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).addColumn("updated_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
339
339
  await db.schema.createIndex("idx_sections_category").on("_dineway_sections").columns(["category_id"]).execute();
340
340
  await db.schema.createIndex("idx_sections_source").on("_dineway_sections").columns(["source"]).execute();
341
341
  }
342
- async function down$95(db) {
342
+ async function down$102(db) {
343
343
  await db.schema.dropIndex("idx_sections_source").execute();
344
344
  await db.schema.dropIndex("idx_sections_category").execute();
345
345
  await db.schema.dropTable("_dineway_sections").execute();
@@ -349,8 +349,8 @@ async function down$95(db) {
349
349
  //#endregion
350
350
  //#region src/database/migrations/012_search.ts
351
351
  var _012_search_exports = /* @__PURE__ */ __exportAll({
352
- down: () => down$94,
353
- up: () => up$94
352
+ down: () => down$101,
353
+ up: () => up$101
354
354
  });
355
355
  /**
356
356
  * Migration: Search Support
@@ -358,11 +358,11 @@ var _012_search_exports = /* @__PURE__ */ __exportAll({
358
358
  * Adds search configuration to collections and searchable flag to fields.
359
359
  * FTS5 tables are created dynamically when search is enabled for a collection.
360
360
  */
361
- async function up$94(db) {
361
+ async function up$101(db) {
362
362
  await db.schema.alterTable("_dineway_collections").addColumn("search_config", "text").execute();
363
363
  await db.schema.alterTable("_dineway_fields").addColumn("searchable", "integer", (col) => col.defaultTo(0)).execute();
364
364
  }
365
- async function down$94(db) {
365
+ async function down$101(db) {
366
366
  await db.schema.alterTable("_dineway_fields").dropColumn("searchable").execute();
367
367
  await db.schema.alterTable("_dineway_collections").dropColumn("search_config").execute();
368
368
  }
@@ -370,8 +370,8 @@ async function down$94(db) {
370
370
  //#endregion
371
371
  //#region src/database/migrations/013_scheduled_publishing.ts
372
372
  var _013_scheduled_publishing_exports = /* @__PURE__ */ __exportAll({
373
- down: () => down$93,
374
- up: () => up$93
373
+ down: () => down$100,
374
+ up: () => up$100
375
375
  });
376
376
  /**
377
377
  * Migration: Add scheduled publishing support
@@ -380,7 +380,7 @@ var _013_scheduled_publishing_exports = /* @__PURE__ */ __exportAll({
380
380
  * When scheduled_at is set and status is 'scheduled', the content
381
381
  * will be auto-published when the scheduled time is reached.
382
382
  */
383
- async function up$93(db) {
383
+ async function up$100(db) {
384
384
  const tableNames = await listTablesLike(db, "ec_%");
385
385
  for (const tableName of tableNames) {
386
386
  const table = { name: tableName };
@@ -395,7 +395,7 @@ async function up$93(db) {
395
395
  `.execute(db);
396
396
  }
397
397
  }
398
- async function down$93(db) {
398
+ async function down$100(db) {
399
399
  const tableNames = await listTablesLike(db, "ec_%");
400
400
  for (const tableName of tableNames) {
401
401
  const table = { name: tableName };
@@ -412,10 +412,10 @@ async function down$93(db) {
412
412
  //#endregion
413
413
  //#region src/database/migrations/014_draft_revisions.ts
414
414
  var _014_draft_revisions_exports = /* @__PURE__ */ __exportAll({
415
- down: () => down$92,
416
- up: () => up$92
415
+ down: () => down$99,
416
+ up: () => up$99
417
417
  });
418
- async function up$92(db) {
418
+ async function up$99(db) {
419
419
  const tables = await db.selectFrom("_dineway_collections").select("slug").execute();
420
420
  for (const row of tables) {
421
421
  const tableName = `ec_${row.slug}`;
@@ -437,7 +437,7 @@ async function up$92(db) {
437
437
  `.execute(db);
438
438
  }
439
439
  }
440
- async function down$92(db) {
440
+ async function down$99(db) {
441
441
  const tables = await db.selectFrom("_dineway_collections").select("slug").execute();
442
442
  for (const row of tables) {
443
443
  const tableName = `ec_${row.slug}`;
@@ -461,8 +461,8 @@ async function down$92(db) {
461
461
  //#endregion
462
462
  //#region src/database/migrations/015_indexes.ts
463
463
  var _015_indexes_exports = /* @__PURE__ */ __exportAll({
464
- down: () => down$91,
465
- up: () => up$91
464
+ down: () => down$98,
465
+ up: () => up$98
466
466
  });
467
467
  /**
468
468
  * Add performance indexes for common query patterns.
@@ -475,7 +475,7 @@ var _015_indexes_exports = /* @__PURE__ */ __exportAll({
475
475
  * 5. Retroactive author_id + updated_at on existing ec_* content tables
476
476
  * (new tables get these from createContentTable() in registry.ts)
477
477
  */
478
- async function up$91(db) {
478
+ async function up$98(db) {
479
479
  await db.schema.createIndex("idx_media_mime_type").on("media").column("mime_type").execute();
480
480
  await db.schema.createIndex("idx_media_filename").on("media").column("filename").execute();
481
481
  await db.schema.createIndex("idx_media_created_at").on("media").column("created_at").execute();
@@ -495,7 +495,7 @@ async function up$91(db) {
495
495
  `.execute(db);
496
496
  }
497
497
  }
498
- async function down$91(db) {
498
+ async function down$98(db) {
499
499
  const tableNames = await listTablesLike(db, "ec_%");
500
500
  for (const tableName of tableNames) {
501
501
  const table = { name: tableName };
@@ -513,8 +513,8 @@ async function down$91(db) {
513
513
  //#endregion
514
514
  //#region src/database/migrations/016_api_tokens.ts
515
515
  var _016_api_tokens_exports = /* @__PURE__ */ __exportAll({
516
- down: () => down$90,
517
- up: () => up$90
516
+ down: () => down$97,
517
+ up: () => up$97
518
518
  });
519
519
  /**
520
520
  * API token tables for programmatic access.
@@ -528,7 +528,7 @@ var _016_api_tokens_exports = /* @__PURE__ */ __exportAll({
528
528
  * created only part of the schema before failing and never recorded the
529
529
  * migration as applied.
530
530
  */
531
- async function up$90(db) {
531
+ async function up$97(db) {
532
532
  await db.schema.createTable("_dineway_api_tokens").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull()).addColumn("token_hash", "text", (col) => col.notNull().unique()).addColumn("prefix", "text", (col) => col.notNull()).addColumn("user_id", "text", (col) => col.notNull()).addColumn("scopes", "text", (col) => col.notNull()).addColumn("expires_at", "text").addColumn("last_used_at", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("api_tokens_user_fk", ["user_id"], "users", ["id"], (cb) => cb.onDelete("cascade")).execute();
533
533
  await db.schema.createIndex("idx_api_tokens_token_hash").ifNotExists().on("_dineway_api_tokens").column("token_hash").execute();
534
534
  await db.schema.createIndex("idx_api_tokens_user_id").ifNotExists().on("_dineway_api_tokens").column("user_id").execute();
@@ -537,7 +537,7 @@ async function up$90(db) {
537
537
  await db.schema.createIndex("idx_oauth_tokens_expires").ifNotExists().on("_dineway_oauth_tokens").column("expires_at").execute();
538
538
  await db.schema.createTable("_dineway_device_codes").ifNotExists().addColumn("device_code", "text", (col) => col.primaryKey()).addColumn("user_code", "text", (col) => col.notNull().unique()).addColumn("scopes", "text", (col) => col.notNull()).addColumn("user_id", "text").addColumn("status", "text", (col) => col.notNull().defaultTo("pending")).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("interval", "integer", (col) => col.notNull().defaultTo(5)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
539
539
  }
540
- async function down$90(db) {
540
+ async function down$97(db) {
541
541
  await db.schema.dropTable("_dineway_device_codes").ifExists().execute();
542
542
  await db.schema.dropTable("_dineway_oauth_tokens").ifExists().execute();
543
543
  await db.schema.dropTable("_dineway_api_tokens").ifExists().execute();
@@ -546,8 +546,8 @@ async function down$90(db) {
546
546
  //#endregion
547
547
  //#region src/database/migrations/017_authorization_codes.ts
548
548
  var _017_authorization_codes_exports = /* @__PURE__ */ __exportAll({
549
- down: () => down$89,
550
- up: () => up$89
549
+ down: () => down$96,
550
+ up: () => up$96
551
551
  });
552
552
  /**
553
553
  * Authorization codes for OAuth 2.1 Authorization Code + PKCE flow.
@@ -557,20 +557,20 @@ var _017_authorization_codes_exports = /* @__PURE__ */ __exportAll({
557
557
  *
558
558
  * Also adds client_id tracking to oauth_tokens for per-client revocation.
559
559
  */
560
- async function up$89(db) {
560
+ async function up$96(db) {
561
561
  await db.schema.createTable("_dineway_authorization_codes").addColumn("code_hash", "text", (col) => col.primaryKey()).addColumn("client_id", "text", (col) => col.notNull()).addColumn("redirect_uri", "text", (col) => col.notNull()).addColumn("user_id", "text", (col) => col.notNull()).addColumn("scopes", "text", (col) => col.notNull()).addColumn("code_challenge", "text", (col) => col.notNull()).addColumn("code_challenge_method", "text", (col) => col.notNull().defaultTo("S256")).addColumn("resource", "text").addColumn("expires_at", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("auth_codes_user_fk", ["user_id"], "users", ["id"], (cb) => cb.onDelete("cascade")).execute();
562
562
  await db.schema.createIndex("idx_auth_codes_expires").on("_dineway_authorization_codes").column("expires_at").execute();
563
563
  await sql`ALTER TABLE _dineway_oauth_tokens ADD COLUMN client_id TEXT`.execute(db);
564
564
  }
565
- async function down$89(db) {
565
+ async function down$96(db) {
566
566
  await db.schema.dropTable("_dineway_authorization_codes").execute();
567
567
  }
568
568
 
569
569
  //#endregion
570
570
  //#region src/database/migrations/018_seo.ts
571
571
  var _018_seo_exports = /* @__PURE__ */ __exportAll({
572
- down: () => down$88,
573
- up: () => up$88
572
+ down: () => down$95,
573
+ up: () => up$95
574
574
  });
575
575
  /**
576
576
  * Migration: SEO support
@@ -583,7 +583,7 @@ var _018_seo_exports = /* @__PURE__ */ __exportAll({
583
583
  * need it. The `has_seo` flag controls whether the admin shows SEO fields
584
584
  * and whether the collection's content appears in sitemaps.
585
585
  */
586
- async function up$88(db) {
586
+ async function up$95(db) {
587
587
  await db.schema.createTable("_dineway_seo").addColumn("collection", "text", (col) => col.notNull()).addColumn("content_id", "text", (col) => col.notNull()).addColumn("seo_title", "text").addColumn("seo_description", "text").addColumn("seo_image", "text").addColumn("seo_canonical", "text").addColumn("seo_no_index", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addPrimaryKeyConstraint("_dineway_seo_pk", ["collection", "content_id"]).execute();
588
588
  await sql`
589
589
  CREATE INDEX idx_dineway_seo_collection
@@ -594,7 +594,7 @@ async function up$88(db) {
594
594
  ADD COLUMN has_seo INTEGER NOT NULL DEFAULT 0
595
595
  `.execute(db);
596
596
  }
597
- async function down$88(db) {
597
+ async function down$95(db) {
598
598
  await sql`DROP TABLE IF EXISTS _dineway_seo`.execute(db);
599
599
  await sql`
600
600
  ALTER TABLE _dineway_collections
@@ -605,8 +605,8 @@ async function down$88(db) {
605
605
  //#endregion
606
606
  //#region src/database/migrations/019_i18n.ts
607
607
  var _019_i18n_exports = /* @__PURE__ */ __exportAll({
608
- down: () => down$87,
609
- up: () => up$87
608
+ down: () => down$94,
609
+ up: () => up$94
610
610
  });
611
611
  /**
612
612
  * Quote an identifier for use in raw SQL. Escapes embedded double-quotes
@@ -719,7 +719,7 @@ async function upPostgres(db) {
719
719
  ADD COLUMN translatable INTEGER NOT NULL DEFAULT 1
720
720
  `.execute(db);
721
721
  }
722
- async function up$87(db) {
722
+ async function up$94(db) {
723
723
  if (!isSqlite(db)) return upPostgres(db);
724
724
  const orphanedTmps = await listTablesLike(db, "ec_%_i18n_tmp");
725
725
  for (const tmpName of orphanedTmps) {
@@ -836,7 +836,7 @@ async function downPostgres(db) {
836
836
  await sql`ALTER TABLE ${sql.ref(t)} DROP COLUMN translation_group`.execute(db);
837
837
  }
838
838
  }
839
- async function down$87(db) {
839
+ async function down$94(db) {
840
840
  if (!isSqlite(db)) return downPostgres(db);
841
841
  await sql`
842
842
  ALTER TABLE _dineway_fields
@@ -943,8 +943,8 @@ async function down$87(db) {
943
943
  //#endregion
944
944
  //#region src/database/migrations/020_collection_url_pattern.ts
945
945
  var _020_collection_url_pattern_exports = /* @__PURE__ */ __exportAll({
946
- down: () => down$86,
947
- up: () => up$86
946
+ down: () => down$93,
947
+ up: () => up$93
948
948
  });
949
949
  /**
950
950
  * Migration: URL pattern for collections
@@ -953,13 +953,13 @@ var _020_collection_url_pattern_exports = /* @__PURE__ */ __exportAll({
953
953
  * can declare its own URL structure (e.g. "/{slug}" for pages, "/blog/{slug}"
954
954
  * for posts). Used for menu URL resolution, sitemaps, and path-based lookups.
955
955
  */
956
- async function up$86(db) {
956
+ async function up$93(db) {
957
957
  await sql`
958
958
  ALTER TABLE _dineway_collections
959
959
  ADD COLUMN url_pattern TEXT
960
960
  `.execute(db);
961
961
  }
962
- async function down$86(db) {
962
+ async function down$93(db) {
963
963
  await sql`
964
964
  ALTER TABLE _dineway_collections
965
965
  DROP COLUMN url_pattern
@@ -969,8 +969,8 @@ async function down$86(db) {
969
969
  //#endregion
970
970
  //#region src/database/migrations/021_remove_section_categories.ts
971
971
  var _021_remove_section_categories_exports = /* @__PURE__ */ __exportAll({
972
- down: () => down$85,
973
- up: () => up$85
972
+ down: () => down$92,
973
+ up: () => up$92
974
974
  });
975
975
  /**
976
976
  * Migration: Remove section categories
@@ -979,12 +979,12 @@ var _021_remove_section_categories_exports = /* @__PURE__ */ __exportAll({
979
979
  * Rather than building the missing UI for a feature with very little need at this stage,
980
980
  * we're removing the feature entirely.
981
981
  */
982
- async function up$85(db) {
982
+ async function up$92(db) {
983
983
  await db.schema.dropIndex("idx_sections_category").ifExists().execute();
984
984
  await db.schema.alterTable("_dineway_sections").dropColumn("category_id").execute();
985
985
  await db.schema.dropTable("_dineway_section_categories").execute();
986
986
  }
987
- async function down$85(db) {
987
+ async function down$92(db) {
988
988
  await db.schema.createTable("_dineway_section_categories").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("sort_order", "integer", (col) => col.defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
989
989
  await db.schema.alterTable("_dineway_sections").addColumn("category_id", "text", (col) => col.references("_dineway_section_categories.id").onDelete("set null")).execute();
990
990
  await db.schema.createIndex("idx_sections_category").on("_dineway_sections").columns(["category_id"]).execute();
@@ -993,8 +993,8 @@ async function down$85(db) {
993
993
  //#endregion
994
994
  //#region src/database/migrations/022_marketplace_plugin_state.ts
995
995
  var _022_marketplace_plugin_state_exports = /* @__PURE__ */ __exportAll({
996
- down: () => down$84,
997
- up: () => up$84
996
+ down: () => down$91,
997
+ up: () => up$91
998
998
  });
999
999
  /**
1000
1000
  * Migration: Add marketplace fields to _plugin_state
@@ -1003,7 +1003,7 @@ var _022_marketplace_plugin_state_exports = /* @__PURE__ */ __exportAll({
1003
1003
  * whether a plugin was installed from config or marketplace,
1004
1004
  * and which marketplace version is installed.
1005
1005
  */
1006
- async function up$84(db) {
1006
+ async function up$91(db) {
1007
1007
  await sql`
1008
1008
  ALTER TABLE _plugin_state
1009
1009
  ADD COLUMN source TEXT NOT NULL DEFAULT 'config'
@@ -1018,7 +1018,7 @@ async function up$84(db) {
1018
1018
  WHERE source = 'marketplace'
1019
1019
  `.execute(db);
1020
1020
  }
1021
- async function down$84(db) {
1021
+ async function down$91(db) {
1022
1022
  await sql`
1023
1023
  DROP INDEX IF EXISTS idx_plugin_state_source
1024
1024
  `.execute(db);
@@ -1035,8 +1035,8 @@ async function down$84(db) {
1035
1035
  //#endregion
1036
1036
  //#region src/database/migrations/023_plugin_metadata.ts
1037
1037
  var _023_plugin_metadata_exports = /* @__PURE__ */ __exportAll({
1038
- down: () => down$83,
1039
- up: () => up$83
1038
+ down: () => down$90,
1039
+ up: () => up$90
1040
1040
  });
1041
1041
  /**
1042
1042
  * Migration: Add display metadata to _plugin_state
@@ -1045,7 +1045,7 @@ var _023_plugin_metadata_exports = /* @__PURE__ */ __exportAll({
1045
1045
  * so the admin UI can show meaningful info without re-fetching
1046
1046
  * from the marketplace on every page load.
1047
1047
  */
1048
- async function up$83(db) {
1048
+ async function up$90(db) {
1049
1049
  await sql`
1050
1050
  ALTER TABLE _plugin_state
1051
1051
  ADD COLUMN display_name TEXT
@@ -1055,7 +1055,7 @@ async function up$83(db) {
1055
1055
  ADD COLUMN description TEXT
1056
1056
  `.execute(db);
1057
1057
  }
1058
- async function down$83(db) {
1058
+ async function down$90(db) {
1059
1059
  await sql`
1060
1060
  ALTER TABLE _plugin_state
1061
1061
  DROP COLUMN description
@@ -1069,8 +1069,8 @@ async function down$83(db) {
1069
1069
  //#endregion
1070
1070
  //#region src/database/migrations/024_media_placeholders.ts
1071
1071
  var _024_media_placeholders_exports = /* @__PURE__ */ __exportAll({
1072
- down: () => down$82,
1073
- up: () => up$82
1072
+ down: () => down$89,
1073
+ up: () => up$89
1074
1074
  });
1075
1075
  /**
1076
1076
  * Migration: Add placeholder columns to media table
@@ -1078,7 +1078,7 @@ var _024_media_placeholders_exports = /* @__PURE__ */ __exportAll({
1078
1078
  * Stores blurhash and dominant_color for LQIP (Low Quality Image Placeholder)
1079
1079
  * support. Generated at upload time from image pixel data.
1080
1080
  */
1081
- async function up$82(db) {
1081
+ async function up$89(db) {
1082
1082
  await sql`
1083
1083
  ALTER TABLE media
1084
1084
  ADD COLUMN blurhash TEXT
@@ -1088,7 +1088,7 @@ async function up$82(db) {
1088
1088
  ADD COLUMN dominant_color TEXT
1089
1089
  `.execute(db);
1090
1090
  }
1091
- async function down$82(db) {
1091
+ async function down$89(db) {
1092
1092
  await sql`
1093
1093
  ALTER TABLE media
1094
1094
  DROP COLUMN dominant_color
@@ -1102,8 +1102,8 @@ async function down$82(db) {
1102
1102
  //#endregion
1103
1103
  //#region src/database/migrations/025_oauth_clients.ts
1104
1104
  var _025_oauth_clients_exports = /* @__PURE__ */ __exportAll({
1105
- down: () => down$81,
1106
- up: () => up$81
1105
+ down: () => down$88,
1106
+ up: () => up$88
1107
1107
  });
1108
1108
  /**
1109
1109
  * Migration: Create OAuth clients table
@@ -1114,18 +1114,18 @@ var _025_oauth_clients_exports = /* @__PURE__ */ __exportAll({
1114
1114
  * Each client has a set of pre-registered redirect URIs (JSON array).
1115
1115
  * The authorize endpoint rejects any redirect_uri not in the client's list.
1116
1116
  */
1117
- async function up$81(db) {
1117
+ async function up$88(db) {
1118
1118
  await db.schema.createTable("_dineway_oauth_clients").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull()).addColumn("redirect_uris", "text", (col) => col.notNull()).addColumn("scopes", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
1119
1119
  }
1120
- async function down$81(db) {
1120
+ async function down$88(db) {
1121
1121
  await db.schema.dropTable("_dineway_oauth_clients").execute();
1122
1122
  }
1123
1123
 
1124
1124
  //#endregion
1125
1125
  //#region src/database/migrations/026_cron_tasks.ts
1126
1126
  var _026_cron_tasks_exports = /* @__PURE__ */ __exportAll({
1127
- down: () => down$80,
1128
- up: () => up$80
1127
+ down: () => down$87,
1128
+ up: () => up$87
1129
1129
  });
1130
1130
  /**
1131
1131
  * Migration: Create cron tasks table for plugin scheduled tasks.
@@ -1136,7 +1136,7 @@ var _026_cron_tasks_exports = /* @__PURE__ */ __exportAll({
1136
1136
  * The `next_run_at` + `status` + `enabled` index drives the "find overdue
1137
1137
  * tasks" query used by CronExecutor.tick().
1138
1138
  */
1139
- async function up$80(db) {
1139
+ async function up$87(db) {
1140
1140
  await db.schema.createTable("_dineway_cron_tasks").addColumn("id", "text", (col) => col.primaryKey()).addColumn("plugin_id", "text", (col) => col.notNull()).addColumn("task_name", "text", (col) => col.notNull()).addColumn("schedule", "text", (col) => col.notNull()).addColumn("is_oneshot", "integer", (col) => col.notNull().defaultTo(0)).addColumn("data", "text").addColumn("next_run_at", "text", (col) => col.notNull()).addColumn("last_run_at", "text").addColumn("status", "text", (col) => col.notNull().defaultTo("idle")).addColumn("locked_at", "text").addColumn("enabled", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_cron_tasks_plugin_task", ["plugin_id", "task_name"]).execute();
1141
1141
  await db.schema.createIndex("idx_cron_tasks_due").on("_dineway_cron_tasks").columns([
1142
1142
  "enabled",
@@ -1145,17 +1145,17 @@ async function up$80(db) {
1145
1145
  ]).execute();
1146
1146
  await db.schema.createIndex("idx_cron_tasks_plugin").on("_dineway_cron_tasks").column("plugin_id").execute();
1147
1147
  }
1148
- async function down$80(db) {
1148
+ async function down$87(db) {
1149
1149
  await db.schema.dropTable("_dineway_cron_tasks").execute();
1150
1150
  }
1151
1151
 
1152
1152
  //#endregion
1153
1153
  //#region src/database/migrations/027_comments.ts
1154
1154
  var _027_comments_exports = /* @__PURE__ */ __exportAll({
1155
- down: () => down$79,
1156
- up: () => up$79
1155
+ down: () => down$86,
1156
+ up: () => up$86
1157
1157
  });
1158
- async function up$79(db) {
1158
+ async function up$86(db) {
1159
1159
  await db.schema.createTable("_dineway_comments").addColumn("id", "text", (col) => col.primaryKey()).addColumn("collection", "text", (col) => col.notNull()).addColumn("content_id", "text", (col) => col.notNull()).addColumn("parent_id", "text", (col) => col.references("_dineway_comments.id").onDelete("cascade")).addColumn("author_name", "text", (col) => col.notNull()).addColumn("author_email", "text", (col) => col.notNull()).addColumn("author_url", "text").addColumn("author_user_id", "text", (col) => col.references("users.id").onDelete("set null")).addColumn("body", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().defaultTo("pending")).addColumn("ip_hash", "text").addColumn("user_agent", "text").addColumn("moderation_metadata", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
1160
1160
  await db.schema.createIndex("idx_comments_content").on("_dineway_comments").columns([
1161
1161
  "collection",
@@ -1171,30 +1171,30 @@ async function up$79(db) {
1171
1171
  await db.schema.alterTable("_dineway_collections").addColumn("comments_closed_after_days", "integer", (col) => col.defaultTo(90)).execute();
1172
1172
  await db.schema.alterTable("_dineway_collections").addColumn("comments_auto_approve_users", "integer", (col) => col.defaultTo(1)).execute();
1173
1173
  }
1174
- async function down$79(db) {
1174
+ async function down$86(db) {
1175
1175
  await db.schema.dropTable("_dineway_comments").execute();
1176
1176
  }
1177
1177
 
1178
1178
  //#endregion
1179
1179
  //#region src/database/migrations/028_drop_author_url.ts
1180
1180
  var _028_drop_author_url_exports = /* @__PURE__ */ __exportAll({
1181
- down: () => down$78,
1182
- up: () => up$78
1181
+ down: () => down$85,
1182
+ up: () => up$85
1183
1183
  });
1184
- async function up$78(db) {
1184
+ async function up$85(db) {
1185
1185
  await sql`ALTER TABLE _dineway_comments DROP COLUMN author_url`.execute(db);
1186
1186
  }
1187
- async function down$78(db) {
1187
+ async function down$85(db) {
1188
1188
  await db.schema.alterTable("_dineway_comments").addColumn("author_url", "text").execute();
1189
1189
  }
1190
1190
 
1191
1191
  //#endregion
1192
1192
  //#region src/database/migrations/029_redirects.ts
1193
1193
  var _029_redirects_exports = /* @__PURE__ */ __exportAll({
1194
- down: () => down$77,
1195
- up: () => up$77
1194
+ down: () => down$84,
1195
+ up: () => up$84
1196
1196
  });
1197
- async function up$77(db) {
1197
+ async function up$84(db) {
1198
1198
  await db.schema.createTable("_dineway_redirects").addColumn("id", "text", (col) => col.primaryKey()).addColumn("source", "text", (col) => col.notNull()).addColumn("destination", "text", (col) => col.notNull()).addColumn("type", "integer", (col) => col.notNull().defaultTo(301)).addColumn("is_pattern", "integer", (col) => col.notNull().defaultTo(0)).addColumn("enabled", "integer", (col) => col.notNull().defaultTo(1)).addColumn("hits", "integer", (col) => col.notNull().defaultTo(0)).addColumn("last_hit_at", "text").addColumn("group_name", "text").addColumn("auto", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
1199
1199
  await db.schema.createIndex("idx_redirects_source").on("_dineway_redirects").column("source").execute();
1200
1200
  await db.schema.createIndex("idx_redirects_enabled").on("_dineway_redirects").column("enabled").execute();
@@ -1203,7 +1203,7 @@ async function up$77(db) {
1203
1203
  await db.schema.createIndex("idx_404_log_path").on("_dineway_404_log").column("path").execute();
1204
1204
  await db.schema.createIndex("idx_404_log_created").on("_dineway_404_log").column("created_at").execute();
1205
1205
  }
1206
- async function down$77(db) {
1206
+ async function down$84(db) {
1207
1207
  await db.schema.dropTable("_dineway_404_log").execute();
1208
1208
  await db.schema.dropTable("_dineway_redirects").execute();
1209
1209
  }
@@ -1211,8 +1211,8 @@ async function down$77(db) {
1211
1211
  //#endregion
1212
1212
  //#region src/database/migrations/030_widen_scheduled_index.ts
1213
1213
  var _030_widen_scheduled_index_exports = /* @__PURE__ */ __exportAll({
1214
- down: () => down$76,
1215
- up: () => up$76
1214
+ down: () => down$83,
1215
+ up: () => up$83
1216
1216
  });
1217
1217
  /**
1218
1218
  * Migration: Widen scheduled publishing index
@@ -1221,7 +1221,7 @@ var _030_widen_scheduled_index_exports = /* @__PURE__ */ __exportAll({
1221
1221
  * Published posts can now have scheduled draft changes, so widen the
1222
1222
  * index to cover all rows where scheduled_at IS NOT NULL.
1223
1223
  */
1224
- async function up$76(db) {
1224
+ async function up$83(db) {
1225
1225
  const tableNames = await listTablesLike(db, "ec_%");
1226
1226
  for (const tableName of tableNames) {
1227
1227
  const table = { name: tableName };
@@ -1235,7 +1235,7 @@ async function up$76(db) {
1235
1235
  `.execute(db);
1236
1236
  }
1237
1237
  }
1238
- async function down$76(db) {
1238
+ async function down$83(db) {
1239
1239
  const tableNames = await listTablesLike(db, "ec_%");
1240
1240
  for (const tableName of tableNames) {
1241
1241
  const table = { name: tableName };
@@ -1253,10 +1253,10 @@ async function down$76(db) {
1253
1253
  //#endregion
1254
1254
  //#region src/database/migrations/031_bylines.ts
1255
1255
  var _031_bylines_exports = /* @__PURE__ */ __exportAll({
1256
- down: () => down$75,
1257
- up: () => up$75
1256
+ down: () => down$82,
1257
+ up: () => up$82
1258
1258
  });
1259
- async function up$75(db) {
1259
+ async function up$82(db) {
1260
1260
  await db.schema.createTable("_dineway_bylines").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("display_name", "text", (col) => col.notNull()).addColumn("bio", "text").addColumn("avatar_media_id", "text", (col) => col.references("media.id").onDelete("set null")).addColumn("website_url", "text").addColumn("user_id", "text", (col) => col.references("users.id").onDelete("set null")).addColumn("is_guest", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
1261
1261
  await sql`
1262
1262
  CREATE UNIQUE INDEX ${sql.ref("idx_bylines_user_id_unique")}
@@ -1288,7 +1288,7 @@ async function up$75(db) {
1288
1288
  `.execute(db);
1289
1289
  }
1290
1290
  }
1291
- async function down$75(db) {
1291
+ async function down$82(db) {
1292
1292
  const tableNames = await listTablesLike(db, "ec_%");
1293
1293
  for (const tableName of tableNames) {
1294
1294
  await sql`
@@ -1306,8 +1306,8 @@ async function down$75(db) {
1306
1306
  //#endregion
1307
1307
  //#region src/database/migrations/032_rate_limits.ts
1308
1308
  var _032_rate_limits_exports = /* @__PURE__ */ __exportAll({
1309
- down: () => down$74,
1310
- up: () => up$74
1309
+ down: () => down$81,
1310
+ up: () => up$81
1311
1311
  });
1312
1312
  /**
1313
1313
  * Migration: Rate limits table + device code polling tracking.
@@ -1318,12 +1318,12 @@ var _032_rate_limits_exports = /* @__PURE__ */ __exportAll({
1318
1318
  * 2. Add last_polled_at column to _dineway_device_codes for
1319
1319
  * RFC 8628 slow_down enforcement.
1320
1320
  */
1321
- async function up$74(db) {
1321
+ async function up$81(db) {
1322
1322
  await db.schema.createTable("_dineway_rate_limits").addColumn("key", "text", (col) => col.notNull()).addColumn("window", "text", (col) => col.notNull()).addColumn("count", "integer", (col) => col.notNull().defaultTo(1)).addPrimaryKeyConstraint("pk_rate_limits", ["key", "window"]).execute();
1323
1323
  await db.schema.createIndex("idx_rate_limits_window").on("_dineway_rate_limits").column("window").execute();
1324
1324
  await db.schema.alterTable("_dineway_device_codes").addColumn("last_polled_at", "text").execute();
1325
1325
  }
1326
- async function down$74(db) {
1326
+ async function down$81(db) {
1327
1327
  await db.schema.dropTable("_dineway_rate_limits").execute();
1328
1328
  await db.schema.alterTable("_dineway_device_codes").dropColumn("last_polled_at").execute();
1329
1329
  }
@@ -1331,8 +1331,8 @@ async function down$74(db) {
1331
1331
  //#endregion
1332
1332
  //#region src/database/migrations/033_optimize_content_indexes.ts
1333
1333
  var _033_optimize_content_indexes_exports = /* @__PURE__ */ __exportAll({
1334
- down: () => down$73,
1335
- up: () => up$73
1334
+ down: () => down$80,
1335
+ up: () => up$80
1336
1336
  });
1337
1337
  /**
1338
1338
  * Migration: Optimize content table indexes for SQLite-compatible performance
@@ -1345,7 +1345,7 @@ var _033_optimize_content_indexes_exports = /* @__PURE__ */ __exportAll({
1345
1345
  *
1346
1346
  * Impact: Reduces row reads by 90%+ for admin panel operations on SQLite-compatible adapters.
1347
1347
  */
1348
- async function up$73(db) {
1348
+ async function up$80(db) {
1349
1349
  const tableNames = await listTablesLike(db, "ec_%");
1350
1350
  for (const tableName of tableNames) {
1351
1351
  const table = { name: tableName };
@@ -1387,7 +1387,7 @@ async function up$73(db) {
1387
1387
  WHERE status = 'trash'
1388
1388
  `.execute(db);
1389
1389
  }
1390
- async function down$73(db) {
1390
+ async function down$80(db) {
1391
1391
  const tableNames = await listTablesLike(db, "ec_%");
1392
1392
  for (const tableName of tableNames) {
1393
1393
  const table = { name: tableName };
@@ -1420,10 +1420,10 @@ async function down$73(db) {
1420
1420
  //#endregion
1421
1421
  //#region src/database/migrations/034_published_at_index.ts
1422
1422
  var _034_published_at_index_exports = /* @__PURE__ */ __exportAll({
1423
- down: () => down$72,
1424
- up: () => up$72
1423
+ down: () => down$79,
1424
+ up: () => up$79
1425
1425
  });
1426
- async function up$72(db) {
1426
+ async function up$79(db) {
1427
1427
  const tableNames = await listTablesLike(db, "ec_%");
1428
1428
  for (const tableName of tableNames) {
1429
1429
  const table = { name: tableName };
@@ -1433,7 +1433,7 @@ async function up$72(db) {
1433
1433
  `.execute(db);
1434
1434
  }
1435
1435
  }
1436
- async function down$72(db) {
1436
+ async function down$79(db) {
1437
1437
  const tableNames = await listTablesLike(db, "ec_%");
1438
1438
  for (const tableName of tableNames) {
1439
1439
  const table = { name: tableName };
@@ -1444,15 +1444,15 @@ async function down$72(db) {
1444
1444
  //#endregion
1445
1445
  //#region src/database/migrations/035_backfill_url_patterns.ts
1446
1446
  var _035_backfill_url_patterns_exports = /* @__PURE__ */ __exportAll({
1447
- down: () => down$71,
1448
- up: () => up$71
1447
+ down: () => down$78,
1448
+ up: () => up$78
1449
1449
  });
1450
1450
  /**
1451
1451
  * Backfill default URL patterns for the built-in posts and pages collections.
1452
1452
  *
1453
1453
  * Existing rows keep custom patterns; only missing defaults are filled.
1454
1454
  */
1455
- async function up$71(db) {
1455
+ async function up$78(db) {
1456
1456
  await sql`
1457
1457
  UPDATE _dineway_collections
1458
1458
  SET url_pattern = '/posts/{slug}'
@@ -1464,7 +1464,7 @@ async function up$71(db) {
1464
1464
  WHERE slug = 'pages' AND url_pattern IS NULL
1465
1465
  `.execute(db);
1466
1466
  }
1467
- async function down$71(db) {
1467
+ async function down$78(db) {
1468
1468
  await sql`
1469
1469
  UPDATE _dineway_collections
1470
1470
  SET url_pattern = NULL
@@ -1480,8 +1480,8 @@ async function down$71(db) {
1480
1480
  //#endregion
1481
1481
  //#region src/database/migrations/036_activity_log.ts
1482
1482
  var _036_activity_log_exports = /* @__PURE__ */ __exportAll({
1483
- down: () => down$70,
1484
- up: () => up$70
1483
+ down: () => down$77,
1484
+ up: () => up$77
1485
1485
  });
1486
1486
  /**
1487
1487
  * Site Context Engine activity foundation.
@@ -1490,7 +1490,7 @@ var _036_activity_log_exports = /* @__PURE__ */ __exportAll({
1490
1490
  * not a request log. Actor IDs intentionally have no foreign key because the
1491
1491
  * actor source can be users, API tokens, or a stable system actor.
1492
1492
  */
1493
- async function up$70(db) {
1493
+ async function up$77(db) {
1494
1494
  await db.schema.createTable("_dineway_activity_log").addColumn("id", "text", (col) => col.primaryKey()).addColumn("actor_type", "text", (col) => col.notNull().check(sql`actor_type in ('user', 'api_token', 'system')`)).addColumn("actor_id", "text", (col) => col.notNull()).addColumn("auth_metadata", "text").addColumn("action_type", "text", (col) => col.notNull()).addColumn("subject_type", "text", (col) => col.notNull()).addColumn("subject_id", "text").addColumn("related_subject_type", "text").addColumn("related_subject_id", "text").addColumn("source_type", "text", (col) => col.check(sql`source_type is null or source_type in ('api_route', 'mcp_tool', 'system', 'plugin', 'unknown')`)).addColumn("source_name", "text").addColumn("result_status", "text", (col) => col.notNull().defaultTo("succeeded").check(sql`result_status in ('succeeded', 'pending', 'failed', 'blocked')`)).addColumn("scope", "text", (col) => col.notNull()).addColumn("summary", "text", (col) => col.notNull()).addColumn("detail", "text").addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
1495
1495
  await db.schema.createIndex("idx_dineway_activity_actor").on("_dineway_activity_log").columns([
1496
1496
  "actor_type",
@@ -1517,15 +1517,15 @@ async function up$70(db) {
1517
1517
  await db.schema.createIndex("idx_dineway_activity_result_status").on("_dineway_activity_log").columns(["result_status", "created_at"]).execute();
1518
1518
  await db.schema.createIndex("idx_dineway_activity_created_at").on("_dineway_activity_log").column("created_at").execute();
1519
1519
  }
1520
- async function down$70(db) {
1520
+ async function down$77(db) {
1521
1521
  await db.schema.dropTable("_dineway_activity_log").execute();
1522
1522
  }
1523
1523
 
1524
1524
  //#endregion
1525
1525
  //#region src/database/migrations/037_context_entries.ts
1526
1526
  var _037_context_entries_exports = /* @__PURE__ */ __exportAll({
1527
- down: () => down$69,
1528
- up: () => up$69
1527
+ down: () => down$76,
1528
+ up: () => up$76
1529
1529
  });
1530
1530
  const CONTEXT_TYPE_SQL = [
1531
1531
  "brand_voice",
@@ -1550,7 +1550,7 @@ const CONTEXT_TYPE_SQL = [
1550
1550
  * marking old entries non-current and linking replacements through
1551
1551
  * `supersedes_id`.
1552
1552
  */
1553
- async function up$69(db) {
1553
+ async function up$76(db) {
1554
1554
  await db.schema.createTable("_dineway_context_entries").addColumn("id", "text", (col) => col.primaryKey()).addColumn("scope", "text", (col) => col.notNull()).addColumn("context_type", "text", (col) => col.notNull().check(sql`context_type in (${sql.raw(CONTEXT_TYPE_SQL)})`)).addColumn("title", "text", (col) => col.notNull()).addColumn("body", "text", (col) => col.notNull()).addColumn("policy_key", "text").addColumn("source_activity_id", "text").addColumn("created_by_actor_type", "text", (col) => col.notNull().check(sql`created_by_actor_type in ('user', 'api_token', 'system')`)).addColumn("created_by_actor_id", "text", (col) => col.notNull()).addColumn("created_auth_metadata", "text").addColumn("supersedes_id", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("is_current", "integer", (col) => col.notNull().defaultTo(1).check(sql`is_current in (0, 1)`)).addColumn("valid_until", "text").addColumn("reviewed_at", "text").addColumn("reviewed_by_actor_type", "text", (col) => col.check(sql`reviewed_by_actor_type is null or reviewed_by_actor_type in ('user', 'api_token', 'system')`)).addColumn("reviewed_by_actor_id", "text").addColumn("review_note", "text").addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("fk_dineway_context_source_activity", ["source_activity_id"], "_dineway_activity_log", ["id"], (cb) => cb.onDelete("set null")).addForeignKeyConstraint("fk_dineway_context_supersedes", ["supersedes_id"], "_dineway_context_entries", ["id"], (cb) => cb.onDelete("set null")).execute();
1555
1555
  await db.schema.createTable("_dineway_context_tags").addColumn("context_entry_id", "text", (col) => col.notNull()).addColumn("tag", "text", (col) => col.notNull()).addPrimaryKeyConstraint("pk_dineway_context_tags", ["context_entry_id", "tag"]).addForeignKeyConstraint("fk_dineway_context_tags_entry", ["context_entry_id"], "_dineway_context_entries", ["id"], (cb) => cb.onDelete("cascade")).execute();
1556
1556
  await db.schema.createIndex("idx_dineway_context_scope_current").on("_dineway_context_entries").columns([
@@ -1575,7 +1575,7 @@ async function up$69(db) {
1575
1575
  await db.schema.createIndex("idx_dineway_context_created_at").on("_dineway_context_entries").column("created_at").execute();
1576
1576
  await db.schema.createIndex("idx_dineway_context_tags_tag").on("_dineway_context_tags").columns(["tag", "context_entry_id"]).execute();
1577
1577
  }
1578
- async function down$69(db) {
1578
+ async function down$76(db) {
1579
1579
  await db.schema.dropTable("_dineway_context_tags").execute();
1580
1580
  await db.schema.dropTable("_dineway_context_entries").execute();
1581
1581
  }
@@ -1583,8 +1583,8 @@ async function down$69(db) {
1583
1583
  //#endregion
1584
1584
  //#region src/database/migrations/038_review_requests.ts
1585
1585
  var _038_review_requests_exports = /* @__PURE__ */ __exportAll({
1586
- down: () => down$68,
1587
- up: () => up$68
1586
+ down: () => down$75,
1587
+ up: () => up$75
1588
1588
  });
1589
1589
  /**
1590
1590
  * Lightweight content review requests for Phase 5a.
@@ -1592,7 +1592,7 @@ var _038_review_requests_exports = /* @__PURE__ */ __exportAll({
1592
1592
  * Review requests bind human approval to immutable content revision/action
1593
1593
  * identifiers so an approval cannot be reused after the draft or action changes.
1594
1594
  */
1595
- async function up$68(db) {
1595
+ async function up$75(db) {
1596
1596
  await db.schema.createTable("_dineway_review_requests").addColumn("id", "text", (col) => col.primaryKey()).addColumn("status", "text", (col) => col.notNull().defaultTo("pending").check(sql`status in ('pending', 'approved', 'rejected')`)).addColumn("collection", "text", (col) => col.notNull()).addColumn("entry_id", "text", (col) => col.notNull()).addColumn("scope", "text", (col) => col.notNull()).addColumn("live_revision_id", "text").addColumn("draft_revision_id", "text").addColumn("reviewed_rev", "text", (col) => col.notNull()).addColumn("action_type", "text", (col) => col.notNull()).addColumn("action_hash", "text", (col) => col.notNull()).addColumn("risk_reason", "text").addColumn("review_payload", "text", (col) => col.notNull()).addColumn("requested_by_actor_type", "text", (col) => col.notNull().check(sql`requested_by_actor_type in ('user', 'api_token', 'system')`)).addColumn("requested_by_actor_id", "text", (col) => col.notNull()).addColumn("requested_auth_metadata", "text").addColumn("resolved_by_actor_type", "text", (col) => col.check(sql`resolved_by_actor_type is null or resolved_by_actor_type in ('user', 'api_token', 'system')`)).addColumn("resolved_by_actor_id", "text").addColumn("resolved_auth_metadata", "text").addColumn("review_note", "text").addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("resolved_at", "text").execute();
1597
1597
  await db.schema.createIndex("idx_dineway_review_status_created").on("_dineway_review_requests").columns(["status", "created_at"]).execute();
1598
1598
  await db.schema.createIndex("idx_dineway_review_target").on("_dineway_review_requests").columns([
@@ -1613,15 +1613,15 @@ async function up$68(db) {
1613
1613
  ]).execute();
1614
1614
  await db.schema.createIndex("idx_dineway_review_resolved_at").on("_dineway_review_requests").column("resolved_at").execute();
1615
1615
  }
1616
- async function down$68(db) {
1616
+ async function down$75(db) {
1617
1617
  await db.schema.dropTable("_dineway_review_requests").execute();
1618
1618
  }
1619
1619
 
1620
1620
  //#endregion
1621
1621
  //#region src/database/migrations/039_entity_aliases.ts
1622
1622
  var _039_entity_aliases_exports = /* @__PURE__ */ __exportAll({
1623
- down: () => down$67,
1624
- up: () => up$67
1623
+ down: () => down$74,
1624
+ up: () => up$74
1625
1625
  });
1626
1626
  const ENTITY_ALIAS_TYPES = [
1627
1627
  "content",
@@ -1636,7 +1636,7 @@ const ENTITY_ALIAS_TYPES = [
1636
1636
  * This replaces CRMy's PostgreSQL-specific alias arrays with a normalized
1637
1637
  * mapping table that works across SQLite/libSQL and PostgreSQL.
1638
1638
  */
1639
- async function up$67(db) {
1639
+ async function up$74(db) {
1640
1640
  const entityTypesSql = sql.join(ENTITY_ALIAS_TYPES.map((value) => sql.lit(value)), sql`, `);
1641
1641
  await db.schema.createTable("_dineway_entity_aliases").addColumn("id", "text", (col) => col.primaryKey()).addColumn("entity_type", "text", (col) => col.notNull().check(sql`entity_type in (${entityTypesSql})`)).addColumn("collection_slug", "text").addColumn("entity_id", "text", (col) => col.notNull()).addColumn("alias", "text", (col) => col.notNull()).addColumn("normalized_alias", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
1642
1642
  await db.schema.createIndex("idx_dineway_entity_alias_lookup").on("_dineway_entity_aliases").columns(["entity_type", "normalized_alias"]).execute();
@@ -1653,17 +1653,17 @@ async function up$67(db) {
1653
1653
  "normalized_alias"
1654
1654
  ]).unique().execute();
1655
1655
  }
1656
- async function down$67(db) {
1656
+ async function down$74(db) {
1657
1657
  await db.schema.dropTable("_dineway_entity_aliases").execute();
1658
1658
  }
1659
1659
 
1660
1660
  //#endregion
1661
1661
  //#region src/database/migrations/040_handoff_snapshots.ts
1662
1662
  var _040_handoff_snapshots_exports = /* @__PURE__ */ __exportAll({
1663
- down: () => down$66,
1664
- up: () => up$66
1663
+ down: () => down$73,
1664
+ up: () => up$73
1665
1665
  });
1666
- const ACTOR_TYPES$3 = [
1666
+ const ACTOR_TYPES$4 = [
1667
1667
  "user",
1668
1668
  "api_token",
1669
1669
  "system"
@@ -1674,8 +1674,8 @@ const HANDOFF_KINDS = [
1674
1674
  "assignment"
1675
1675
  ];
1676
1676
  const REFERENCE_TYPES = ["review_request", "assignment"];
1677
- async function up$66(db) {
1678
- const actorTypesSql = sql.join(ACTOR_TYPES$3.map((value) => sql.lit(value)), sql`, `);
1677
+ async function up$73(db) {
1678
+ const actorTypesSql = sql.join(ACTOR_TYPES$4.map((value) => sql.lit(value)), sql`, `);
1679
1679
  const handoffKindsSql = sql.join(HANDOFF_KINDS.map((value) => sql.lit(value)), sql`, `);
1680
1680
  const referenceTypesSql = sql.join(REFERENCE_TYPES.map((value) => sql.lit(value)), sql`, `);
1681
1681
  await db.schema.createTable("_dineway_handoff_snapshots").addColumn("id", "text", (col) => col.primaryKey()).addColumn("scope", "text", (col) => col.notNull()).addColumn("actor_type", "text", (col) => col.notNull().check(sql`actor_type in (${actorTypesSql})`)).addColumn("actor_id", "text", (col) => col.notNull()).addColumn("auth_metadata", "text").addColumn("objective", "text", (col) => col.notNull()).addColumn("reasoning", "text", (col) => col.notNull()).addColumn("key_findings", "text", (col) => col.notNull().defaultTo(sql`'[]'`)).addColumn("touched_objects", "text", (col) => col.notNull().defaultTo(sql`'[]'`)).addColumn("pending_actions", "text", (col) => col.notNull().defaultTo(sql`'[]'`)).addColumn("tool_evidence", "text", (col) => col.notNull().defaultTo(sql`'[]'`)).addColumn("confidence", "real").addColumn("handoff_kind", "text", (col) => col.notNull().check(sql`handoff_kind in (${handoffKindsSql})`).defaultTo(sql`'pause'`)).addColumn("reference_type", "text", (col) => col.check(sql`reference_type is null or reference_type in (${referenceTypesSql})`)).addColumn("reference_id", "text").addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("resumed_at", "text").execute();
@@ -1688,17 +1688,17 @@ async function up$66(db) {
1688
1688
  await db.schema.createIndex("idx_dineway_handoff_kind_created").on("_dineway_handoff_snapshots").columns(["handoff_kind", "created_at"]).execute();
1689
1689
  await db.schema.createIndex("idx_dineway_handoff_reference").on("_dineway_handoff_snapshots").columns(["reference_type", "reference_id"]).execute();
1690
1690
  }
1691
- async function down$66(db) {
1691
+ async function down$73(db) {
1692
1692
  await db.schema.dropTable("_dineway_handoff_snapshots").execute();
1693
1693
  }
1694
1694
 
1695
1695
  //#endregion
1696
1696
  //#region src/database/migrations/041_assignments.ts
1697
1697
  var _041_assignments_exports = /* @__PURE__ */ __exportAll({
1698
- down: () => down$65,
1699
- up: () => up$65
1698
+ down: () => down$72,
1699
+ up: () => up$72
1700
1700
  });
1701
- const ACTOR_TYPES$2 = [
1701
+ const ACTOR_TYPES$3 = [
1702
1702
  "user",
1703
1703
  "api_token",
1704
1704
  "system"
@@ -1718,8 +1718,8 @@ const ASSIGNMENT_PRIORITIES = [
1718
1718
  "high",
1719
1719
  "urgent"
1720
1720
  ];
1721
- async function up$65(db) {
1722
- const actorTypesSql = sql.join(ACTOR_TYPES$2.map((value) => sql.lit(value)), sql`, `);
1721
+ async function up$72(db) {
1722
+ const actorTypesSql = sql.join(ACTOR_TYPES$3.map((value) => sql.lit(value)), sql`, `);
1723
1723
  const statusesSql = sql.join(ASSIGNMENT_STATUSES.map((value) => sql.lit(value)), sql`, `);
1724
1724
  const prioritiesSql = sql.join(ASSIGNMENT_PRIORITIES.map((value) => sql.lit(value)), sql`, `);
1725
1725
  await db.schema.createTable("_dineway_assignments").addColumn("id", "text", (col) => col.primaryKey()).addColumn("scope", "text", (col) => col.notNull()).addColumn("assignment_type", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().defaultTo(sql`'pending'`).check(sql`status in (${statusesSql})`)).addColumn("priority", "text", (col) => col.notNull().defaultTo(sql`'normal'`).check(sql`priority in (${prioritiesSql})`)).addColumn("title", "text", (col) => col.notNull()).addColumn("summary", "text").addColumn("details", "text").addColumn("assigned_by_actor_type", "text", (col) => col.notNull().check(sql`assigned_by_actor_type in (${actorTypesSql})`)).addColumn("assigned_by_actor_id", "text", (col) => col.notNull()).addColumn("assigned_to_actor_type", "text", (col) => col.check(sql`assigned_to_actor_type is null or assigned_to_actor_type in (${actorTypesSql})`)).addColumn("assigned_to_actor_id", "text").addColumn("metadata", "text", (col) => col.notNull().defaultTo(sql`'{}'`)).addColumn("related_handoff_snapshot_id", "text", (col) => col.references("_dineway_handoff_snapshots.id").onDelete("set null")).addColumn("due_at", "text").addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("accepted_at", "text").addColumn("started_at", "text").addColumn("blocked_at", "text").addColumn("completed_at", "text").addColumn("declined_at", "text").addColumn("cancelled_at", "text").execute();
@@ -1750,17 +1750,17 @@ async function up$65(db) {
1750
1750
  await db.schema.createIndex("idx_dineway_assignment_due_at").on("_dineway_assignments").column("due_at").execute();
1751
1751
  await db.schema.createIndex("idx_dineway_assignment_handoff").on("_dineway_assignments").column("related_handoff_snapshot_id").execute();
1752
1752
  }
1753
- async function down$65(db) {
1753
+ async function down$72(db) {
1754
1754
  await db.schema.dropTable("_dineway_assignments").execute();
1755
1755
  }
1756
1756
 
1757
1757
  //#endregion
1758
1758
  //#region src/database/migrations/042_hitl_requests.ts
1759
1759
  var _042_hitl_requests_exports = /* @__PURE__ */ __exportAll({
1760
- down: () => down$64,
1761
- up: () => up$64
1760
+ down: () => down$71,
1761
+ up: () => up$71
1762
1762
  });
1763
- const ACTOR_TYPES$1 = [
1763
+ const ACTOR_TYPES$2 = [
1764
1764
  "user",
1765
1765
  "api_token",
1766
1766
  "system"
@@ -1776,8 +1776,8 @@ const HITL_PRIORITIES = [
1776
1776
  "high",
1777
1777
  "urgent"
1778
1778
  ];
1779
- async function up$64(db) {
1780
- const actorTypesSql = sql.join(ACTOR_TYPES$1.map((value) => sql.lit(value)), sql`, `);
1779
+ async function up$71(db) {
1780
+ const actorTypesSql = sql.join(ACTOR_TYPES$2.map((value) => sql.lit(value)), sql`, `);
1781
1781
  const statusesSql = sql.join(HITL_STATUSES.map((value) => sql.lit(value)), sql`, `);
1782
1782
  const prioritiesSql = sql.join(HITL_PRIORITIES.map((value) => sql.lit(value)), sql`, `);
1783
1783
  await db.schema.createTable("_dineway_hitl_requests").addColumn("id", "text", (col) => col.primaryKey()).addColumn("scope", "text", (col) => col.notNull()).addColumn("action_type", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().defaultTo(sql`'pending'`).check(sql`status in (${statusesSql})`)).addColumn("priority", "text", (col) => col.notNull().defaultTo(sql`'normal'`).check(sql`priority in (${prioritiesSql})`)).addColumn("title", "text", (col) => col.notNull()).addColumn("summary", "text").addColumn("risk_reason", "text", (col) => col.notNull()).addColumn("review_payload", "text", (col) => col.notNull()).addColumn("target_ref_type", "text", (col) => col.notNull()).addColumn("target_ref_id", "text", (col) => col.notNull()).addColumn("requested_by_actor_type", "text", (col) => col.notNull().check(sql`requested_by_actor_type in (${actorTypesSql})`)).addColumn("requested_by_actor_id", "text", (col) => col.notNull()).addColumn("requested_auth_metadata", "text").addColumn("resolved_by_actor_type", "text", (col) => col.check(sql`resolved_by_actor_type is null or resolved_by_actor_type in (${actorTypesSql})`)).addColumn("resolved_by_actor_id", "text").addColumn("resolved_auth_metadata", "text").addColumn("review_note", "text").addColumn("metadata", "text", (col) => col.notNull().defaultTo(sql`'{}'`)).addColumn("related_assignment_id", "text", (col) => col.references("_dineway_assignments.id").onDelete("set null")).addColumn("related_handoff_snapshot_id", "text", (col) => col.references("_dineway_handoff_snapshots.id").onDelete("set null")).addColumn("sla_due_at", "text").addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("resolved_at", "text").execute();
@@ -1811,7 +1811,7 @@ async function up$64(db) {
1811
1811
  await db.schema.createIndex("idx_dineway_hitl_sla_due_at").on("_dineway_hitl_requests").column("sla_due_at").execute();
1812
1812
  await db.schema.createIndex("idx_dineway_assignment_hitl").on("_dineway_assignments").column("related_hitl_request_id").execute();
1813
1813
  }
1814
- async function down$64(db) {
1814
+ async function down$71(db) {
1815
1815
  await db.schema.dropIndex("idx_dineway_assignment_hitl").execute();
1816
1816
  await db.schema.alterTable("_dineway_assignments").dropColumn("related_hitl_request_id").execute();
1817
1817
  await db.schema.dropTable("_dineway_hitl_requests").execute();
@@ -1820,8 +1820,8 @@ async function down$64(db) {
1820
1820
  //#endregion
1821
1821
  //#region src/database/migrations/043_bounded_404_log.ts
1822
1822
  var _043_bounded_404_log_exports = /* @__PURE__ */ __exportAll({
1823
- down: () => down$63,
1824
- up: () => up$63
1823
+ down: () => down$70,
1824
+ up: () => up$70
1825
1825
  });
1826
1826
  /**
1827
1827
  * Migration: Bounded 404 logging
@@ -1830,7 +1830,7 @@ var _043_bounded_404_log_exports = /* @__PURE__ */ __exportAll({
1830
1830
  * Previously every 404 inserted a new row, so a requester could grow the
1831
1831
  * table without bound by hitting unique URLs.
1832
1832
  */
1833
- async function up$63(db) {
1833
+ async function up$70(db) {
1834
1834
  await db.schema.alterTable("_dineway_404_log").addColumn("hits", "integer", (col) => col.notNull().defaultTo(1)).execute();
1835
1835
  await db.schema.alterTable("_dineway_404_log").addColumn("last_seen_at", "text").execute();
1836
1836
  await sql`
@@ -1876,7 +1876,7 @@ async function up$63(db) {
1876
1876
  await db.schema.dropIndex("idx_404_log_path").execute();
1877
1877
  await db.schema.createIndex("idx_404_log_last_seen").on("_dineway_404_log").column("last_seen_at").execute();
1878
1878
  }
1879
- async function down$63(db) {
1879
+ async function down$70(db) {
1880
1880
  await db.schema.dropIndex("idx_404_log_last_seen").execute();
1881
1881
  await db.schema.dropIndex("idx_404_log_path_unique").execute();
1882
1882
  await db.schema.createIndex("idx_404_log_path").on("_dineway_404_log").column("path").execute();
@@ -1887,21 +1887,21 @@ async function down$63(db) {
1887
1887
  //#endregion
1888
1888
  //#region src/database/migrations/044_credential_algorithm.ts
1889
1889
  var _044_credential_algorithm_exports = /* @__PURE__ */ __exportAll({
1890
- down: () => down$62,
1891
- up: () => up$62
1890
+ down: () => down$69,
1891
+ up: () => up$69
1892
1892
  });
1893
- async function up$62(db) {
1893
+ async function up$69(db) {
1894
1894
  if (!await columnExists(db, "credentials", "algorithm")) await db.schema.alterTable("credentials").addColumn("algorithm", "integer", (col) => col.notNull().defaultTo(-7)).execute();
1895
1895
  }
1896
- async function down$62(db) {
1896
+ async function down$69(db) {
1897
1897
  if (await columnExists(db, "credentials", "algorithm")) await db.schema.alterTable("credentials").dropColumn("algorithm").execute();
1898
1898
  }
1899
1899
 
1900
1900
  //#endregion
1901
1901
  //#region src/database/migrations/045_i18n_menus_and_taxonomies.ts
1902
1902
  var _045_i18n_menus_and_taxonomies_exports = /* @__PURE__ */ __exportAll({
1903
- down: () => down$61,
1904
- up: () => up$61
1903
+ down: () => down$68,
1904
+ up: () => up$68
1905
1905
  });
1906
1906
  /**
1907
1907
  * i18n for menus + taxonomies. Adds `locale` + `translation_group` to system
@@ -1912,7 +1912,7 @@ var _045_i18n_menus_and_taxonomies_exports = /* @__PURE__ */ __exportAll({
1912
1912
  function getDefaultLocale$1() {
1913
1913
  return getI18nConfig()?.defaultLocale ?? "en";
1914
1914
  }
1915
- async function up$61(db) {
1915
+ async function up$68(db) {
1916
1916
  const defaultLocale = getDefaultLocale$1();
1917
1917
  if (isSqlite(db)) {
1918
1918
  await sql.raw(`PRAGMA foreign_keys = OFF`).execute(db);
@@ -2103,7 +2103,7 @@ async function assertSingleLocale$1(db, defaultLocale) {
2103
2103
  if (count > 0) throw new Error(`Cannot revert migration 045_i18n_menus_and_taxonomies: ${count} row(s) in "${table}" use a non-default locale (defaultLocale="${defaultLocale}"). Reverting would drop them silently. Export translations first (or delete them) and re-run the rollback. See packages/core/src/database/migrations/045_i18n_menus_and_taxonomies.ts.`);
2104
2104
  }
2105
2105
  }
2106
- async function down$61(db) {
2106
+ async function down$68(db) {
2107
2107
  const defaultLocale = getDefaultLocale$1();
2108
2108
  await assertSingleLocale$1(db, defaultLocale);
2109
2109
  const widenedTables = [
@@ -2197,21 +2197,21 @@ async function rebuildTaxonomyDefsDown(db) {
2197
2197
  //#endregion
2198
2198
  //#region src/database/migrations/046_astro_sessions.ts
2199
2199
  var _046_astro_sessions_exports = /* @__PURE__ */ __exportAll({
2200
- down: () => down$60,
2201
- up: () => up$60
2200
+ down: () => down$67,
2201
+ up: () => up$67
2202
2202
  });
2203
- async function up$60(db) {
2203
+ async function up$67(db) {
2204
2204
  await db.schema.createTable("_dineway_sessions").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("value", "text", (col) => col.notNull()).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
2205
2205
  }
2206
- async function down$60(db) {
2206
+ async function down$67(db) {
2207
2207
  await db.schema.dropTable("_dineway_sessions").ifExists().execute();
2208
2208
  }
2209
2209
 
2210
2210
  //#endregion
2211
2211
  //#region src/database/migrations/047_content_locale_list_index.ts
2212
2212
  var _047_content_locale_list_index_exports = /* @__PURE__ */ __exportAll({
2213
- down: () => down$59,
2214
- up: () => up$59
2213
+ down: () => down$66,
2214
+ up: () => up$66
2215
2215
  });
2216
2216
  /**
2217
2217
  * Add locale-aware composite indexes for content list queries.
@@ -2221,7 +2221,7 @@ var _047_content_locale_list_index_exports = /* @__PURE__ */ __exportAll({
2221
2221
  * path but omit locale, so locale-filtered lists cannot be served by one index
2222
2222
  * on large tables.
2223
2223
  */
2224
- async function up$59(db) {
2224
+ async function up$66(db) {
2225
2225
  const tableNames = await listTablesLike(db, "ec_%");
2226
2226
  for (const tableName of tableNames) {
2227
2227
  await sql`
@@ -2234,7 +2234,7 @@ async function up$59(db) {
2234
2234
  `.execute(db);
2235
2235
  }
2236
2236
  }
2237
- async function down$59(db) {
2237
+ async function down$66(db) {
2238
2238
  const tableNames = await listTablesLike(db, "ec_%");
2239
2239
  for (const tableName of tableNames) {
2240
2240
  await sql`DROP INDEX IF EXISTS ${sql.ref(contentLocaleUpdatedIndexName(tableName))}`.execute(db);
@@ -2245,8 +2245,8 @@ async function down$59(db) {
2245
2245
  //#endregion
2246
2246
  //#region src/database/migrations/048_byline_i18n.ts
2247
2247
  var _048_byline_i18n_exports = /* @__PURE__ */ __exportAll({
2248
- down: () => down$58,
2249
- up: () => up$58
2248
+ down: () => down$65,
2249
+ up: () => up$65
2250
2250
  });
2251
2251
  /**
2252
2252
  * Adds row-per-locale bylines.
@@ -2259,7 +2259,7 @@ var _048_byline_i18n_exports = /* @__PURE__ */ __exportAll({
2259
2259
  function getDefaultLocale() {
2260
2260
  return getI18nConfig()?.defaultLocale ?? "en";
2261
2261
  }
2262
- async function up$58(db) {
2262
+ async function up$65(db) {
2263
2263
  const defaultLocale = getDefaultLocale();
2264
2264
  if (isSqlite(db)) {
2265
2265
  await rebuildContentBylines(db);
@@ -2418,7 +2418,7 @@ async function assertSingleLocale(db, defaultLocale) {
2418
2418
  const count = Number(result.rows[0]?.count ?? 0);
2419
2419
  if (count > 0) throw new Error(`Cannot revert migration 048_byline_i18n: ${count} row(s) in "_dineway_bylines" use a non-default locale (defaultLocale="${defaultLocale}").`);
2420
2420
  }
2421
- async function down$58(db) {
2421
+ async function down$65(db) {
2422
2422
  const defaultLocale = getDefaultLocale();
2423
2423
  await assertSingleLocale(db, defaultLocale);
2424
2424
  await assertContentBylinesResolve(db, defaultLocale);
@@ -2540,10 +2540,10 @@ async function restoreContentBylinesFk(db) {
2540
2540
  //#endregion
2541
2541
  //#region src/database/migrations/049_byline_fields.ts
2542
2542
  var _049_byline_fields_exports = /* @__PURE__ */ __exportAll({
2543
- down: () => down$57,
2544
- up: () => up$57
2543
+ down: () => down$64,
2544
+ up: () => up$64
2545
2545
  });
2546
- async function up$57(db) {
2546
+ async function up$64(db) {
2547
2547
  await db.schema.createTable("_dineway_byline_fields").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("type", "text", (col) => col.notNull()).addColumn("required", "integer", (col) => col.notNull().defaultTo(0)).addColumn("translatable", "integer", (col) => col.notNull().defaultTo(1)).addColumn("validation", "text").addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
2548
2548
  await db.schema.createIndex("idx__dineway_byline_fields_sort_order").ifNotExists().on("_dineway_byline_fields").column("sort_order").execute();
2549
2549
  await db.schema.createTable("_dineway_byline_field_values").ifNotExists().addColumn("byline_id", "text", (col) => col.notNull().references("_dineway_bylines.id").onDelete("cascade")).addColumn("field_id", "text", (col) => col.notNull().references("_dineway_byline_fields.id").onDelete("cascade")).addColumn("value", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addPrimaryKeyConstraint("_dineway_byline_field_values_pk", ["byline_id", "field_id"]).execute();
@@ -2557,7 +2557,7 @@ async function up$57(db) {
2557
2557
  ON CONFLICT (name) DO NOTHING
2558
2558
  `.execute(db);
2559
2559
  }
2560
- async function down$57(db) {
2560
+ async function down$64(db) {
2561
2561
  await db.schema.dropTable("_dineway_byline_field_group_values").ifExists().execute();
2562
2562
  await db.schema.dropTable("_dineway_byline_field_values").ifExists().execute();
2563
2563
  await db.schema.dropTable("_dineway_byline_fields").ifExists().execute();
@@ -2567,8 +2567,8 @@ async function down$57(db) {
2567
2567
  //#endregion
2568
2568
  //#region src/database/migrations/050_content_references.ts
2569
2569
  var _050_content_references_exports = /* @__PURE__ */ __exportAll({
2570
- down: () => down$56,
2571
- up: () => up$56
2570
+ down: () => down$63,
2571
+ up: () => up$63
2572
2572
  });
2573
2573
  /**
2574
2574
  * Content references.
@@ -2577,7 +2577,7 @@ var _050_content_references_exports = /* @__PURE__ */ __exportAll({
2577
2577
  * with one localized row per locale. `_dineway_content_references` stores
2578
2578
  * parent -> child edges keyed by translation groups so edges are locale-agnostic.
2579
2579
  */
2580
- async function up$56(db) {
2580
+ async function up$63(db) {
2581
2581
  const defaultLocale = getI18nConfig()?.defaultLocale ?? "en";
2582
2582
  await db.schema.createTable("_dineway_relations").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull()).addColumn("parent_collection", "text", (col) => col.notNull()).addColumn("child_collection", "text", (col) => col.notNull()).addColumn("parent_label", "text", (col) => col.notNull()).addColumn("child_label", "text", (col) => col.notNull()).addColumn("locale", "text", (col) => col.notNull().defaultTo(defaultLocale)).addColumn("translation_group", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addUniqueConstraint("_dineway_relations_name_locale_unique", ["name", "locale"]).execute();
2583
2583
  await db.schema.createIndex("idx__dineway_relations_locale").ifNotExists().on("_dineway_relations").column("locale").execute();
@@ -2598,7 +2598,7 @@ async function up$56(db) {
2598
2598
  await db.schema.createIndex("idx__dineway_content_references_child").ifNotExists().on("_dineway_content_references").columns(["child_group", "relation_group"]).execute();
2599
2599
  await db.schema.createIndex("idx__dineway_content_references_relation").ifNotExists().on("_dineway_content_references").column("relation_group").execute();
2600
2600
  }
2601
- async function down$56(db) {
2601
+ async function down$63(db) {
2602
2602
  await db.schema.dropTable("_dineway_content_references").ifExists().execute();
2603
2603
  await db.schema.dropTable("_dineway_relations").ifExists().execute();
2604
2604
  }
@@ -2606,8 +2606,8 @@ async function down$56(db) {
2606
2606
  //#endregion
2607
2607
  //#region src/database/migrations/051_dineway_web_plugin.ts
2608
2608
  var _051_dineway_web_plugin_exports = /* @__PURE__ */ __exportAll({
2609
- down: () => down$55,
2610
- up: () => up$55
2609
+ down: () => down$62,
2610
+ up: () => up$62
2611
2611
  });
2612
2612
  const SESSION_STATUSES = [
2613
2613
  "active",
@@ -2642,7 +2642,7 @@ const HANDOFF_AUDIT_EVENTS = [
2642
2642
  function enumValues(values) {
2643
2643
  return sql.join(values.map((value) => sql.lit(value)), sql`, `);
2644
2644
  }
2645
- async function up$55(db) {
2645
+ async function up$62(db) {
2646
2646
  const sessionStatuses = enumValues(SESSION_STATUSES);
2647
2647
  const onboardingStatuses = enumValues(ONBOARDING_STATUSES);
2648
2648
  const checkoutStatuses = enumValues(CHECKOUT_STATUSES);
@@ -2685,7 +2685,7 @@ async function up$55(db) {
2685
2685
  await db.schema.createIndex("idx_dineway_web_handoff_audit_handoff").ifNotExists().on("_dineway_dineway_web_handoff_audit").column("handoff_id").execute();
2686
2686
  await db.schema.createIndex("idx_dineway_web_handoff_audit_event").ifNotExists().on("_dineway_dineway_web_handoff_audit").column("event").execute();
2687
2687
  }
2688
- async function down$55(db) {
2688
+ async function down$62(db) {
2689
2689
  await db.schema.dropTable("_dineway_dineway_web_handoff_audit").ifExists().execute();
2690
2690
  await db.schema.dropTable("_dineway_dineway_web_handoffs").ifExists().execute();
2691
2691
  await db.schema.dropTable("_dineway_dineway_web_sites_projections").ifExists().execute();
@@ -2700,19 +2700,19 @@ async function down$55(db) {
2700
2700
  //#endregion
2701
2701
  //#region src/database/migrations/052_taxonomies_name_locale_index.ts
2702
2702
  var _052_taxonomies_name_locale_index_exports = /* @__PURE__ */ __exportAll({
2703
- down: () => down$54,
2704
- up: () => up$54
2703
+ down: () => down$61,
2704
+ up: () => up$61
2705
2705
  });
2706
2706
  /**
2707
2707
  * Add a composite taxonomy lookup index for queries that filter by name and locale.
2708
2708
  * The composite's leftmost prefix covers name-only lookups, so it replaces the
2709
2709
  * older single-column name index while preserving the locale-only index.
2710
2710
  */
2711
- async function up$54(db) {
2711
+ async function up$61(db) {
2712
2712
  await db.schema.createIndex("idx_taxonomies_name_locale").ifNotExists().on("taxonomies").columns(["name", "locale"]).execute();
2713
2713
  await db.schema.dropIndex("idx_taxonomies_name").ifExists().execute();
2714
2714
  }
2715
- async function down$54(db) {
2715
+ async function down$61(db) {
2716
2716
  await db.schema.createIndex("idx_taxonomies_name").ifNotExists().on("taxonomies").column("name").execute();
2717
2717
  await db.schema.dropIndex("idx_taxonomies_name_locale").ifExists().execute();
2718
2718
  }
@@ -2720,8 +2720,8 @@ async function down$54(db) {
2720
2720
  //#endregion
2721
2721
  //#region src/database/migrations/053_restore_content_taxonomies_term_index.ts
2722
2722
  var _053_restore_content_taxonomies_term_index_exports = /* @__PURE__ */ __exportAll({
2723
- down: () => down$53,
2724
- up: () => up$53
2723
+ down: () => down$60,
2724
+ up: () => up$60
2725
2725
  });
2726
2726
  /**
2727
2727
  * Restore the reverse lookup index on content taxonomy assignments.
@@ -2730,16 +2730,16 @@ var _053_restore_content_taxonomies_term_index_exports = /* @__PURE__ */ __expor
2730
2730
  * covers upgraded SQLite databases that already recorded the table rebuild but
2731
2731
  * ended up missing only this index.
2732
2732
  */
2733
- async function up$53(db) {
2733
+ async function up$60(db) {
2734
2734
  await db.schema.createIndex("idx_content_taxonomies_term").ifNotExists().on("content_taxonomies").column("taxonomy_id").execute();
2735
2735
  }
2736
- async function down$53(db) {}
2736
+ async function down$60(db) {}
2737
2737
 
2738
2738
  //#endregion
2739
2739
  //#region src/database/migrations/054_restore_taxonomy_parent_index.ts
2740
2740
  var _054_restore_taxonomy_parent_index_exports = /* @__PURE__ */ __exportAll({
2741
- down: () => down$52,
2742
- up: () => up$52
2741
+ down: () => down$59,
2742
+ up: () => up$59
2743
2743
  });
2744
2744
  /**
2745
2745
  * Restore the parent lookup index on hierarchical taxonomy terms.
@@ -2748,16 +2748,16 @@ var _054_restore_taxonomy_parent_index_exports = /* @__PURE__ */ __exportAll({
2748
2748
  * could drop it on upgraded databases. Fresh installs recreate it in the
2749
2749
  * rebuild path; this forward repair covers already-migrated databases.
2750
2750
  */
2751
- async function up$52(db) {
2751
+ async function up$59(db) {
2752
2752
  await db.schema.createIndex("idx_taxonomies_parent").ifNotExists().on("taxonomies").column("parent_id").execute();
2753
2753
  }
2754
- async function down$52(db) {}
2754
+ async function down$59(db) {}
2755
2755
 
2756
2756
  //#endregion
2757
2757
  //#region src/database/migrations/055_taxonomy_parent_group.ts
2758
2758
  var _055_taxonomy_parent_group_exports = /* @__PURE__ */ __exportAll({
2759
- down: () => down$51,
2760
- up: () => up$51
2759
+ down: () => down$58,
2760
+ up: () => up$58
2761
2761
  });
2762
2762
  /**
2763
2763
  * Store the parent's `translation_group` in `taxonomies.parent_id` instead of a
@@ -2772,7 +2772,7 @@ var _055_taxonomy_parent_group_exports = /* @__PURE__ */ __exportAll({
2772
2772
  * anchor row's id. Only rewrite when that anchor row exists; otherwise keep the
2773
2773
  * existing row id rather than writing a dangling FK value.
2774
2774
  */
2775
- async function up$51(db) {
2775
+ async function up$58(db) {
2776
2776
  await sql`
2777
2777
  UPDATE taxonomies
2778
2778
  SET parent_id = (
@@ -2799,7 +2799,7 @@ async function up$51(db) {
2799
2799
  * Rows with no same-locale parent are left as-is so rollback does not silently
2800
2800
  * detach a subtree.
2801
2801
  */
2802
- async function down$51(db) {
2802
+ async function down$58(db) {
2803
2803
  await sql`
2804
2804
  UPDATE taxonomies
2805
2805
  SET parent_id = COALESCE(
@@ -2818,8 +2818,8 @@ async function down$51(db) {
2818
2818
  //#endregion
2819
2819
  //#region src/database/migrations/056_media_usage_index.ts
2820
2820
  var _056_media_usage_index_exports = /* @__PURE__ */ __exportAll({
2821
- down: () => down$50,
2822
- up: () => up$50
2821
+ down: () => down$57,
2822
+ up: () => up$57
2823
2823
  });
2824
2824
  /**
2825
2825
  * Internal media usage projection tables.
@@ -2828,7 +2828,7 @@ var _056_media_usage_index_exports = /* @__PURE__ */ __exportAll({
2828
2828
  * imports, and no content-table scans. Production rows are introduced by later
2829
2829
  * phases once the central snapshot/indexer path is reviewed.
2830
2830
  */
2831
- async function up$50(db) {
2831
+ async function up$57(db) {
2832
2832
  await db.schema.createTable("_dineway_media_usage_sources").ifNotExists().addColumn("source_key", "text", (col) => col.primaryKey()).addColumn("source_type", "text", (col) => col.notNull()).addColumn("collection_slug", "text").addColumn("content_id", "text").addColumn("source_variant", "text", (col) => col.notNull()).addColumn("locale", "text").addColumn("translation_group", "text").addColumn("content_slug", "text").addColumn("content_title", "text").addColumn("content_status", "text").addColumn("content_scheduled_at", "text").addColumn("content_deleted_at", "text").addColumn("revision_id", "text").addColumn("current_generation", "text", (col) => col.notNull()).addColumn("schema_version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("indexed_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
2833
2833
  await db.schema.createIndex("idx__dineway_media_usage_sources_content").ifNotExists().on("_dineway_media_usage_sources").columns([
2834
2834
  "source_type",
@@ -2850,7 +2850,7 @@ async function up$50(db) {
2850
2850
  await db.schema.createIndex("idx__dineway_media_usage_provider_asset").ifNotExists().on("_dineway_media_usage").columns(["provider", "provider_asset_id"]).execute();
2851
2851
  await db.schema.createIndex("idx__dineway_media_usage_source_generation").ifNotExists().on("_dineway_media_usage").columns(["source_key", "generation"]).execute();
2852
2852
  }
2853
- async function down$50(db) {
2853
+ async function down$57(db) {
2854
2854
  await db.schema.dropTable("_dineway_media_usage").ifExists().execute();
2855
2855
  await db.schema.dropTable("_dineway_media_usage_sources").ifExists().execute();
2856
2856
  }
@@ -2858,8 +2858,8 @@ async function down$50(db) {
2858
2858
  //#endregion
2859
2859
  //#region src/database/migrations/057_media_usage_index_status.ts
2860
2860
  var _057_media_usage_index_status_exports = /* @__PURE__ */ __exportAll({
2861
- down: () => down$49,
2862
- up: () => up$49
2861
+ down: () => down$56,
2862
+ up: () => up$56
2863
2863
  });
2864
2864
  const SOURCE_TABLE = "_dineway_media_usage_sources";
2865
2865
  const DUPLICATE_COLUMN_RE = /(?:duplicate column|column .* already exists|already exists.*column)/i;
@@ -2869,7 +2869,7 @@ const DUPLICATE_COLUMN_RE = /(?:duplicate column|column .* already exists|alread
2869
2869
  * DDL-only by design: adds source metadata and adapter-scope status tracking
2870
2870
  * without scanning content tables or importing runtime code.
2871
2871
  */
2872
- async function up$49(db) {
2872
+ async function up$56(db) {
2873
2873
  await addSourceMetadataColumns(db);
2874
2874
  await db.schema.createTable("_dineway_media_usage_index_status").ifNotExists().addColumn("adapter_id", "text", (col) => col.notNull()).addColumn("scope_type", "text", (col) => col.notNull()).addColumn("scope_key", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull()).addColumn("schema_version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("started_at", "text").addColumn("completed_at", "text").addColumn("cursor", "text").addColumn("indexed_source_count", "integer", (col) => col.notNull().defaultTo(0)).addColumn("failed_source_count", "integer", (col) => col.notNull().defaultTo(0)).addColumn("last_error_code", "text").addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addPrimaryKeyConstraint("_dineway_media_usage_index_status_pk", [
2875
2875
  "adapter_id",
@@ -2884,7 +2884,7 @@ async function up$49(db) {
2884
2884
  await db.schema.createIndex("idx__dineway_media_usage_sources_fingerprint").ifNotExists().on("_dineway_media_usage_sources").column("source_fingerprint").execute();
2885
2885
  await db.schema.createIndex("idx__dineway_media_usage_index_status_status").ifNotExists().on("_dineway_media_usage_index_status").columns(["adapter_id", "status"]).execute();
2886
2886
  }
2887
- async function down$49(db) {
2887
+ async function down$56(db) {
2888
2888
  await db.schema.dropIndex("idx__dineway_media_usage_index_status_status").ifExists().execute();
2889
2889
  await db.schema.dropIndex("idx__dineway_media_usage_sources_fingerprint").ifExists().execute();
2890
2890
  await db.schema.dropIndex("idx__dineway_media_usage_sources_completeness").ifExists().execute();
@@ -2940,10 +2940,10 @@ async function dropSourceMetadataColumns(db) {
2940
2940
  //#endregion
2941
2941
  //#region src/database/migrations/058_comment_reactions.ts
2942
2942
  var _058_comment_reactions_exports = /* @__PURE__ */ __exportAll({
2943
- down: () => down$48,
2944
- up: () => up$48
2943
+ down: () => down$55,
2944
+ up: () => up$55
2945
2945
  });
2946
- async function up$48(db) {
2946
+ async function up$55(db) {
2947
2947
  await db.schema.createTable("_dineway_comment_reactions").addColumn("id", "text", (col) => col.primaryKey()).addColumn("comment_id", "text", (col) => col.notNull().references("_dineway_comments.id").onDelete("cascade")).addColumn("reaction", "text", (col) => col.notNull().defaultTo("like")).addColumn("voter_hash", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp$1(db))).execute();
2948
2948
  await db.schema.createIndex("idx_dineway_comment_reactions_unique").on("_dineway_comment_reactions").columns([
2949
2949
  "comment_id",
@@ -2953,17 +2953,17 @@ async function up$48(db) {
2953
2953
  await db.schema.createIndex("idx_dineway_comment_reactions_comment_id").on("_dineway_comment_reactions").column("comment_id").execute();
2954
2954
  await db.schema.createIndex("idx_dineway_comment_reactions_voter_recent").on("_dineway_comment_reactions").columns(["voter_hash", "created_at"]).execute();
2955
2955
  }
2956
- async function down$48(db) {
2956
+ async function down$55(db) {
2957
2957
  await db.schema.dropTable("_dineway_comment_reactions").execute();
2958
2958
  }
2959
2959
 
2960
2960
  //#endregion
2961
2961
  //#region src/database/migrations/059_hitl_executions.ts
2962
2962
  var _059_hitl_executions_exports = /* @__PURE__ */ __exportAll({
2963
- down: () => down$47,
2964
- up: () => up$47
2963
+ down: () => down$54,
2964
+ up: () => up$54
2965
2965
  });
2966
- const ACTOR_TYPES = [
2966
+ const ACTOR_TYPES$1 = [
2967
2967
  "user",
2968
2968
  "api_token",
2969
2969
  "system"
@@ -2975,8 +2975,8 @@ const EXECUTION_STATUSES = [
2975
2975
  "failed",
2976
2976
  "indeterminate"
2977
2977
  ];
2978
- async function up$47(db) {
2979
- const actorTypesSql = sql.join(ACTOR_TYPES.map((value) => sql.lit(value)), sql`, `);
2978
+ async function up$54(db) {
2979
+ const actorTypesSql = sql.join(ACTOR_TYPES$1.map((value) => sql.lit(value)), sql`, `);
2980
2980
  const reviewModesSql = sql.join(REVIEW_MODES.map((value) => sql.lit(value)), sql`, `);
2981
2981
  const statusesSql = sql.join(EXECUTION_STATUSES.map((value) => sql.lit(value)), sql`, `);
2982
2982
  await db.schema.createTable("_dineway_hitl_executions").addColumn("id", "text", (col) => col.primaryKey()).addColumn("hitl_request_id", "text", (col) => col.references("_dineway_hitl_requests.id").onDelete("restrict")).addColumn("plugin_id", "text", (col) => col.notNull()).addColumn("tool_name", "text", (col) => col.notNull()).addColumn("review_mode", "text", (col) => col.notNull().check(sql`review_mode in (${reviewModesSql})`)).addColumn("action_hash", "text", (col) => col.notNull()).addColumn("idempotency_key", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().defaultTo(sql`'claimed'`).check(sql`status in (${statusesSql})`)).addColumn("actor_type", "text", (col) => col.notNull().check(sql`actor_type in (${actorTypesSql})`)).addColumn("actor_id", "text", (col) => col.notNull()).addColumn("scope", "text", (col) => col.notNull()).addColumn("target_ref_type", "text", (col) => col.notNull()).addColumn("target_ref_id", "text", (col) => col.notNull()).addColumn("result_json", "text").addColumn("error_code", "text").addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("completed_at", "text").execute();
@@ -3000,31 +3000,31 @@ async function up$47(db) {
3000
3000
  "created_at"
3001
3001
  ]).execute();
3002
3002
  }
3003
- async function down$47(db) {
3003
+ async function down$54(db) {
3004
3004
  await db.schema.dropTable("_dineway_hitl_executions").execute();
3005
3005
  }
3006
3006
 
3007
3007
  //#endregion
3008
3008
  //#region src/database/migrations/060_plugin_secrets.ts
3009
3009
  var _060_plugin_secrets_exports = /* @__PURE__ */ __exportAll({
3010
- down: () => down$46,
3011
- up: () => up$46
3010
+ down: () => down$53,
3011
+ up: () => up$53
3012
3012
  });
3013
- async function up$46(db) {
3013
+ async function up$53(db) {
3014
3014
  await db.schema.createTable("_dineway_plugin_secrets").addColumn("plugin_id", "text", (col) => col.notNull()).addColumn("secret_name", "text", (col) => col.notNull()).addColumn("encryption_version", "integer", (col) => col.notNull()).addColumn("key_id", "text", (col) => col.notNull()).addColumn("nonce", "text", (col) => col.notNull()).addColumn("ciphertext", "text", (col) => col.notNull()).addColumn("fingerprint", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addPrimaryKeyConstraint("pk_dineway_plugin_secrets", ["plugin_id", "secret_name"]).execute();
3015
3015
  await db.schema.createIndex("idx_dineway_plugin_secrets_plugin_updated").on("_dineway_plugin_secrets").columns(["plugin_id", "updated_at"]).execute();
3016
3016
  }
3017
- async function down$46(db) {
3017
+ async function down$53(db) {
3018
3018
  await db.schema.dropTable("_dineway_plugin_secrets").execute();
3019
3019
  }
3020
3020
 
3021
3021
  //#endregion
3022
3022
  //#region src/database/migrations/061_restaurant_locations.ts
3023
3023
  var _061_restaurant_locations_exports = /* @__PURE__ */ __exportAll({
3024
- down: () => down$45,
3025
- up: () => up$45
3024
+ down: () => down$52,
3025
+ up: () => up$52
3026
3026
  });
3027
- async function up$45(db) {
3027
+ async function up$52(db) {
3028
3028
  await db.schema.createTable("restaurant_locations").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("name", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'archived')`).defaultTo("active")).addColumn("active_slot", "integer", (col) => col.unique().check(sql`active_slot between 1 and 5`)).addColumn("default_key", "text", (col) => col.unique().check(sql`default_key = 'default'`)).addColumn("timezone", "text", (col) => col.notNull()).addColumn("currency", "text", (col) => col.notNull()).addColumn("address_line1", "text").addColumn("address_line2", "text").addColumn("city", "text").addColumn("region", "text").addColumn("postal_code", "text").addColumn("country_code", "text").addColumn("latitude", "real").addColumn("longitude", "real").addColumn("phone", "text").addColumn("email", "text").addColumn("service_modes_json", "text", (col) => col.notNull().defaultTo("[]")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_locations_active_slot", sql`(status = 'active' and active_slot is not null) or (status = 'archived' and active_slot is null)`).addCheckConstraint("ck_restaurant_locations_default_active", sql`default_key is null or status = 'active'`).execute();
3029
3029
  await db.schema.createIndex("idx_restaurant_locations_status").on("restaurant_locations").column("status").execute();
3030
3030
  await db.schema.createIndex("idx_restaurant_locations_created_at").on("restaurant_locations").column("created_at").execute();
@@ -3033,7 +3033,7 @@ async function up$45(db) {
3033
3033
  await db.schema.createIndex("idx_restaurant_location_memberships_user_id").on("restaurant_location_memberships").column("user_id").execute();
3034
3034
  await db.schema.createIndex("idx_restaurant_location_memberships_location_id").on("restaurant_location_memberships").column("location_id").execute();
3035
3035
  }
3036
- async function down$45(db) {
3036
+ async function down$52(db) {
3037
3037
  await db.schema.dropTable("restaurant_location_memberships").execute();
3038
3038
  await db.schema.dropTable("restaurant_locations").execute();
3039
3039
  }
@@ -3041,10 +3041,10 @@ async function down$45(db) {
3041
3041
  //#endregion
3042
3042
  //#region src/database/migrations/062_restaurant_menus.ts
3043
3043
  var _062_restaurant_menus_exports = /* @__PURE__ */ __exportAll({
3044
- down: () => down$44,
3045
- up: () => up$44
3044
+ down: () => down$51,
3045
+ up: () => up$51
3046
3046
  });
3047
- async function up$44(db) {
3047
+ async function up$51(db) {
3048
3048
  await db.schema.createTable("restaurant_menus").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("name", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'archived')`).defaultTo("active")).addColumn("is_published", "integer", (col) => col.notNull().check(sql`is_published in (0, 1)`).defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
3049
3049
  await db.schema.createTable("restaurant_menu_location_assignments").addColumn("id", "text", (col) => col.primaryKey()).addColumn("menu_id", "text", (col) => col.notNull().references("restaurant_menus.id").onDelete("cascade")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("is_active", "integer", (col) => col.notNull().check(sql`is_active in (0, 1)`).defaultTo(1)).addColumn("sort_order", "integer", (col) => col.notNull().check(sql`sort_order >= 0`).defaultTo(0)).addColumn("schedule_json", "text", (col) => col.notNull().defaultTo("[]")).addColumn("service_modes_json", "text", (col) => col.notNull().defaultTo("[]")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_menu_location_assignment", ["menu_id", "location_id"]).execute();
3050
3050
  await db.schema.createTable("restaurant_menu_sections").addColumn("id", "text", (col) => col.primaryKey()).addColumn("menu_id", "text", (col) => col.notNull().references("restaurant_menus.id").onDelete("cascade")).addColumn("slug", "text", (col) => col.notNull()).addColumn("name", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'archived')`).defaultTo("active")).addColumn("is_visible", "integer", (col) => col.notNull().check(sql`is_visible in (0, 1)`).defaultTo(1)).addColumn("available_hours_json", "text", (col) => col.notNull().defaultTo("[]")).addColumn("sort_order", "integer", (col) => col.notNull().check(sql`sort_order >= 0`).defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_menu_section_slug", ["menu_id", "slug"]).execute();
@@ -3055,9 +3055,9 @@ async function up$44(db) {
3055
3055
  await db.schema.createTable("restaurant_menu_item_modifier_groups").addColumn("id", "text", (col) => col.primaryKey()).addColumn("menu_item_id", "text", (col) => col.notNull().references("restaurant_menu_items.id").onDelete("cascade")).addColumn("modifier_group_id", "text", (col) => col.notNull().references("restaurant_modifier_groups.id").onDelete("cascade")).addColumn("min_selections", "integer", (col) => col.notNull().check(sql`min_selections >= 0`).defaultTo(0)).addColumn("max_selections", "integer", (col) => col.notNull().check(sql`max_selections >= 1`).defaultTo(1)).addColumn("sort_order", "integer", (col) => col.notNull().check(sql`sort_order >= 0`).defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_menu_item_modifier_group", ["menu_item_id", "modifier_group_id"]).addCheckConstraint("ck_restaurant_menu_item_modifier_group_limits", sql`min_selections <= max_selections`).execute();
3056
3056
  await db.schema.createTable("restaurant_menu_item_translations").addColumn("id", "text", (col) => col.primaryKey()).addColumn("menu_item_id", "text", (col) => col.notNull().references("restaurant_menu_items.id").onDelete("cascade")).addColumn("locale", "text", (col) => col.notNull()).addColumn("name", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("image_alt_text", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_menu_item_translation", ["menu_item_id", "locale"]).execute();
3057
3057
  await db.schema.createTable("restaurant_menu_overrides").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("menu_item_id", "text", (col) => col.notNull().references("restaurant_menu_items.id").onDelete("cascade")).addColumn("price_minor_override", "integer", (col) => col.check(sql`price_minor_override >= 0`)).addColumn("currency_override", "text", (col) => col.check(sql`length(currency_override) = 3`)).addColumn("available_override", "integer", (col) => col.check(sql`available_override in (0, 1)`)).addColumn("hidden_override", "integer", (col) => col.check(sql`hidden_override in (0, 1)`)).addColumn("unavailable_until_override", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_menu_override", ["location_id", "menu_item_id"]).addCheckConstraint("ck_restaurant_menu_override_price_currency", sql`(price_minor_override is null and currency_override is null) or (price_minor_override is not null and currency_override is not null)`).execute();
3058
- await createIndexes$6(db);
3058
+ await createIndexes$9(db);
3059
3059
  }
3060
- async function createIndexes$6(db) {
3060
+ async function createIndexes$9(db) {
3061
3061
  for (const [name, table, column] of [
3062
3062
  [
3063
3063
  "idx_restaurant_menus_status",
@@ -3287,7 +3287,7 @@ async function createIndexes$6(db) {
3287
3287
  ]
3288
3288
  ]) await db.schema.createIndex(name).on(table).columns([...columns]).execute();
3289
3289
  }
3290
- async function down$44(db) {
3290
+ async function down$51(db) {
3291
3291
  await db.schema.dropTable("restaurant_menu_overrides").execute();
3292
3292
  await db.schema.dropTable("restaurant_menu_item_translations").execute();
3293
3293
  await db.schema.dropTable("restaurant_menu_item_modifier_groups").execute();
@@ -3303,11 +3303,11 @@ async function down$44(db) {
3303
3303
  //#endregion
3304
3304
  //#region src/database/migrations/063_restaurant_hours.ts
3305
3305
  var _063_restaurant_hours_exports = /* @__PURE__ */ __exportAll({
3306
- down: () => down$43,
3307
- up: () => up$43
3306
+ down: () => down$50,
3307
+ up: () => up$50
3308
3308
  });
3309
3309
  const SERVICE_SCOPE_CHECK = sql`service_scope in ('all', 'dine_in', 'pickup', 'delivery', 'reservations')`;
3310
- async function up$43(db) {
3310
+ async function up$50(db) {
3311
3311
  await db.schema.createTable("restaurant_hours").addColumn("id", "text", (col) => col.primaryKey()).addColumn("weekday", "integer", (col) => col.notNull().check(sql`weekday between 0 and 6`)).addColumn("service_scope", "text", (col) => col.notNull().check(SERVICE_SCOPE_CHECK)).addColumn("windows_json", "text", (col) => col.notNull().defaultTo("[]")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_hours_day_scope", ["weekday", "service_scope"]).execute();
3312
3312
  await db.schema.createTable("restaurant_hours_overrides").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("weekday", "integer", (col) => col.notNull().check(sql`weekday between 0 and 6`)).addColumn("service_scope", "text", (col) => col.notNull().check(SERVICE_SCOPE_CHECK)).addColumn("windows_json", "text", (col) => col.notNull().defaultTo("[]")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_hours_override_day_scope", [
3313
3313
  "location_id",
@@ -3324,9 +3324,9 @@ async function up$43(db) {
3324
3324
  or
3325
3325
  (scope = 'time_range' and service_date is null and starts_at is not null and ends_at is not null and ends_at > starts_at)
3326
3326
  )`).addCheckConstraint("ck_restaurant_closures_removed", sql`(status = 'active' and removed_at is null) or (status = 'removed' and removed_at is not null)`).execute();
3327
- await createIndexes$5(db);
3327
+ await createIndexes$8(db);
3328
3328
  }
3329
- async function createIndexes$5(db) {
3329
+ async function createIndexes$8(db) {
3330
3330
  for (const [name, table, column] of [
3331
3331
  [
3332
3332
  "idx_restaurant_hours_weekday",
@@ -3436,7 +3436,7 @@ async function createIndexes$5(db) {
3436
3436
  "ends_at"
3437
3437
  ]).execute();
3438
3438
  }
3439
- async function down$43(db) {
3439
+ async function down$50(db) {
3440
3440
  await db.schema.dropTable("restaurant_closures").execute();
3441
3441
  await db.schema.dropTable("restaurant_special_hours").execute();
3442
3442
  await db.schema.dropTable("restaurant_hours_overrides").execute();
@@ -3446,18 +3446,18 @@ async function down$43(db) {
3446
3446
  //#endregion
3447
3447
  //#region src/database/migrations/064_restaurant_reservations.ts
3448
3448
  var _064_restaurant_reservations_exports = /* @__PURE__ */ __exportAll({
3449
- down: () => down$42,
3450
- up: () => up$42
3449
+ down: () => down$49,
3450
+ up: () => up$49
3451
3451
  });
3452
3452
  const RESERVATION_STATUS_CHECK = sql`status in ('pending', 'confirmed', 'seated', 'completed', 'cancelled', 'no_show')`;
3453
3453
  const RESERVATION_SOURCE_CHECK = sql`source in ('public', 'admin', 'mcp', 'import')`;
3454
3454
  const HOLD_STATUS_CHECK = sql`status in ('active', 'committed', 'released', 'expired')`;
3455
3455
  const ACTIVE_REMOVED_STATUS_CHECK = sql`status in ('active', 'removed')`;
3456
- async function up$42(db) {
3456
+ async function up$49(db) {
3457
3457
  await createSettingsTables(db);
3458
3458
  await createFloorTables(db);
3459
3459
  await createReservationTables(db);
3460
- await createIndexes$4(db);
3460
+ await createIndexes$7(db);
3461
3461
  }
3462
3462
  async function createSettingsTables(db) {
3463
3463
  await db.schema.createTable("restaurant_reservation_settings").addColumn("id", "text", (col) => col.primaryKey()).addColumn("default_key", "text", (col) => col.notNull().unique().check(sql`default_key = 'default'`).defaultTo("default")).addColumn("capacity_per_slot", "integer", (col) => col.notNull().check(sql`capacity_per_slot between 1 and 1000`).defaultTo(40)).addColumn("slot_minutes", "integer", (col) => col.notNull().check(sql`slot_minutes between 5 and 240`).defaultTo(30)).addColumn("lead_minutes", "integer", (col) => col.notNull().check(sql`lead_minutes between 0 and 10080`).defaultTo(60)).addColumn("max_party_size", "integer", (col) => col.notNull().check(sql`max_party_size between 1 and 1000`).defaultTo(12)).addColumn("hold_minutes", "integer", (col) => col.notNull().check(sql`hold_minutes between 1 and 60`).defaultTo(15)).addColumn("booking_horizon_days", "integer", (col) => col.notNull().check(sql`booking_horizon_days between 1 and 730`).defaultTo(90)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
@@ -3483,7 +3483,7 @@ async function createReservationTables(db) {
3483
3483
  or (status = 'revoked' and consumed_at is null and revoked_at is not null)
3484
3484
  )`).execute();
3485
3485
  }
3486
- async function createIndexes$4(db) {
3486
+ async function createIndexes$7(db) {
3487
3487
  for (const [name, table, column] of [
3488
3488
  [
3489
3489
  "idx_restaurant_reservation_settings_created_at",
@@ -3812,7 +3812,7 @@ async function createIndexes$4(db) {
3812
3812
  WHERE status = 'active'
3813
3813
  `.execute(db);
3814
3814
  }
3815
- async function down$42(db) {
3815
+ async function down$49(db) {
3816
3816
  await db.schema.dropTable("restaurant_guest_access").execute();
3817
3817
  await db.schema.dropTable("restaurant_reservation_table_assignments").execute();
3818
3818
  await db.schema.dropTable("restaurant_reservation_holds").execute();
@@ -3828,8 +3828,8 @@ async function down$42(db) {
3828
3828
  //#endregion
3829
3829
  //#region src/database/migrations/065_restaurant_orders.ts
3830
3830
  var _065_restaurant_orders_exports = /* @__PURE__ */ __exportAll({
3831
- down: () => down$41,
3832
- up: () => up$41
3831
+ down: () => down$48,
3832
+ up: () => up$48
3833
3833
  });
3834
3834
  const ORDER_STATUS_CHECK = sql`status in ('pending_payment', 'confirmed', 'preparing', 'ready', 'out_for_delivery', 'completed', 'cancelled')`;
3835
3835
  const ORDER_SOURCE_CHECK = sql`source in ('public', 'admin', 'mcp', 'import', 'qr')`;
@@ -3838,13 +3838,13 @@ const PAYMENT_STATUS_CHECK = sql`status in ('requires_action', 'processing', 'au
3838
3838
  const REFUND_STATUS_CHECK = sql`status in ('pending', 'succeeded', 'failed', 'cancelled')`;
3839
3839
  const CART_HOLD_STATUS_CHECK = sql`status in ('active', 'committed', 'released', 'expired')`;
3840
3840
  const ACTOR_TYPE_CHECK = sql`actor_type in ('user', 'api_token', 'system')`;
3841
- async function up$41(db) {
3842
- await createOrderTables(db);
3843
- await createPaymentTables(db);
3844
- await createIndexes$3(db);
3841
+ async function up$48(db) {
3842
+ await createOrderTables$1(db);
3843
+ await createPaymentTables$1(db);
3844
+ await createIndexes$6(db);
3845
3845
  await createImmutableLedgerTriggers(db);
3846
3846
  }
3847
- async function createOrderTables(db) {
3847
+ async function createOrderTables$1(db) {
3848
3848
  await db.schema.createTable("restaurant_order_sequences").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("next_number", "integer", (col) => col.notNull().check(sql`next_number >= 1`).defaultTo(1)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
3849
3849
  await db.schema.createTable("restaurant_orders").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("table_id", "text", (col) => col.references("restaurant_tables.id").onDelete("restrict")).addColumn("order_number", "integer", (col) => col.notNull().check(sql`order_number >= 1`)).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("fulfilment_type", "text", (col) => col.notNull().check(FULFILMENT_TYPE_CHECK$1)).addColumn("service_date", "text", (col) => col.notNull().check(sql`length(service_date) = 10`)).addColumn("fulfilment_at", "text", (col) => col.notNull()).addColumn("timezone", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(ORDER_STATUS_CHECK).defaultTo("pending_payment")).addColumn("source", "text", (col) => col.notNull().check(ORDER_SOURCE_CHECK).defaultTo("public")).addColumn("guest_name", "text", (col) => col.notNull()).addColumn("guest_email", "text").addColumn("guest_phone", "text").addColumn("delivery_address_json", "text").addColumn("special_instructions", "text").addColumn("internal_note", "text").addColumn("confirmed_at", "text").addColumn("cancelled_at", "text").addColumn("completed_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_orders_location_number", ["location_id", "order_number"]).addUniqueConstraint("uq_restaurant_orders_location_id", ["location_id", "id"]).addCheckConstraint("ck_restaurant_orders_contact", sql`fulfilment_type = 'dine_in' or guest_email is not null or guest_phone is not null`).addCheckConstraint("ck_restaurant_orders_delivery_address", sql`(fulfilment_type = 'delivery' and delivery_address_json is not null) or (fulfilment_type <> 'delivery' and delivery_address_json is null)`).addCheckConstraint("ck_restaurant_orders_table", sql`(fulfilment_type = 'dine_in' and table_id is not null) or (fulfilment_type <> 'dine_in' and table_id is null)`).addCheckConstraint("ck_restaurant_orders_cancelled", sql`(status = 'cancelled' and cancelled_at is not null) or (status <> 'cancelled' and cancelled_at is null)`).addCheckConstraint("ck_restaurant_orders_completed", sql`(status = 'completed' and completed_at is not null) or (status <> 'completed' and completed_at is null)`).execute();
3850
3850
  await db.schema.createTable("restaurant_order_snapshots").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("order_id", "text", (col) => col.notNull().unique()).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("subtotal_minor", "integer", (col) => col.notNull().check(sql`subtotal_minor >= 0`)).addColumn("discount_minor", "integer", (col) => col.notNull().check(sql`discount_minor >= 0`).defaultTo(0)).addColumn("tax_minor", "integer", (col) => col.notNull().check(sql`tax_minor >= 0`).defaultTo(0)).addColumn("tip_minor", "integer", (col) => col.notNull().check(sql`tip_minor >= 0`).defaultTo(0)).addColumn("service_fee_minor", "integer", (col) => col.notNull().check(sql`service_fee_minor >= 0`).defaultTo(0)).addColumn("delivery_fee_minor", "integer", (col) => col.notNull().check(sql`delivery_fee_minor >= 0`).defaultTo(0)).addColumn("total_minor", "integer", (col) => col.notNull().check(sql`total_minor >= 0`)).addColumn("tax_mode", "text", (col) => col.notNull().check(sql`tax_mode in ('stripe_tax', 'manual_vat', 'none')`)).addColumn("payment_flow", "text", (col) => col.notNull().check(sql`payment_flow in ('checkout', 'payment_element', 'offline')`)).addColumn("pricing_hash", "text", (col) => col.notNull()).addColumn("tax_context_json", "text", (col) => col.notNull().defaultTo("{}")).addColumn("fulfilment_context_json", "text", (col) => col.notNull().defaultTo("{}")).addColumn("provider_context_json", "text", (col) => col.notNull().defaultTo("{}")).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("fk_restaurant_order_snapshots_order_location", ["location_id", "order_id"], "restaurant_orders", ["location_id", "id"], (cb) => cb.onDelete("cascade")).addUniqueConstraint("uq_restaurant_order_snapshots_order_id", ["order_id", "id"]).addCheckConstraint("ck_restaurant_order_snapshots_total", sql`total_minor = subtotal_minor - discount_minor + tax_minor + tip_minor + service_fee_minor + delivery_fee_minor`).addCheckConstraint("ck_restaurant_order_snapshots_discount", sql`discount_minor <= subtotal_minor`).execute();
@@ -3857,7 +3857,7 @@ async function createOrderTables(db) {
3857
3857
  or (status in ('released', 'expired') and order_id is null and committed_at is null and released_at is not null)
3858
3858
  )`).execute();
3859
3859
  }
3860
- async function createPaymentTables(db) {
3860
+ async function createPaymentTables$1(db) {
3861
3861
  await db.schema.createTable("restaurant_payments").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("order_id", "text").addColumn("reservation_request_id", "text").addColumn("reservation_offer_id", "text").addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("provider", "text", (col) => col.notNull().check(sql`provider in ('stripe', 'offline')`)).addColumn("payment_flow", "text", (col) => col.notNull().check(sql`payment_flow in ('checkout', 'payment_element', 'offline')`)).addColumn("provider_session_id", "text").addColumn("provider_payment_id", "text").addColumn("status", "text", (col) => col.notNull().check(PAYMENT_STATUS_CHECK)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("amount_authorized_minor", "integer", (col) => col.notNull().check(sql`amount_authorized_minor >= 0`).defaultTo(0)).addColumn("amount_captured_minor", "integer", (col) => col.notNull().check(sql`amount_captured_minor >= 0`).defaultTo(0)).addColumn("amount_refunded_minor", "integer", (col) => col.notNull().check(sql`amount_refunded_minor >= 0`).defaultTo(0)).addColumn("failure_code", "text").addColumn("failure_message", "text").addColumn("provider_context_json", "text", (col) => col.notNull().defaultTo("{}")).addColumn("processed_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("fk_restaurant_payments_order_location", ["location_id", "order_id"], "restaurant_orders", ["location_id", "id"], (cb) => cb.onDelete("restrict")).addUniqueConstraint("uq_restaurant_payments_provider_session", ["provider", "provider_session_id"]).addUniqueConstraint("uq_restaurant_payments_provider_payment", ["provider", "provider_payment_id"]).addUniqueConstraint("uq_restaurant_payments_location_id", ["location_id", "id"]).addCheckConstraint("ck_restaurant_payments_subject", sql`(
3862
3862
  (order_id is not null and reservation_request_id is null and reservation_offer_id is null)
3863
3863
  or (order_id is null and reservation_request_id is not null and reservation_offer_id is null)
@@ -3865,7 +3865,7 @@ async function createPaymentTables(db) {
3865
3865
  )`).addCheckConstraint("ck_restaurant_payments_amounts", sql`amount_refunded_minor <= amount_captured_minor and amount_captured_minor <= amount_authorized_minor`).addCheckConstraint("ck_restaurant_payments_provider_flow", sql`(provider = 'offline' and payment_flow = 'offline') or (provider = 'stripe' and payment_flow in ('checkout', 'payment_element'))`).execute();
3866
3866
  await db.schema.createTable("restaurant_refunds").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("order_id", "text", (col) => col.notNull()).addColumn("payment_id", "text", (col) => col.notNull()).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("provider_refund_id", "text").addColumn("status", "text", (col) => col.notNull().check(REFUND_STATUS_CHECK)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("amount_minor", "integer", (col) => col.notNull().check(sql`amount_minor > 0`)).addColumn("reason", "text", (col) => col.notNull()).addColumn("financial_snapshot_json", "text", (col) => col.notNull()).addColumn("actor_type", "text", (col) => col.notNull().check(ACTOR_TYPE_CHECK)).addColumn("actor_id", "text").addColumn("failure_code", "text").addColumn("failure_message", "text").addColumn("completed_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("fk_restaurant_refunds_order_location", ["location_id", "order_id"], "restaurant_orders", ["location_id", "id"], (cb) => cb.onDelete("restrict")).addForeignKeyConstraint("fk_restaurant_refunds_payment_location", ["location_id", "payment_id"], "restaurant_payments", ["location_id", "id"], (cb) => cb.onDelete("restrict")).addUniqueConstraint("uq_restaurant_refunds_provider_refund", ["provider_refund_id", "payment_id"]).addCheckConstraint("ck_restaurant_refunds_completed", sql`(status = 'succeeded' and completed_at is not null) or (status <> 'succeeded' and completed_at is null)`).execute();
3867
3867
  }
3868
- async function createIndexes$3(db) {
3868
+ async function createIndexes$6(db) {
3869
3869
  for (const [name, table, column] of [
3870
3870
  [
3871
3871
  "idx_restaurant_order_sequences_location_id",
@@ -4175,7 +4175,7 @@ async function createImmutableLedgerTriggers(db) {
4175
4175
  `.execute(db);
4176
4176
  }
4177
4177
  }
4178
- async function down$41(db) {
4178
+ async function down$48(db) {
4179
4179
  await db.schema.dropTable("restaurant_refunds").execute();
4180
4180
  await db.schema.dropTable("restaurant_payments").execute();
4181
4181
  await db.schema.dropTable("restaurant_cart_holds").execute();
@@ -4190,10 +4190,10 @@ async function down$41(db) {
4190
4190
  //#endregion
4191
4191
  //#region src/database/migrations/066_restaurant_stripe_configuration.ts
4192
4192
  var _066_restaurant_stripe_configuration_exports = /* @__PURE__ */ __exportAll({
4193
- down: () => down$40,
4194
- up: () => up$40
4193
+ down: () => down$47,
4194
+ up: () => up$47
4195
4195
  });
4196
- async function up$40(db) {
4196
+ async function up$47(db) {
4197
4197
  await db.schema.createTable("restaurant_stripe_settings").addColumn("id", "text", (col) => col.primaryKey()).addColumn("default_key", "text", (col) => col.notNull().unique().defaultTo("default")).addColumn("mode", "text", (col) => col.notNull().check(sql`mode in ('test', 'live')`).defaultTo("test")).addColumn("publishable_key", "text").addColumn("payments_enabled", "integer", (col) => col.notNull().check(sql`payments_enabled in (0, 1)`).defaultTo(0)).addColumn("enabled_fulfilment_types_json", "text", (col) => col.notNull().defaultTo("[\"pickup\"]")).addColumn("payment_flow", "text", (col) => col.notNull().check(sql`payment_flow in ('checkout', 'payment_element')`).defaultTo("checkout")).addColumn("automatic_tax_enabled", "integer", (col) => col.notNull().check(sql`automatic_tax_enabled in (0, 1)`).defaultTo(1)).addColumn("configuration_status", "text", (col) => col.notNull().check(sql`configuration_status in ('unconfigured', 'unverified', 'valid', 'invalid')`).defaultTo("unconfigured")).addColumn("stripe_account_id", "text").addColumn("charges_enabled", "integer", (col) => col.check(sql`charges_enabled is null or charges_enabled in (0, 1)`)).addColumn("details_submitted", "integer", (col) => col.check(sql`details_submitted is null or details_submitted in (0, 1)`)).addColumn("tax_status", "text", (col) => col.notNull().check(sql`tax_status in ('unknown', 'active', 'pending', 'unavailable')`).defaultTo("unknown")).addColumn("validation_error_code", "text").addColumn("last_validated_at", "text").addColumn("connect_status", "text", (col) => col.notNull().check(sql`connect_status in ('not_configured', 'restricted', 'ready')`).defaultTo("not_configured")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_stripe_settings_default_key", sql`default_key = 'default'`).execute();
4198
4198
  await db.schema.createTable("restaurant_stripe_location_settings").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("payments_enabled", "integer", (col) => col.check(sql`payments_enabled is null or payments_enabled in (0, 1)`)).addColumn("enabled_fulfilment_types_json", "text").addColumn("payment_flow", "text", (col) => col.check(sql`payment_flow is null or payment_flow in ('checkout', 'payment_element')`)).addColumn("tax_mode", "text", (col) => col.check(sql`tax_mode is null or tax_mode in ('stripe_tax', 'manual_vat', 'none')`)).addColumn("manual_vat_reason", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_stripe_location_manual_vat_reason", sql`(tax_mode = 'manual_vat' and manual_vat_reason is not null and length(trim(manual_vat_reason)) > 0) or ((tax_mode is null or tax_mode <> 'manual_vat') and manual_vat_reason is null)`).execute();
4199
4199
  await db.schema.createTable("restaurant_stripe_manual_tax_rates").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("tax_code", "text", (col) => col.notNull().defaultTo("*")).addColumn("stripe_tax_rate_id", "text", (col) => col.notNull()).addColumn("display_name", "text", (col) => col.notNull()).addColumn("jurisdiction", "text", (col) => col.notNull()).addColumn("percentage", "text", (col) => col.notNull()).addColumn("inclusive", "integer", (col) => col.notNull().check(sql`inclusive in (0, 1)`).defaultTo(0)).addColumn("active", "integer", (col) => col.notNull().check(sql`active in (0, 1)`).defaultTo(1)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_stripe_manual_tax_rates_mapping", ["location_id", "tax_code"]).execute();
@@ -4260,7 +4260,7 @@ async function up$40(db) {
4260
4260
  "tax_code"
4261
4261
  ]).execute();
4262
4262
  }
4263
- async function down$40(db) {
4263
+ async function down$47(db) {
4264
4264
  await db.schema.dropTable("restaurant_stripe_manual_tax_rates").execute();
4265
4265
  await db.schema.dropTable("restaurant_stripe_location_settings").execute();
4266
4266
  await db.schema.dropTable("restaurant_stripe_settings").execute();
@@ -4269,10 +4269,10 @@ async function down$40(db) {
4269
4269
  //#endregion
4270
4270
  //#region src/database/migrations/067_restaurant_payment_requested_amount.ts
4271
4271
  var _067_restaurant_payment_requested_amount_exports = /* @__PURE__ */ __exportAll({
4272
- down: () => down$39,
4273
- up: () => up$39
4272
+ down: () => down$46,
4273
+ up: () => up$46
4274
4274
  });
4275
- async function up$39(db) {
4275
+ async function up$46(db) {
4276
4276
  await db.schema.alterTable("restaurant_payments").addColumn("amount_requested_minor", "integer", (column) => column.notNull().defaultTo(0).check(sql`amount_requested_minor >= 0`)).execute();
4277
4277
  await sql`
4278
4278
  UPDATE restaurant_payments
@@ -4288,19 +4288,19 @@ async function up$39(db) {
4288
4288
  WHERE amount_requested_minor = 0
4289
4289
  `.execute(db);
4290
4290
  }
4291
- async function down$39(db) {
4291
+ async function down$46(db) {
4292
4292
  await db.schema.alterTable("restaurant_payments").dropColumn("amount_requested_minor").execute();
4293
4293
  }
4294
4294
 
4295
4295
  //#endregion
4296
4296
  //#region src/database/migrations/068_restaurant_stripe_events.ts
4297
4297
  var _068_restaurant_stripe_events_exports = /* @__PURE__ */ __exportAll({
4298
- down: () => down$38,
4299
- up: () => up$38
4298
+ down: () => down$45,
4299
+ up: () => up$45
4300
4300
  });
4301
4301
  const currentTimestamp = sql`(datetime('now'))`;
4302
4302
  const retentionTimestamp = sql`(datetime('now', '+30 days'))`;
4303
- async function up$38(db) {
4303
+ async function up$45(db) {
4304
4304
  await db.schema.createTable("restaurant_stripe_events").addColumn("id", "text", (col) => col.primaryKey()).addColumn("event_id", "text", (col) => col.notNull().unique()).addColumn("event_type", "text", (col) => col.notNull()).addColumn("livemode", "integer", (col) => col.notNull().check(sql`livemode in (0, 1)`)).addColumn("api_version", "text").addColumn("object_type", "text").addColumn("object_id", "text").addColumn("payload_sha256", "text", (col) => col.notNull().check(sql`length(payload_sha256) = 71 and payload_sha256 like 'sha256:%'`)).addColumn("status", "text", (col) => col.notNull().defaultTo("processing").check(sql`status in ('processing', 'processed', 'failed', 'ignored')`)).addColumn("attempt_count", "integer", (col) => col.notNull().defaultTo(1).check(sql`attempt_count >= 1`)).addColumn("error_code", "text", (col) => col.check(sql`length(error_code) <= 64`)).addColumn("location_id", "text", (col) => col.references("restaurant_locations.id").onDelete("set null")).addColumn("payment_id", "text", (col) => col.references("restaurant_payments.id").onDelete("set null")).addColumn("received_at", "text", (col) => col.notNull().defaultTo(currentTimestamp)).addColumn("last_attempt_at", "text", (col) => col.notNull().defaultTo(currentTimestamp)).addColumn("processed_at", "text").addColumn("retain_until", "text", (col) => col.notNull().defaultTo(retentionTimestamp)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp)).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp)).addCheckConstraint("ck_restaurant_stripe_events_object", sql`(object_type is null and object_id is null) or (object_type is not null and object_id is not null)`).addCheckConstraint("ck_restaurant_stripe_events_processed", sql`(status in ('processed', 'ignored') and processed_at is not null) or (status in ('processing', 'failed') and processed_at is null)`).addCheckConstraint("ck_restaurant_stripe_events_retention", sql`datetime(retain_until) >= datetime(received_at, '+30 days')`).execute();
4305
4305
  for (const [name, column] of [
4306
4306
  ["idx_restaurant_stripe_events_status", "status"],
@@ -4317,22 +4317,22 @@ async function up$38(db) {
4317
4317
  "id"
4318
4318
  ]).execute();
4319
4319
  }
4320
- async function down$38(db) {
4320
+ async function down$45(db) {
4321
4321
  await db.schema.dropTable("restaurant_stripe_events").execute();
4322
4322
  }
4323
4323
 
4324
4324
  //#endregion
4325
4325
  //#region src/database/migrations/069_restaurant_tax_behavior.ts
4326
4326
  var _069_restaurant_tax_behavior_exports = /* @__PURE__ */ __exportAll({
4327
- down: () => down$37,
4328
- up: () => up$37
4327
+ down: () => down$44,
4328
+ up: () => up$44
4329
4329
  });
4330
- async function up$37(db) {
4330
+ async function up$44(db) {
4331
4331
  await db.schema.alterTable("restaurant_stripe_settings").addColumn("default_tax_behavior", "text", (column) => column.notNull().defaultTo("exclusive").check(sql`default_tax_behavior in ('exclusive', 'inclusive')`)).execute();
4332
4332
  await db.schema.alterTable("restaurant_stripe_location_settings").addColumn("tax_behavior", "text", (column) => column.check(sql`tax_behavior is null or tax_behavior in ('exclusive', 'inclusive')`)).execute();
4333
4333
  await db.schema.alterTable("restaurant_menu_items").addColumn("tax_behavior", "text", (column) => column.check(sql`tax_behavior is null or tax_behavior in ('exclusive', 'inclusive')`)).execute();
4334
4334
  }
4335
- async function down$37(db) {
4335
+ async function down$44(db) {
4336
4336
  await db.schema.alterTable("restaurant_menu_items").dropColumn("tax_behavior").execute();
4337
4337
  await db.schema.alterTable("restaurant_stripe_location_settings").dropColumn("tax_behavior").execute();
4338
4338
  await db.schema.alterTable("restaurant_stripe_settings").dropColumn("default_tax_behavior").execute();
@@ -4341,15 +4341,15 @@ async function down$37(db) {
4341
4341
  //#endregion
4342
4342
  //#region src/database/migrations/070_restaurant_inclusive_order_item_totals.ts
4343
4343
  var _070_restaurant_inclusive_order_item_totals_exports = /* @__PURE__ */ __exportAll({
4344
- down: () => down$36,
4345
- up: () => up$36
4344
+ down: () => down$43,
4345
+ up: () => up$43
4346
4346
  });
4347
4347
  const REBUILT_ORDER_ITEMS = "_restaurant_order_items_rebuild";
4348
4348
  const REBUILT_ORDER_ITEM_MODIFIERS = "_restaurant_order_item_modifiers_rebuild";
4349
- async function up$36(db) {
4349
+ async function up$43(db) {
4350
4350
  await rebuildOrderItemLedger(db, true);
4351
4351
  }
4352
- async function down$36(db) {
4352
+ async function down$43(db) {
4353
4353
  await rebuildOrderItemLedger(db, false);
4354
4354
  }
4355
4355
  async function rebuildOrderItemLedger(db, inclusiveAware) {
@@ -4385,7 +4385,7 @@ async function rebuildOrderItemLedger(db, inclusiveAware) {
4385
4385
  await db.schema.dropTable("restaurant_order_items").execute();
4386
4386
  await db.schema.alterTable(REBUILT_ORDER_ITEMS).renameTo("restaurant_order_items").execute();
4387
4387
  await db.schema.alterTable(REBUILT_ORDER_ITEM_MODIFIERS).renameTo("restaurant_order_item_modifiers").execute();
4388
- await createIndexes$2(db);
4388
+ await createIndexes$5(db);
4389
4389
  await createImmutableTriggers(db);
4390
4390
  }
4391
4391
  async function createOrderItemsTable(db, inclusiveAware) {
@@ -4396,7 +4396,7 @@ async function createOrderItemsTable(db, inclusiveAware) {
4396
4396
  async function createOrderItemModifiersTable(db) {
4397
4397
  await db.schema.createTable(REBUILT_ORDER_ITEM_MODIFIERS).addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("order_id", "text", (column) => column.notNull()).addColumn("order_item_id", "text", (column) => column.notNull().references(`${REBUILT_ORDER_ITEMS}.id`).onDelete("cascade")).addColumn("modifier_option_id", "text", (column) => column.references("restaurant_modifier_options.id").onDelete("set null")).addColumn("group_name", "text", (column) => column.notNull()).addColumn("option_name", "text", (column) => column.notNull()).addColumn("quantity", "integer", (column) => column.notNull().check(sql`quantity >= 1`)).addColumn("unit_amount_minor", "integer", (column) => column.notNull().check(sql`unit_amount_minor >= 0`)).addColumn("total_amount_minor", "integer", (column) => column.notNull().check(sql`total_amount_minor = unit_amount_minor * quantity`)).addColumn("sort_order", "integer", (column) => column.notNull().defaultTo(0)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("fk_restaurant_order_item_modifiers_order_location", ["location_id", "order_id"], "restaurant_orders", ["location_id", "id"], (callback) => callback.onDelete("cascade")).execute();
4398
4398
  }
4399
- async function createIndexes$2(db) {
4399
+ async function createIndexes$5(db) {
4400
4400
  for (const [name, table, column] of [
4401
4401
  [
4402
4402
  "idx_restaurant_order_items_location_id",
@@ -4472,11 +4472,11 @@ async function createImmutableTriggers(db) {
4472
4472
  //#endregion
4473
4473
  //#region src/database/migrations/071_restaurant_delivery_zones.ts
4474
4474
  var _071_restaurant_delivery_zones_exports = /* @__PURE__ */ __exportAll({
4475
- down: () => down$35,
4476
- up: () => up$35
4475
+ down: () => down$42,
4476
+ up: () => up$42
4477
4477
  });
4478
4478
  const DELIVERY_ZONE_STATUS_CHECK = sql`status in ('active', 'archived')`;
4479
- async function up$35(db) {
4479
+ async function up$42(db) {
4480
4480
  await db.schema.createTable("restaurant_delivery_zones").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("name", "text", (column) => column.notNull()).addColumn("status", "text", (column) => column.notNull().check(DELIVERY_ZONE_STATUS_CHECK).defaultTo("active")).addColumn("priority", "integer", (column) => column.notNull().check(sql`priority >= 0`).defaultTo(0)).addColumn("radius_meters", "integer", (column) => column.check(sql`radius_meters is null or radius_meters > 0`)).addColumn("postal_codes_json", "text", (column) => column.notNull().defaultTo("[]")).addColumn("area_codes_json", "text", (column) => column.notNull().defaultTo("[]")).addColumn("fee_minor", "integer", (column) => column.notNull().check(sql`fee_minor >= 0`).defaultTo(0)).addColumn("minimum_order_minor", "integer", (column) => column.notNull().check(sql`minimum_order_minor >= 0`).defaultTo(0)).addColumn("estimated_minutes", "integer", (column) => column.notNull().check(sql`estimated_minutes between 1 and 1440`).defaultTo(45)).addColumn("version", "integer", (column) => column.notNull().check(sql`version >= 1`).defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_delivery_zones_location_id", ["location_id", "id"]).execute();
4481
4481
  await db.schema.createIndex("idx_restaurant_delivery_zones_location_status_priority").on("restaurant_delivery_zones").columns([
4482
4482
  "location_id",
@@ -4485,35 +4485,35 @@ async function up$35(db) {
4485
4485
  "id"
4486
4486
  ]).execute();
4487
4487
  }
4488
- async function down$35(db) {
4488
+ async function down$42(db) {
4489
4489
  await db.schema.dropTable("restaurant_delivery_zones").execute();
4490
4490
  }
4491
4491
 
4492
4492
  //#endregion
4493
4493
  //#region src/database/migrations/072_restaurant_delivery_settings.ts
4494
4494
  var _072_restaurant_delivery_settings_exports = /* @__PURE__ */ __exportAll({
4495
- down: () => down$34,
4496
- up: () => up$34
4495
+ down: () => down$41,
4496
+ up: () => up$41
4497
4497
  });
4498
4498
  const SLOT_MINUTES_CHECK = sql`slot_minutes between 5 and 120 and slot_minutes % 5 = 0`;
4499
- async function up$34(db) {
4499
+ async function up$41(db) {
4500
4500
  await db.schema.createTable("restaurant_delivery_settings").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("slot_minutes", "integer", (column) => column.notNull().check(SLOT_MINUTES_CHECK).defaultTo(30)).addColumn("lead_minutes", "integer", (column) => column.notNull().check(sql`lead_minutes between 0 and 10080`).defaultTo(60)).addColumn("booking_horizon_days", "integer", (column) => column.notNull().check(sql`booking_horizon_days between 0 and 365`).defaultTo(14)).addColumn("version", "integer", (column) => column.notNull().check(sql`version >= 1`).defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
4501
4501
  await db.schema.createIndex("idx_restaurant_delivery_settings_location_id").on("restaurant_delivery_settings").column("location_id").execute();
4502
4502
  }
4503
- async function down$34(db) {
4503
+ async function down$41(db) {
4504
4504
  await db.schema.dropTable("restaurant_delivery_settings").execute();
4505
4505
  }
4506
4506
 
4507
4507
  //#endregion
4508
4508
  //#region src/database/migrations/073_restaurant_dine_in.ts
4509
4509
  var _073_restaurant_dine_in_exports = /* @__PURE__ */ __exportAll({
4510
- down: () => down$33,
4511
- up: () => up$33
4510
+ down: () => down$40,
4511
+ up: () => up$40
4512
4512
  });
4513
4513
  const SESSION_STATUS_CHECK = sql`status in ('open', 'closed', 'cancelled')`;
4514
4514
  const ROUND_PAYMENT_MODE_CHECK = sql`payment_mode in ('prepaid', 'offline', 'tab')`;
4515
4515
  const ROUND_STATUS_CHECK = sql`status in ('open', 'authorized', 'settled', 'voided')`;
4516
- async function up$33(db) {
4516
+ async function up$40(db) {
4517
4517
  await db.schema.createTable("restaurant_dine_in_sessions").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("table_id", "text", (col) => col.notNull().references("restaurant_tables.id").onDelete("restrict")).addColumn("session_key", "text", (col) => col.notNull().unique()).addColumn("token_id", "text", (col) => col.notNull().unique()).addColumn("token_hash", "text", (col) => col.notNull().unique()).addColumn("service_date", "text", (col) => col.notNull().check(sql`length(service_date) = 10`)).addColumn("status", "text", (col) => col.notNull().check(SESSION_STATUS_CHECK).defaultTo("open")).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("opened_at", "text", (col) => col.notNull()).addColumn("closed_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_dine_in_sessions_location_id", ["location_id", "id"]).addCheckConstraint("ck_restaurant_dine_in_sessions_state", sql`(status = 'open' and closed_at is null) or (status in ('closed', 'cancelled') and closed_at is not null)`).execute();
4518
4518
  await db.schema.createTable("restaurant_tab_rounds").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("session_id", "text", (col) => col.notNull()).addColumn("order_id", "text", (col) => col.notNull().unique()).addColumn("payment_id", "text", (col) => col.unique()).addColumn("round_number", "integer", (col) => col.notNull().check(sql`round_number >= 1`)).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("payment_mode", "text", (col) => col.notNull().check(ROUND_PAYMENT_MODE_CHECK)).addColumn("status", "text", (col) => col.notNull().check(ROUND_STATUS_CHECK).defaultTo("open")).addColumn("authorization_ceiling_minor", "integer", (col) => col.notNull().check(sql`authorization_ceiling_minor >= 0`).defaultTo(0)).addColumn("amount_requested_minor", "integer", (col) => col.notNull().check(sql`amount_requested_minor > 0`)).addColumn("amount_authorized_minor", "integer", (col) => col.notNull().check(sql`amount_authorized_minor >= 0`).defaultTo(0)).addColumn("amount_captured_minor", "integer", (col) => col.notNull().check(sql`amount_captured_minor >= 0`).defaultTo(0)).addColumn("amount_refunded_minor", "integer", (col) => col.notNull().check(sql`amount_refunded_minor >= 0`).defaultTo(0)).addColumn("opened_at", "text", (col) => col.notNull()).addColumn("settled_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addForeignKeyConstraint("fk_restaurant_tab_rounds_session_location", ["location_id", "session_id"], "restaurant_dine_in_sessions", ["location_id", "id"], (cb) => cb.onDelete("restrict")).addForeignKeyConstraint("fk_restaurant_tab_rounds_order_location", ["location_id", "order_id"], "restaurant_orders", ["location_id", "id"], (cb) => cb.onDelete("restrict")).addForeignKeyConstraint("fk_restaurant_tab_rounds_payment_location", ["location_id", "payment_id"], "restaurant_payments", ["location_id", "id"], (cb) => cb.onDelete("restrict")).addUniqueConstraint("uq_restaurant_tab_rounds_session_number", ["session_id", "round_number"]).addUniqueConstraint("uq_restaurant_tab_rounds_location_id", ["location_id", "id"]).addCheckConstraint("ck_restaurant_tab_rounds_amounts", sql`amount_refunded_minor <= amount_captured_minor and amount_captured_minor <= amount_authorized_minor`).addCheckConstraint("ck_restaurant_tab_rounds_authorization", sql`payment_mode <> 'tab' or authorization_ceiling_minor >= amount_requested_minor`).addCheckConstraint("ck_restaurant_tab_rounds_settled", sql`(status = 'settled' and settled_at is not null) or (status <> 'settled' and settled_at is null)`).execute();
4519
4519
  await db.schema.createIndex("idx_restaurant_dine_in_sessions_location_id").on("restaurant_dine_in_sessions").column("location_id").execute();
@@ -4541,7 +4541,7 @@ async function up$33(db) {
4541
4541
  WHERE status = 'open'
4542
4542
  `.execute(db);
4543
4543
  }
4544
- async function down$33(db) {
4544
+ async function down$40(db) {
4545
4545
  await db.schema.dropTable("restaurant_tab_rounds").execute();
4546
4546
  await db.schema.dropTable("restaurant_dine_in_sessions").execute();
4547
4547
  }
@@ -4549,11 +4549,11 @@ async function down$33(db) {
4549
4549
  //#endregion
4550
4550
  //#region src/database/migrations/074_restaurant_outbox.ts
4551
4551
  var _074_restaurant_outbox_exports = /* @__PURE__ */ __exportAll({
4552
- down: () => down$32,
4553
- up: () => up$32
4552
+ down: () => down$39,
4553
+ up: () => up$39
4554
4554
  });
4555
4555
  const OUTBOX_STATUS_CHECK = sql`status in ('pending', 'processing', 'delivered', 'failed')`;
4556
- async function up$32(db) {
4556
+ async function up$39(db) {
4557
4557
  await db.schema.createTable("restaurant_outbox_events").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("aggregate_type", "text", (col) => col.notNull().check(sql`length(aggregate_type) between 1 and 64`)).addColumn("aggregate_id", "text", (col) => col.notNull().check(sql`length(aggregate_id) between 1 and 128`)).addColumn("event_type", "text", (col) => col.notNull().check(sql`length(event_type) between 1 and 128`)).addColumn("dedupe_key", "text", (col) => col.notNull().unique()).addColumn("payload_json", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(OUTBOX_STATUS_CHECK).defaultTo("pending")).addColumn("attempt_count", "integer", (col) => col.notNull().check(sql`attempt_count >= 0`).defaultTo(0)).addColumn("available_at", "text", (col) => col.notNull()).addColumn("locked_until", "text").addColumn("last_error_code", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_outbox_location_id", ["location_id", "id"]).execute();
4558
4558
  for (const [name, column] of [
4559
4559
  ["idx_restaurant_outbox_location_id", "location_id"],
@@ -4569,19 +4569,19 @@ async function up$32(db) {
4569
4569
  "id"
4570
4570
  ]).execute();
4571
4571
  }
4572
- async function down$32(db) {
4572
+ async function down$39(db) {
4573
4573
  await db.schema.dropTable("restaurant_outbox_events").execute();
4574
4574
  }
4575
4575
 
4576
4576
  //#endregion
4577
4577
  //#region src/database/migrations/075_restaurant_kds_tickets.ts
4578
4578
  var _075_restaurant_kds_tickets_exports = /* @__PURE__ */ __exportAll({
4579
- down: () => down$31,
4580
- up: () => up$31
4579
+ down: () => down$38,
4580
+ up: () => up$38
4581
4581
  });
4582
4582
  const FULFILMENT_TYPE_CHECK = sql`fulfilment_type in ('dine_in', 'pickup', 'delivery')`;
4583
4583
  const KDS_STATUS_CHECK = sql`status in ('queued', 'preparing', 'ready', 'completed', 'cancelled')`;
4584
- async function up$31(db) {
4584
+ async function up$38(db) {
4585
4585
  await db.schema.createTable("restaurant_kds_tickets").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("order_id", "text", (col) => col.notNull().unique().references("restaurant_orders.id").onDelete("restrict")).addColumn("order_number", "integer", (col) => col.notNull().check(sql`order_number > 0`)).addColumn("fulfilment_type", "text", (col) => col.notNull().check(FULFILMENT_TYPE_CHECK)).addColumn("items_json", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(KDS_STATUS_CHECK).defaultTo("queued")).addColumn("priority", "integer", (col) => col.notNull().check(sql`priority >= 0`).defaultTo(0)).addColumn("started_at", "text").addColumn("ready_at", "text").addColumn("completed_at", "text").addColumn("cancelled_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_kds_tickets_location_id", ["location_id", "id"]).addForeignKeyConstraint("fk_restaurant_kds_tickets_order_location", ["location_id", "order_id"], "restaurant_orders", ["location_id", "id"], (cb) => cb.onDelete("restrict")).execute();
4586
4586
  for (const [name, column] of [
4587
4587
  ["idx_restaurant_kds_tickets_location_id", "location_id"],
@@ -4599,38 +4599,38 @@ async function up$31(db) {
4599
4599
  "id"
4600
4600
  ]).execute();
4601
4601
  }
4602
- async function down$31(db) {
4602
+ async function down$38(db) {
4603
4603
  await db.schema.dropTable("restaurant_kds_tickets").execute();
4604
4604
  }
4605
4605
 
4606
4606
  //#endregion
4607
4607
  //#region src/database/migrations/076_restaurant_notification_settings.ts
4608
4608
  var _076_restaurant_notification_settings_exports = /* @__PURE__ */ __exportAll({
4609
- down: () => down$30,
4610
- up: () => up$30
4609
+ down: () => down$37,
4610
+ up: () => up$37
4611
4611
  });
4612
4612
  const SCOPE_CHECK = sql`(
4613
4613
  (location_id is null and scope_key = 'global') or
4614
4614
  (location_id is not null and scope_key = ('location:' || location_id))
4615
4615
  )`;
4616
- async function up$30(db) {
4616
+ async function up$37(db) {
4617
4617
  await db.schema.createTable("restaurant_notification_settings").addColumn("id", "text", (col) => col.primaryKey()).addColumn("scope_key", "text", (col) => col.notNull().unique()).addColumn("location_id", "text", (col) => col.references("restaurant_locations.id").onDelete("cascade")).addColumn("webhook_url", "text", (col) => col.check(sql`webhook_url is null or length(webhook_url) between 1 and 2048`)).addColumn("webhook_enabled", "integer", (col) => col.notNull().check(sql`webhook_enabled in (0, 1)`).defaultTo(0)).addColumn("webhook_event_types_json", "text", (col) => col.notNull().defaultTo("[]")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_notification_settings_scope", SCOPE_CHECK).execute();
4618
4618
  await db.schema.createIndex("idx_restaurant_notification_settings_location_id").on("restaurant_notification_settings").column("location_id").execute();
4619
4619
  await db.schema.createIndex("idx_restaurant_notification_settings_updated_at").on("restaurant_notification_settings").column("updated_at").execute();
4620
4620
  }
4621
- async function down$30(db) {
4621
+ async function down$37(db) {
4622
4622
  await db.schema.dropTable("restaurant_notification_settings").execute();
4623
4623
  }
4624
4624
 
4625
4625
  //#endregion
4626
4626
  //#region src/database/migrations/077_restaurant_outbox_deliveries.ts
4627
4627
  var _077_restaurant_outbox_deliveries_exports = /* @__PURE__ */ __exportAll({
4628
- down: () => down$29,
4629
- up: () => up$29
4628
+ down: () => down$36,
4629
+ up: () => up$36
4630
4630
  });
4631
4631
  const CHANNEL_CHECK = sql`channel in ('email', 'webhook', 'receipt', 'external_kds')`;
4632
4632
  const DELIVERY_STATUS_CHECK = sql`status in ('pending', 'processing', 'delivered', 'failed')`;
4633
- async function up$29(db) {
4633
+ async function up$36(db) {
4634
4634
  await db.schema.createTable("restaurant_outbox_deliveries").addColumn("id", "text", (col) => col.primaryKey()).addColumn("event_id", "text", (col) => col.notNull().references("restaurant_outbox_events.id").onDelete("cascade")).addColumn("channel", "text", (col) => col.notNull().check(CHANNEL_CHECK)).addColumn("status", "text", (col) => col.notNull().check(DELIVERY_STATUS_CHECK).defaultTo("pending")).addColumn("attempt_count", "integer", (col) => col.notNull().check(sql`attempt_count >= 0`).defaultTo(0)).addColumn("available_at", "text", (col) => col.notNull()).addColumn("locked_until", "text").addColumn("last_error_code", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_outbox_delivery_event_channel", ["event_id", "channel"]).execute();
4635
4635
  await db.schema.createIndex("idx_restaurant_outbox_deliveries_event_id").on("restaurant_outbox_deliveries").column("event_id").execute();
4636
4636
  await db.schema.createIndex("idx_restaurant_outbox_deliveries_channel").on("restaurant_outbox_deliveries").column("channel").execute();
@@ -4672,17 +4672,17 @@ async function up$29(db) {
4672
4672
  ON CONFLICT (event_id, channel) DO NOTHING
4673
4673
  `.execute(db);
4674
4674
  }
4675
- async function down$29(db) {
4675
+ async function down$36(db) {
4676
4676
  await db.schema.dropTable("restaurant_outbox_deliveries").execute();
4677
4677
  }
4678
4678
 
4679
4679
  //#endregion
4680
4680
  //#region src/database/migrations/078_restaurant_external_kds_settings.ts
4681
4681
  var _078_restaurant_external_kds_settings_exports = /* @__PURE__ */ __exportAll({
4682
- down: () => down$28,
4683
- up: () => up$28
4682
+ down: () => down$35,
4683
+ up: () => up$35
4684
4684
  });
4685
- async function up$28(db) {
4685
+ async function up$35(db) {
4686
4686
  await db.schema.alterTable("restaurant_notification_settings").addColumn("external_kds_url", "text", (col) => col.check(sql`external_kds_url is null or length(external_kds_url) between 1 and 2048`)).execute();
4687
4687
  await db.schema.alterTable("restaurant_notification_settings").addColumn("external_kds_enabled", "integer", (col) => col.notNull().check(sql`external_kds_enabled in (0, 1)`).defaultTo(0)).execute();
4688
4688
  await db.schema.alterTable("restaurant_notification_settings").addColumn("external_kds_event_types_json", "text", (col) => col.notNull().defaultTo("[]")).execute();
@@ -4699,7 +4699,7 @@ async function up$28(db) {
4699
4699
  ON CONFLICT (event_id, channel) DO NOTHING
4700
4700
  `.execute(db);
4701
4701
  }
4702
- async function down$28(db) {
4702
+ async function down$35(db) {
4703
4703
  await db.schema.alterTable("restaurant_notification_settings").dropColumn("external_kds_event_types_json").execute();
4704
4704
  await db.schema.alterTable("restaurant_notification_settings").dropColumn("external_kds_enabled").execute();
4705
4705
  await db.schema.alterTable("restaurant_notification_settings").dropColumn("external_kds_url").execute();
@@ -4708,26 +4708,26 @@ async function down$28(db) {
4708
4708
  //#endregion
4709
4709
  //#region src/database/migrations/079_restaurant_dine_in_settings.ts
4710
4710
  var _079_restaurant_dine_in_settings_exports = /* @__PURE__ */ __exportAll({
4711
- down: () => down$27,
4712
- up: () => up$27
4711
+ down: () => down$34,
4712
+ up: () => up$34
4713
4713
  });
4714
4714
  const PAYMENT_MODE_CHECK = sql`default_payment_mode in ('prepaid', 'offline', 'tab')`;
4715
- async function up$27(db) {
4715
+ async function up$34(db) {
4716
4716
  await db.schema.createTable("restaurant_dine_in_settings").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("qr_enabled", "integer", (column) => column.notNull().check(sql`qr_enabled in (0, 1)`).defaultTo(1)).addColumn("offline_payment_enabled", "integer", (column) => column.notNull().check(sql`offline_payment_enabled in (0, 1)`).defaultTo(1)).addColumn("open_tab_enabled", "integer", (column) => column.notNull().check(sql`open_tab_enabled in (0, 1)`).defaultTo(1)).addColumn("default_payment_mode", "text", (column) => column.notNull().check(PAYMENT_MODE_CHECK).defaultTo("prepaid")).addColumn("tab_authorization_ceiling_minor", "integer", (column) => column.notNull().check(sql`tab_authorization_ceiling_minor >= 0`).defaultTo(0)).addColumn("session_ttl_seconds", "integer", (column) => column.notNull().check(sql`session_ttl_seconds between 300 and 86400`).defaultTo(43200)).addColumn("version", "integer", (column) => column.notNull().check(sql`version >= 1`).defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_dine_in_settings_default_mode", sql`default_payment_mode <> 'tab' or open_tab_enabled = 1`).execute();
4717
4717
  await db.schema.createIndex("idx_restaurant_dine_in_settings_location_id").on("restaurant_dine_in_settings").column("location_id").execute();
4718
4718
  await db.schema.createIndex("idx_restaurant_dine_in_settings_updated_at").on("restaurant_dine_in_settings").column("updated_at").execute();
4719
4719
  }
4720
- async function down$27(db) {
4720
+ async function down$34(db) {
4721
4721
  await db.schema.dropTable("restaurant_dine_in_settings").execute();
4722
4722
  }
4723
4723
 
4724
4724
  //#endregion
4725
4725
  //#region src/database/migrations/080_restaurant_operating_settings.ts
4726
4726
  var _080_restaurant_operating_settings_exports = /* @__PURE__ */ __exportAll({
4727
- down: () => down$26,
4728
- up: () => up$26
4727
+ down: () => down$33,
4728
+ up: () => up$33
4729
4729
  });
4730
- async function up$26(db) {
4730
+ async function up$33(db) {
4731
4731
  await db.schema.createTable("restaurant_operating_settings").addColumn("id", "text", (column) => column.primaryKey()).addColumn("scope_key", "text", (column) => column.notNull().unique()).addColumn("location_id", "text", (column) => column.unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("default_currency", "text").addColumn("default_timezone", "text").addColumn("default_service_modes_json", "text").addColumn("tips_enabled", "integer", (column) => column.check(sql`tips_enabled in (0, 1)`)).addColumn("suggested_tip_percentages_json", "text").addColumn("service_fee_basis_points", "integer", (column) => column.check(sql`service_fee_basis_points between 0 and 10000`)).addColumn("version", "integer", (column) => column.notNull().check(sql`version >= 1`).defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_operating_settings_scope", sql`(
4732
4732
  location_id is null and scope_key = '*' and
4733
4733
  default_currency is not null and default_timezone is not null and
@@ -4740,22 +4740,22 @@ async function up$26(db) {
4740
4740
  await db.schema.createIndex("idx_restaurant_operating_settings_location_id").on("restaurant_operating_settings").column("location_id").execute();
4741
4741
  await db.schema.createIndex("idx_restaurant_operating_settings_updated_at").on("restaurant_operating_settings").column("updated_at").execute();
4742
4742
  }
4743
- async function down$26(db) {
4743
+ async function down$33(db) {
4744
4744
  await db.schema.dropTable("restaurant_operating_settings").execute();
4745
4745
  }
4746
4746
 
4747
4747
  //#endregion
4748
4748
  //#region src/database/migrations/081_restaurant_email_notification_settings.ts
4749
4749
  var _081_restaurant_email_notification_settings_exports = /* @__PURE__ */ __exportAll({
4750
- down: () => down$25,
4751
- up: () => up$25
4750
+ down: () => down$32,
4751
+ up: () => up$32
4752
4752
  });
4753
- async function up$25(db) {
4753
+ async function up$32(db) {
4754
4754
  await db.schema.alterTable("restaurant_notification_settings").addColumn("email_enabled", "integer", (col) => col.notNull().check(sql`email_enabled in (0, 1)`).defaultTo(0)).execute();
4755
4755
  await db.schema.alterTable("restaurant_notification_settings").addColumn("email_event_types_json", "text", (col) => col.notNull().defaultTo("[]")).execute();
4756
4756
  await db.schema.alterTable("restaurant_notification_settings").addColumn("email_templates_json", "text", (col) => col.notNull().defaultTo("{}")).execute();
4757
4757
  }
4758
- async function down$25(db) {
4758
+ async function down$32(db) {
4759
4759
  await db.schema.alterTable("restaurant_notification_settings").dropColumn("email_templates_json").execute();
4760
4760
  await db.schema.alterTable("restaurant_notification_settings").dropColumn("email_event_types_json").execute();
4761
4761
  await db.schema.alterTable("restaurant_notification_settings").dropColumn("email_enabled").execute();
@@ -4764,17 +4764,17 @@ async function down$25(db) {
4764
4764
  //#endregion
4765
4765
  //#region src/database/migrations/082_restaurant_reservation_checkout_holds.ts
4766
4766
  var _082_restaurant_reservation_checkout_holds_exports = /* @__PURE__ */ __exportAll({
4767
- down: () => down$24,
4768
- up: () => up$24
4767
+ down: () => down$31,
4768
+ up: () => up$31
4769
4769
  });
4770
- async function up$24(db) {
4770
+ async function up$31(db) {
4771
4771
  await db.schema.alterTable("restaurant_reservation_holds").addColumn("zone_id", "text", (col) => col.references("restaurant_zones.id").onDelete("set null")).execute();
4772
4772
  await db.schema.alterTable("restaurant_reservation_holds").addColumn("token_id", "text").execute();
4773
4773
  await db.schema.alterTable("restaurant_reservation_holds").addColumn("token_hash", "text").execute();
4774
4774
  await db.schema.createIndex("idx_restaurant_reservation_holds_zone_id").on("restaurant_reservation_holds").column("zone_id").execute();
4775
4775
  await db.schema.createIndex("idx_restaurant_reservation_holds_token_hash").unique().on("restaurant_reservation_holds").column("token_hash").execute();
4776
4776
  }
4777
- async function down$24(db) {
4777
+ async function down$31(db) {
4778
4778
  await db.schema.dropIndex("idx_restaurant_reservation_holds_token_hash").execute();
4779
4779
  await db.schema.dropIndex("idx_restaurant_reservation_holds_zone_id").execute();
4780
4780
  await db.schema.alterTable("restaurant_reservation_holds").dropColumn("token_hash").execute();
@@ -4785,10 +4785,10 @@ async function down$24(db) {
4785
4785
  //#endregion
4786
4786
  //#region src/database/migrations/083_restaurant_reservation_availability_indexes.ts
4787
4787
  var _083_restaurant_reservation_availability_indexes_exports = /* @__PURE__ */ __exportAll({
4788
- down: () => down$23,
4789
- up: () => up$23
4788
+ down: () => down$30,
4789
+ up: () => up$30
4790
4790
  });
4791
- async function up$23(db) {
4791
+ async function up$30(db) {
4792
4792
  await db.schema.createIndex("idx_restaurant_reservations_location_availability").on("restaurant_reservations").columns([
4793
4793
  "location_id",
4794
4794
  "status",
@@ -4803,7 +4803,7 @@ async function up$23(db) {
4803
4803
  "expires_at"
4804
4804
  ]).execute();
4805
4805
  }
4806
- async function down$23(db) {
4806
+ async function down$30(db) {
4807
4807
  await db.schema.dropIndex("idx_restaurant_reservation_holds_location_availability").execute();
4808
4808
  await db.schema.dropIndex("idx_restaurant_reservations_location_availability").execute();
4809
4809
  }
@@ -4811,19 +4811,19 @@ async function down$23(db) {
4811
4811
  //#endregion
4812
4812
  //#region src/database/migrations/084_restaurant_reservation_demand.ts
4813
4813
  var _084_restaurant_reservation_demand_exports = /* @__PURE__ */ __exportAll({
4814
- down: () => down$22,
4815
- up: () => up$22
4814
+ down: () => down$29,
4815
+ up: () => up$29
4816
4816
  });
4817
- async function up$22(db) {
4817
+ async function up$29(db) {
4818
4818
  await createDemandSettings(db);
4819
4819
  await createReservationRequests(db);
4820
4820
  await createRequestTableAssignments(db);
4821
4821
  await createPriorityAlerts(db);
4822
4822
  await createPriorityAlertOpportunities(db);
4823
4823
  await createPriorityAlertDeliveries(db);
4824
- await createIndexes$1(db);
4824
+ await createIndexes$4(db);
4825
4825
  }
4826
- async function down$22(db) {
4826
+ async function down$29(db) {
4827
4827
  await db.schema.dropTable("restaurant_priority_alert_deliveries").execute();
4828
4828
  await db.schema.dropTable("restaurant_priority_alert_opportunities").execute();
4829
4829
  await db.schema.dropTable("restaurant_priority_alerts").execute();
@@ -4864,7 +4864,7 @@ async function createPriorityAlertOpportunities(db) {
4864
4864
  async function createPriorityAlertDeliveries(db) {
4865
4865
  await db.schema.createTable("restaurant_priority_alert_deliveries").addColumn("id", "text", (col) => col.primaryKey()).addColumn("opportunity_id", "text", (col) => col.notNull().references("restaurant_priority_alert_opportunities.id").onDelete("cascade")).addColumn("alert_id", "text", (col) => col.notNull().references("restaurant_priority_alerts.id").onDelete("cascade")).addColumn("batch_number", "integer", (col) => col.notNull().check(sql`batch_number >= 1`)).addColumn("channel", "text", (col) => col.notNull().check(sql`channel in ('email', 'sms', 'whatsapp')`)).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('scheduled', 'processing', 'sent', 'failed', 'opened', 'converted', 'suppressed', 'expired')`).defaultTo("scheduled")).addColumn("token_id", "text", (col) => col.notNull().unique()).addColumn("token_hash", "text", (col) => col.notNull().unique()).addColumn("available_at", "text", (col) => col.notNull()).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("attempt_count", "integer", (col) => col.notNull().check(sql`attempt_count >= 0`).defaultTo(0)).addColumn("last_error_code", "text").addColumn("sent_at", "text").addColumn("opened_at", "text").addColumn("converted_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_priority_alert_deliveries_opportunity_alert", ["opportunity_id", "alert_id"]).execute();
4866
4866
  }
4867
- async function createIndexes$1(db) {
4867
+ async function createIndexes$4(db) {
4868
4868
  await db.schema.createIndex("idx_restaurant_reservation_requests_location_status_created").on("restaurant_reservation_requests").columns([
4869
4869
  "location_id",
4870
4870
  "status",
@@ -4912,10 +4912,10 @@ async function createIndexes$1(db) {
4912
4912
  //#endregion
4913
4913
  //#region src/database/migrations/085_restaurant_reservation_offers.ts
4914
4914
  var _085_restaurant_reservation_offers_exports = /* @__PURE__ */ __exportAll({
4915
- down: () => down$21,
4916
- up: () => up$21
4915
+ down: () => down$28,
4916
+ up: () => up$28
4917
4917
  });
4918
- async function up$21(db) {
4918
+ async function up$28(db) {
4919
4919
  await db.schema.createTable("restaurant_reservation_offers").addColumn("id", "text", (col) => col.primaryKey()).addColumn("source_reservation_id", "text", (col) => col.notNull().unique().references("restaurant_reservations.id").onDelete("restrict")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("zone_id", "text", (col) => col.references("restaurant_zones.id").onDelete("set null")).addColumn("hold_id", "text", (col) => col.notNull().unique().references("restaurant_reservation_holds.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("token_id", "text", (col) => col.notNull().unique()).addColumn("token_hash", "text", (col) => col.notNull().unique()).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("service_date", "text", (col) => col.notNull().check(sql`length(service_date) = 10`)).addColumn("starts_at", "text", (col) => col.notNull()).addColumn("ends_at", "text", (col) => col.notNull()).addColumn("duration_minutes", "integer", (col) => col.notNull().check(sql`duration_minutes between 30 and 240`)).addColumn("party_size", "integer", (col) => col.notNull().check(sql`party_size between 1 and 1000`)).addColumn("message", "text").addColumn("payment_mode", "text", (col) => col.notNull().check(sql`payment_mode in ('none', 'charge')`).defaultTo("none")).addColumn("amount_minor", "integer", (col) => col.check(sql`amount_minor is null or amount_minor > 0`)).addColumn("currency", "text", (col) => col.check(sql`currency is null or length(currency) = 3`)).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('pending', 'accepted', 'declined', 'expired')`).defaultTo("pending")).addColumn("accepted_reservation_id", "text", (col) => col.references("restaurant_reservations.id").onDelete("restrict")).addColumn("offered_by_actor_type", "text", (col) => col.notNull().check(sql`offered_by_actor_type in ('user', 'api_token', 'system')`)).addColumn("offered_by_actor_id", "text").addColumn("accepted_at", "text").addColumn("declined_at", "text").addColumn("expired_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_reservation_offers_time", sql`ends_at > starts_at`).addCheckConstraint("ck_restaurant_reservation_offers_payment", sql`(payment_mode = 'none' and amount_minor is null and currency is null)
4920
4920
  or (payment_mode = 'charge' and amount_minor is not null and currency is not null)`).addCheckConstraint("ck_restaurant_reservation_offers_state", sql`(
4921
4921
  (status = 'pending' and accepted_reservation_id is null and accepted_at is null and declined_at is null and expired_at is null)
@@ -4929,17 +4929,17 @@ async function up$21(db) {
4929
4929
  await db.schema.createIndex("idx_restaurant_reservation_offers_status_expires").on("restaurant_reservation_offers").columns(["status", "expires_at"]).execute();
4930
4930
  await db.schema.createIndex("idx_restaurant_reservation_offers_created_at").on("restaurant_reservation_offers").column("created_at").execute();
4931
4931
  }
4932
- async function down$21(db) {
4932
+ async function down$28(db) {
4933
4933
  await db.schema.dropTable("restaurant_reservation_offers").execute();
4934
4934
  }
4935
4935
 
4936
4936
  //#endregion
4937
4937
  //#region src/database/migrations/086_restaurant_reservation_payment_policies.ts
4938
4938
  var _086_restaurant_reservation_payment_policies_exports = /* @__PURE__ */ __exportAll({
4939
- down: () => down$20,
4940
- up: () => up$20
4939
+ down: () => down$27,
4940
+ up: () => up$27
4941
4941
  });
4942
- async function up$20(db) {
4942
+ async function up$27(db) {
4943
4943
  await db.schema.createTable("restaurant_reservation_payment_policies").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("name", "text", (col) => col.notNull()).addColumn("scope_type", "text", (col) => col.notNull().check(sql`scope_type in ('venue_default', 'party_size', 'service_window', 'experience')`)).addColumn("experience_key", "text").addColumn("service_date", "text", (col) => col.check(sql`service_date is null or length(service_date) = 10`)).addColumn("starts_at_local", "text", (col) => col.check(sql`starts_at_local is null or length(starts_at_local) = 5`)).addColumn("ends_at_local", "text", (col) => col.check(sql`ends_at_local is null or length(ends_at_local) = 5`)).addColumn("min_party_size", "integer", (col) => col.check(sql`min_party_size is null or min_party_size between 1 and 1000`)).addColumn("max_party_size", "integer", (col) => col.check(sql`max_party_size is null or max_party_size between 1 and 1000`)).addColumn("collection_mode", "text", (col) => col.notNull().check(sql`collection_mode in ('none', 'charge', 'authorize')`).defaultTo("none")).addColumn("amount_basis", "text", (col) => col.notNull().check(sql`amount_basis in ('none', 'fixed', 'per_guest', 'quote_percentage', 'quote_total')`).defaultTo("none")).addColumn("amount_value", "integer").addColumn("currency", "text", (col) => col.check(sql`currency is null or length(currency) = 3`)).addColumn("cancellation_window_minutes", "integer", (col) => col.notNull().check(sql`cancellation_window_minutes >= 0`).defaultTo(1440)).addColumn("cancellation_fee_basis", "text", (col) => col.notNull().check(sql`cancellation_fee_basis in ('none', 'fixed', 'percentage', 'full')`).defaultTo("none")).addColumn("cancellation_fee_value", "integer").addColumn("cancellation_fee_currency", "text", (col) => col.check(sql`cancellation_fee_currency is null or length(cancellation_fee_currency) = 3`)).addColumn("modification_requires_review", "integer", (col) => col.notNull().check(sql`modification_requires_review in (0, 1)`).defaultTo(1)).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'inactive')`).defaultTo("active")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_reservation_payment_policies_scope", sql`(
4944
4944
  (scope_type = 'venue_default' and experience_key is null and service_date is null and starts_at_local is null and ends_at_local is null and min_party_size is null and max_party_size is null)
4945
4945
  or (scope_type = 'experience' and experience_key is not null and service_date is null and starts_at_local is null and ends_at_local is null and min_party_size is null and max_party_size is null)
@@ -4976,17 +4976,17 @@ async function up$20(db) {
4976
4976
  ]).execute();
4977
4977
  await db.schema.createIndex("idx_restaurant_reservation_payment_policies_created_at").on("restaurant_reservation_payment_policies").column("created_at").execute();
4978
4978
  }
4979
- async function down$20(db) {
4979
+ async function down$27(db) {
4980
4980
  await db.schema.dropTable("restaurant_reservation_payment_policies").execute();
4981
4981
  }
4982
4982
 
4983
4983
  //#endregion
4984
4984
  //#region src/database/migrations/087_restaurant_reservation_commercial_catalog.ts
4985
4985
  var _087_restaurant_reservation_commercial_catalog_exports = /* @__PURE__ */ __exportAll({
4986
- down: () => down$19,
4987
- up: () => up$19
4986
+ down: () => down$26,
4987
+ up: () => up$26
4988
4988
  });
4989
- async function up$19(db) {
4989
+ async function up$26(db) {
4990
4990
  await db.schema.createTable("restaurant_reservation_experiences").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("experience_key", "text", (col) => col.notNull()).addColumn("name", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("booking_mode", "text", (col) => col.notNull().check(sql`booking_mode in ('direct', 'request')`)).addColumn("price_basis", "text", (col) => col.notNull().check(sql`price_basis in ('none', 'fixed', 'per_guest', 'minimum_spend')`)).addColumn("price_minor", "integer").addColumn("currency", "text", (col) => col.check(sql`currency is null or length(currency) = 3`)).addColumn("duration_minutes", "integer", (col) => col.check(sql`duration_minutes is null or duration_minutes between 30 and 480`)).addColumn("min_party_size", "integer", (col) => col.notNull().check(sql`min_party_size between 1 and 1000`)).addColumn("max_party_size", "integer", (col) => col.notNull().check(sql`max_party_size between 1 and 1000`)).addColumn("max_bookings_per_slot", "integer", (col) => col.check(sql`max_bookings_per_slot is null or max_bookings_per_slot > 0`)).addColumn("max_covers_per_slot", "integer", (col) => col.check(sql`max_covers_per_slot is null or max_covers_per_slot > 0`)).addColumn("sales_start_at", "text").addColumn("sales_end_at", "text").addColumn("image_media_id", "text", (col) => col.references("media.id").onDelete("set null")).addColumn("image_alt_text", "text").addColumn("terms_text", "text").addColumn("status", "text", (col) => col.notNull().check(sql`status in ('draft', 'active', 'archived')`).defaultTo("draft")).addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_experiences_location_key", ["location_id", "experience_key"]).addCheckConstraint("ck_restaurant_reservation_experiences_price", sql`(price_basis = 'none' and price_minor is null and currency is null)
4991
4991
  or (price_basis in ('fixed', 'per_guest', 'minimum_spend') and price_minor is not null and price_minor > 0 and currency is not null)`).addCheckConstraint("ck_restaurant_reservation_experiences_party_size", sql`min_party_size <= max_party_size`).addCheckConstraint("ck_restaurant_reservation_experiences_sales_window", sql`sales_start_at is null or sales_end_at is null or sales_end_at > sales_start_at`).execute();
4992
4992
  await db.schema.createTable("restaurant_reservation_addon_categories").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("category_key", "text", (col) => col.notNull()).addColumn("name", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("available_for_standard", "integer", (col) => col.notNull().check(sql`available_for_standard in (0, 1)`).defaultTo(0)).addColumn("min_quantity", "integer", (col) => col.notNull().check(sql`min_quantity >= 0`).defaultTo(0)).addColumn("max_quantity", "integer", (col) => col.check(sql`max_quantity is null or max_quantity >= 0`)).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'inactive', 'archived')`).defaultTo("active")).addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_addon_categories_location_key", ["location_id", "category_key"]).addCheckConstraint("ck_restaurant_reservation_addon_categories_quantity", sql`max_quantity is null or min_quantity <= max_quantity`).execute();
@@ -5069,7 +5069,7 @@ async function up$19(db) {
5069
5069
  ]
5070
5070
  ]) await db.schema.createIndex(name).on(table).columns([...columns]).execute();
5071
5071
  }
5072
- async function down$19(db) {
5072
+ async function down$26(db) {
5073
5073
  await db.schema.dropTable("restaurant_reservation_experience_included_addons").execute();
5074
5074
  await db.schema.dropTable("restaurant_reservation_experience_addon_categories").execute();
5075
5075
  await db.schema.dropTable("restaurant_reservation_addons").execute();
@@ -5080,10 +5080,10 @@ async function down$19(db) {
5080
5080
  //#endregion
5081
5081
  //#region src/database/migrations/088_restaurant_reservation_hold_commercial_allocations.ts
5082
5082
  var _088_restaurant_reservation_hold_commercial_allocations_exports = /* @__PURE__ */ __exportAll({
5083
- down: () => down$18,
5084
- up: () => up$18
5083
+ down: () => down$25,
5084
+ up: () => up$25
5085
5085
  });
5086
- async function up$18(db) {
5086
+ async function up$25(db) {
5087
5087
  await db.schema.createTable("restaurant_reservation_hold_commercial_selections").addColumn("id", "text", (col) => col.primaryKey()).addColumn("hold_id", "text", (col) => col.notNull().unique().references("restaurant_reservation_holds.id").onDelete("cascade")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("experience_id", "text", (col) => col.references("restaurant_reservation_experiences.id").onDelete("restrict")).addColumn("experience_version", "integer").addColumn("revision", "integer", (col) => col.notNull().defaultTo(0)).addColumn("acknowledged_revision", "integer").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_reservation_hold_commercial_experience", sql`(experience_id is null and experience_version is null)
5088
5088
  or (experience_id is not null and experience_version is not null and experience_version > 0)`).addCheckConstraint("ck_restaurant_reservation_hold_commercial_revision", sql`revision >= 0 and (acknowledged_revision is null or acknowledged_revision between 0 and revision)`).execute();
5089
5089
  await db.schema.createTable("restaurant_reservation_hold_addons").addColumn("id", "text", (col) => col.primaryKey()).addColumn("selection_id", "text", (col) => col.notNull().references("restaurant_reservation_hold_commercial_selections.id").onDelete("cascade")).addColumn("hold_id", "text", (col) => col.notNull().references("restaurant_reservation_holds.id").onDelete("cascade")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("category_id", "text", (col) => col.notNull().references("restaurant_reservation_addon_categories.id").onDelete("restrict")).addColumn("addon_id", "text", (col) => col.notNull().references("restaurant_reservation_addons.id").onDelete("restrict")).addColumn("addon_version", "integer", (col) => col.notNull().check(sql`addon_version > 0`)).addColumn("allocation_kind", "text", (col) => col.notNull().check(sql`allocation_kind in ('included', 'selected')`)).addColumn("requested_quantity", "integer", (col) => col.notNull().check(sql`requested_quantity >= 0`)).addColumn("allocated_quantity", "integer", (col) => col.notNull().check(sql`allocated_quantity >= 0`)).addColumn("service_date", "text", (col) => col.notNull().check(sql`length(service_date) = 10`)).addColumn("starts_at", "text", (col) => col.notNull()).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'committed', 'released', 'expired')`).defaultTo("active")).addColumn("released_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_hold_addon_kind", [
@@ -5147,7 +5147,7 @@ async function up$18(db) {
5147
5147
  ]
5148
5148
  ]) await db.schema.createIndex(name).on(table).columns([...columns]).execute();
5149
5149
  }
5150
- async function down$18(db) {
5150
+ async function down$25(db) {
5151
5151
  await db.schema.dropTable("restaurant_reservation_hold_addon_operations").execute();
5152
5152
  await db.schema.dropTable("restaurant_reservation_hold_addons").execute();
5153
5153
  await db.schema.dropTable("restaurant_reservation_hold_commercial_selections").execute();
@@ -5156,10 +5156,10 @@ async function down$18(db) {
5156
5156
  //#endregion
5157
5157
  //#region src/database/migrations/089_restaurant_reservation_quotes.ts
5158
5158
  var _089_restaurant_reservation_quotes_exports = /* @__PURE__ */ __exportAll({
5159
- down: () => down$17,
5160
- up: () => up$17
5159
+ down: () => down$24,
5160
+ up: () => up$24
5161
5161
  });
5162
- async function up$17(db) {
5162
+ async function up$24(db) {
5163
5163
  await db.schema.createTable("restaurant_reservation_quotes").addColumn("id", "text", (col) => col.primaryKey()).addColumn("hold_id", "text", (col) => col.notNull().references("restaurant_reservation_holds.id").onDelete("restrict")).addColumn("selection_id", "text", (col) => col.notNull().references("restaurant_reservation_hold_commercial_selections.id").onDelete("restrict")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("payment_policy_id", "text", (col) => col.notNull().references("restaurant_reservation_payment_policies.id").onDelete("restrict")).addColumn("payment_policy_version", "integer", (col) => col.notNull().check(sql`payment_policy_version > 0`)).addColumn("experience_id", "text", (col) => col.references("restaurant_reservation_experiences.id").onDelete("restrict")).addColumn("experience_version", "integer").addColumn("selection_revision", "integer", (col) => col.notNull().check(sql`selection_revision >= 0`)).addColumn("collection_mode", "text", (col) => col.notNull().check(sql`collection_mode in ('none', 'charge', 'authorize')`)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("subtotal_minor", "integer", (col) => col.notNull().check(sql`subtotal_minor >= 0`)).addColumn("discount_minor", "integer", (col) => col.notNull().check(sql`discount_minor >= 0 and discount_minor <= subtotal_minor`)).addColumn("fee_minor", "integer", (col) => col.notNull().check(sql`fee_minor >= 0`)).addColumn("tax_minor", "integer", (col) => col.notNull().check(sql`tax_minor >= 0`)).addColumn("gratuity_minor", "integer", (col) => col.notNull().check(sql`gratuity_minor >= 0`)).addColumn("total_minor", "integer", (col) => col.notNull().check(sql`total_minor >= 0`)).addColumn("due_now_minor", "integer", (col) => col.notNull().check(sql`due_now_minor >= 0`)).addColumn("authorization_minor", "integer", (col) => col.notNull().check(sql`authorization_minor >= 0`)).addColumn("pricing_hash", "text", (col) => col.notNull().check(sql`length(pricing_hash) = 71 and pricing_hash like 'sha256:%'`)).addColumn("snapshot_json", "text", (col) => col.notNull()).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_quotes_selection_revision", ["selection_id", "selection_revision"]).addCheckConstraint("ck_restaurant_reservation_quotes_experience", sql`(experience_id is null and experience_version is null)
5164
5164
  or (experience_id is not null and experience_version is not null and experience_version > 0)`).addCheckConstraint("ck_restaurant_reservation_quotes_total", sql`total_minor = subtotal_minor - discount_minor + fee_minor + tax_minor + gratuity_minor`).addCheckConstraint("ck_restaurant_reservation_quotes_collection", sql`(collection_mode = 'none' and due_now_minor = 0 and authorization_minor = 0)
5165
5165
  or (collection_mode = 'charge' and authorization_minor = 0)
@@ -5199,7 +5199,7 @@ async function up$17(db) {
5199
5199
  ]
5200
5200
  ]) await db.schema.createIndex(name).on(table).column(column).execute();
5201
5201
  }
5202
- async function down$17(db) {
5202
+ async function down$24(db) {
5203
5203
  await db.schema.dropTable("restaurant_reservation_quote_lines").execute();
5204
5204
  await db.schema.dropTable("restaurant_reservation_quotes").execute();
5205
5205
  }
@@ -5207,10 +5207,10 @@ async function down$17(db) {
5207
5207
  //#endregion
5208
5208
  //#region src/database/migrations/090_restaurant_reservation_quote_payments.ts
5209
5209
  var _090_restaurant_reservation_quote_payments_exports = /* @__PURE__ */ __exportAll({
5210
- down: () => down$16,
5211
- up: () => up$16
5210
+ down: () => down$23,
5211
+ up: () => up$23
5212
5212
  });
5213
- async function up$16(db) {
5213
+ async function up$23(db) {
5214
5214
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
5215
5215
  try {
5216
5216
  await sql`
@@ -5285,7 +5285,7 @@ async function up$16(db) {
5285
5285
  }
5286
5286
  await assertForeignKeys$5(db);
5287
5287
  }
5288
- async function down$16(db) {
5288
+ async function down$23(db) {
5289
5289
  await db.schema.dropTable("restaurant_reservation_quote_checkouts").execute();
5290
5290
  await sql`
5291
5291
  DELETE FROM restaurant_refunds
@@ -5396,10 +5396,10 @@ async function assertForeignKeys$5(db) {
5396
5396
  //#endregion
5397
5397
  //#region src/database/migrations/091_restaurant_reservation_refunds.ts
5398
5398
  var _091_restaurant_reservation_refunds_exports = /* @__PURE__ */ __exportAll({
5399
- down: () => down$15,
5400
- up: () => up$15
5399
+ down: () => down$22,
5400
+ up: () => up$22
5401
5401
  });
5402
- async function up$15(db) {
5402
+ async function up$22(db) {
5403
5403
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
5404
5404
  try {
5405
5405
  await sql`
@@ -5464,7 +5464,7 @@ async function up$15(db) {
5464
5464
  }
5465
5465
  await assertForeignKeys$4(db);
5466
5466
  }
5467
- async function down$15(db) {
5467
+ async function down$22(db) {
5468
5468
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
5469
5469
  try {
5470
5470
  await sql`
@@ -5548,10 +5548,10 @@ async function assertForeignKeys$4(db) {
5548
5548
  //#endregion
5549
5549
  //#region src/database/migrations/092_restaurant_guest_profiles.ts
5550
5550
  var _092_restaurant_guest_profiles_exports = /* @__PURE__ */ __exportAll({
5551
- down: () => down$14,
5552
- up: () => up$14
5551
+ down: () => down$21,
5552
+ up: () => up$21
5553
5553
  });
5554
- async function up$14(db) {
5554
+ async function up$21(db) {
5555
5555
  await db.schema.createTable("restaurant_guest_profiles").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("created_request_key", "text", (col) => col.notNull().unique()).addColumn("claimed_user_id", "text", (col) => col.references("users.id").onDelete("set null")).addColumn("display_name", "text", (col) => col.notNull().check(sql`length(display_name) between 1 and 160`)).addColumn("normalized_email", "text").addColumn("normalized_phone", "text").addColumn("preferred_language", "text", (col) => col.notNull().check(sql`length(preferred_language) between 2 and 35`).defaultTo("en")).addColumn("preferred_channel", "text", (col) => col.check(sql`preferred_channel in ('email', 'sms', 'whatsapp')`)).addColumn("priority_tier", "integer", (col) => col.notNull().check(sql`priority_tier between 0 and 100`).defaultTo(0)).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'merged', 'anonymized')`).defaultTo("active")).addColumn("merged_into_id", "text", (col) => col.references("restaurant_guest_profiles.id").onDelete("restrict")).addColumn("last_activity_at", "text", (col) => col.notNull()).addColumn("anonymized_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_guest_profiles_identity", sql`(status = 'active' and (normalized_email is not null or normalized_phone is not null) and merged_into_id is null and anonymized_at is null) or (status = 'merged' and merged_into_id is not null and anonymized_at is null) or (status = 'anonymized' and normalized_email is null and normalized_phone is null and merged_into_id is null and anonymized_at is not null)`).addCheckConstraint("ck_restaurant_guest_profiles_distinct_merge", sql`merged_into_id is null or merged_into_id <> id`).execute();
5556
5556
  await db.schema.createTable("restaurant_guest_profile_requests").addColumn("request_key", "text", (col) => col.primaryKey()).addColumn("profile_id", "text", (col) => col.notNull().references("restaurant_guest_profiles.id").onDelete("cascade")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("input_fingerprint", "text", (col) => col.notNull().check(sql`length(input_fingerprint) = 64`)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
5557
5557
  await db.schema.createTable("restaurant_guest_profile_reservations").addColumn("id", "text", (col) => col.primaryKey()).addColumn("profile_id", "text", (col) => col.notNull().references("restaurant_guest_profiles.id").onDelete("cascade")).addColumn("reservation_id", "text", (col) => col.notNull().unique().references("restaurant_reservations.id").onDelete("cascade")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("match_source", "text", (col) => col.notNull().check(sql`match_source in ('contact', 'account', 'staff', 'import')`)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
@@ -5624,7 +5624,7 @@ async function up$14(db) {
5624
5624
  await sql`CREATE UNIQUE INDEX idx_restaurant_guest_profiles_active_phone ON restaurant_guest_profiles(location_id, normalized_phone) WHERE status = 'active' AND normalized_phone IS NOT NULL`.execute(db);
5625
5625
  await sql`CREATE UNIQUE INDEX idx_restaurant_guest_profiles_claimed_user_location ON restaurant_guest_profiles(location_id, claimed_user_id) WHERE status = 'active' AND claimed_user_id IS NOT NULL`.execute(db);
5626
5626
  }
5627
- async function down$14(db) {
5627
+ async function down$21(db) {
5628
5628
  await db.schema.dropTable("restaurant_guest_consents").execute();
5629
5629
  await db.schema.dropTable("restaurant_guest_profile_reservations").execute();
5630
5630
  await db.schema.dropTable("restaurant_guest_profile_requests").execute();
@@ -5634,24 +5634,24 @@ async function down$14(db) {
5634
5634
  //#endregion
5635
5635
  //#region src/database/migrations/093_restaurant_guest_profile_retention.ts
5636
5636
  var _093_restaurant_guest_profile_retention_exports = /* @__PURE__ */ __exportAll({
5637
- down: () => down$13,
5638
- up: () => up$13
5637
+ down: () => down$20,
5638
+ up: () => up$20
5639
5639
  });
5640
- async function up$13(db) {
5640
+ async function up$20(db) {
5641
5641
  await db.schema.createTable("restaurant_guest_profile_retention_settings").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("inactivity_months", "integer", (col) => col.notNull().check(sql`inactivity_months between 1 and 120`).defaultTo(24)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
5642
5642
  await db.schema.createIndex("idx_restaurant_guest_profile_retention_location_id").unique().on("restaurant_guest_profile_retention_settings").column("location_id").execute();
5643
5643
  }
5644
- async function down$13(db) {
5644
+ async function down$20(db) {
5645
5645
  await db.schema.dropTable("restaurant_guest_profile_retention_settings").execute();
5646
5646
  }
5647
5647
 
5648
5648
  //#endregion
5649
5649
  //#region src/database/migrations/094_restaurant_guest_profile_sharing.ts
5650
5650
  var _094_restaurant_guest_profile_sharing_exports = /* @__PURE__ */ __exportAll({
5651
- down: () => down$12,
5652
- up: () => up$12
5651
+ down: () => down$19,
5652
+ up: () => up$19
5653
5653
  });
5654
- async function up$12(db) {
5654
+ async function up$19(db) {
5655
5655
  await db.schema.createTable("restaurant_related_location_pairs").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_a_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("location_b_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'inactive')`)).addColumn("policy_version", "text", (col) => col.notNull().check(sql`length(policy_version) between 1 and 128`)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_related_location_pairs_locations", ["location_a_id", "location_b_id"]).addCheckConstraint("ck_restaurant_related_location_pairs_canonical", sql`location_a_id < location_b_id`).execute();
5656
5656
  await db.schema.createTable("restaurant_guest_profile_sharing_consents").addColumn("id", "text", (col) => col.primaryKey()).addColumn("pair_id", "text", (col) => col.notNull().references("restaurant_related_location_pairs.id").onDelete("restrict")).addColumn("profile_id", "text", (col) => col.notNull().references("restaurant_guest_profiles.id").onDelete("cascade")).addColumn("source_location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("target_location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('granted', 'withdrawn')`)).addColumn("source", "text", (col) => col.notNull().check(sql`source in ('checkout', 'account')`)).addColumn("policy_version", "text", (col) => col.notNull().check(sql`length(policy_version) between 1 and 128`)).addColumn("occurred_at", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_guest_profile_sharing_distinct_locations", sql`source_location_id <> target_location_id`).execute();
5657
5657
  for (const [name, table, columns] of [
@@ -5697,7 +5697,7 @@ async function up$12(db) {
5697
5697
  ]
5698
5698
  ]) await db.schema.createIndex(name).on(table).columns([...columns]).execute();
5699
5699
  }
5700
- async function down$12(db) {
5700
+ async function down$19(db) {
5701
5701
  await db.schema.dropTable("restaurant_guest_profile_sharing_consents").execute();
5702
5702
  await db.schema.dropTable("restaurant_related_location_pairs").execute();
5703
5703
  }
@@ -5705,10 +5705,10 @@ async function down$12(db) {
5705
5705
  //#endregion
5706
5706
  //#region src/database/migrations/095_restaurant_priority_alert_notification_recovery.ts
5707
5707
  var _095_restaurant_priority_alert_notification_recovery_exports = /* @__PURE__ */ __exportAll({
5708
- down: () => down$11,
5709
- up: () => up$11
5708
+ down: () => down$18,
5709
+ up: () => up$18
5710
5710
  });
5711
- async function up$11(db) {
5711
+ async function up$18(db) {
5712
5712
  await db.schema.alterTable("restaurant_priority_alerts").addColumn("preferred_language", "text", (col) => col.notNull().defaultTo("en").check(sql`length(preferred_language) between 2 and 35`)).execute();
5713
5713
  await db.schema.alterTable("restaurant_priority_alert_deliveries").addColumn("channel_attempt_count", "integer", (col) => col.notNull().defaultTo(0).check(sql`channel_attempt_count >= 0`)).execute();
5714
5714
  await db.schema.alterTable("restaurant_priority_alert_deliveries").addColumn("fallback_count", "integer", (col) => col.notNull().defaultTo(0).check(sql`fallback_count >= 0`)).execute();
@@ -5718,7 +5718,7 @@ async function up$11(db) {
5718
5718
  "id"
5719
5719
  ]).execute();
5720
5720
  }
5721
- async function down$11(db) {
5721
+ async function down$18(db) {
5722
5722
  await db.schema.dropIndex("idx_restaurant_priority_alert_deliveries_failure_queue").execute();
5723
5723
  await db.schema.alterTable("restaurant_priority_alert_deliveries").dropColumn("fallback_count").execute();
5724
5724
  await db.schema.alterTable("restaurant_priority_alert_deliveries").dropColumn("channel_attempt_count").execute();
@@ -5731,8 +5731,8 @@ var _096_restaurant_reservation_notification_preferences_exports = /* @__PURE__
5731
5731
  addRestaurantReservationNotificationPreferenceColumns: () => addRestaurantReservationNotificationPreferenceColumns,
5732
5732
  addRestaurantReservationQuoteCheckoutNotificationPreferenceColumns: () => addRestaurantReservationQuoteCheckoutNotificationPreferenceColumns,
5733
5733
  addRestaurantReservationRequestNotificationPreferenceColumns: () => addRestaurantReservationRequestNotificationPreferenceColumns,
5734
- down: () => down$10,
5735
- up: () => up$10
5734
+ down: () => down$17,
5735
+ up: () => up$17
5736
5736
  });
5737
5737
  async function addRestaurantReservationNotificationPreferenceColumns(db) {
5738
5738
  await addNotificationPreferenceColumns(db, "restaurant_reservations");
@@ -5743,12 +5743,12 @@ async function addRestaurantReservationRequestNotificationPreferenceColumns(db)
5743
5743
  async function addRestaurantReservationQuoteCheckoutNotificationPreferenceColumns(db) {
5744
5744
  await addNotificationPreferenceColumns(db, "restaurant_reservation_quote_checkouts");
5745
5745
  }
5746
- async function up$10(db) {
5746
+ async function up$17(db) {
5747
5747
  await addRestaurantReservationNotificationPreferenceColumns(db);
5748
5748
  await addRestaurantReservationRequestNotificationPreferenceColumns(db);
5749
5749
  await addRestaurantReservationQuoteCheckoutNotificationPreferenceColumns(db);
5750
5750
  }
5751
- async function down$10(db) {
5751
+ async function down$17(db) {
5752
5752
  await dropNotificationPreferenceColumns(db, "restaurant_reservation_quote_checkouts");
5753
5753
  await dropNotificationPreferenceColumns(db, "restaurant_reservation_requests");
5754
5754
  await dropNotificationPreferenceColumns(db, "restaurant_reservations");
@@ -5767,12 +5767,12 @@ async function dropNotificationPreferenceColumns(db, table) {
5767
5767
  //#endregion
5768
5768
  //#region src/database/migrations/097_restaurant_guest_notification_recovery.ts
5769
5769
  var _097_restaurant_guest_notification_recovery_exports = /* @__PURE__ */ __exportAll({
5770
- down: () => down$9,
5771
- up: () => up$9
5770
+ down: () => down$16,
5771
+ up: () => up$16
5772
5772
  });
5773
5773
  const REBUILT_TABLE = "_restaurant_outbox_deliveries_097";
5774
5774
  const DOWN_TABLE$3 = "_restaurant_outbox_deliveries_097_down";
5775
- async function up$9(db) {
5775
+ async function up$16(db) {
5776
5776
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
5777
5777
  try {
5778
5778
  await createRecoverableDeliveryTable(db, REBUILT_TABLE);
@@ -5796,7 +5796,7 @@ async function up$9(db) {
5796
5796
  }
5797
5797
  await assertForeignKeys$3(db);
5798
5798
  }
5799
- async function down$9(db) {
5799
+ async function down$16(db) {
5800
5800
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
5801
5801
  try {
5802
5802
  await createLegacyDeliveryTable(db, DOWN_TABLE$3);
@@ -5848,12 +5848,12 @@ async function assertForeignKeys$3(db) {
5848
5848
  //#endregion
5849
5849
  //#region src/database/migrations/098_restaurant_private_event_requests.ts
5850
5850
  var _098_restaurant_private_event_requests_exports = /* @__PURE__ */ __exportAll({
5851
- down: () => down$8,
5852
- up: () => up$8
5851
+ down: () => down$15,
5852
+ up: () => up$15
5853
5853
  });
5854
5854
  const UP_TABLE$2 = "_restaurant_reservation_requests_098";
5855
5855
  const DOWN_TABLE$2 = "_restaurant_reservation_requests_098_down";
5856
- async function up$8(db) {
5856
+ async function up$15(db) {
5857
5857
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
5858
5858
  try {
5859
5859
  await createExperienceRequestTable(db);
@@ -5890,7 +5890,7 @@ async function up$8(db) {
5890
5890
  }
5891
5891
  await assertForeignKeys$2(db);
5892
5892
  }
5893
- async function down$8(db) {
5893
+ async function down$15(db) {
5894
5894
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
5895
5895
  try {
5896
5896
  await createLegacyRequestTable(db);
@@ -6077,10 +6077,10 @@ async function assertForeignKeys$2(db) {
6077
6077
  //#endregion
6078
6078
  //#region src/database/migrations/099_restaurant_reservation_promotions.ts
6079
6079
  var _099_restaurant_reservation_promotions_exports = /* @__PURE__ */ __exportAll({
6080
- down: () => down$7,
6081
- up: () => up$7
6080
+ down: () => down$14,
6081
+ up: () => up$14
6082
6082
  });
6083
- async function up$7(db) {
6083
+ async function up$14(db) {
6084
6084
  await db.schema.createTable("restaurant_reservation_promotions").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("code_digest", "text", (col) => col.notNull().check(sql`length(code_digest) = 71 and code_digest like 'sha256:%'`)).addColumn("code_hint", "text", (col) => col.notNull().check(sql`length(code_hint) between 1 and 8`)).addColumn("name", "text", (col) => col.notNull().check(sql`length(name) between 1 and 160`)).addColumn("discount_type", "text", (col) => col.notNull().check(sql`discount_type in ('fixed', 'percentage')`)).addColumn("discount_value", "integer", (col) => col.notNull().check(sql`discount_value > 0`)).addColumn("max_discount_minor", "integer", (col) => col.check(sql`max_discount_minor is null or max_discount_minor > 0`)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("applies_to", "text", (col) => col.notNull().check(sql`applies_to in ('all', 'experience', 'addons')`)).addColumn("service_starts_at", "text").addColumn("service_ends_at", "text").addColumn("max_redemptions", "integer", (col) => col.check(sql`max_redemptions is null or max_redemptions > 0`)).addColumn("reserved_count", "integer", (col) => col.notNull().defaultTo(0).check(sql`reserved_count >= 0`)).addColumn("redeemed_count", "integer", (col) => col.notNull().defaultTo(0).check(sql`redeemed_count >= 0`)).addColumn("status", "text", (col) => col.notNull().defaultTo("active").check(sql`status in ('active', 'archived')`)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_promotions_location_code", ["location_id", "code_digest"]).addCheckConstraint("ck_restaurant_reservation_promotions_discount", sql`(discount_type = 'fixed' and max_discount_minor is null)
6085
6085
  or (discount_type = 'percentage' and discount_value between 1 and 10000)`).addCheckConstraint("ck_restaurant_reservation_promotions_window", sql`service_starts_at is null or service_ends_at is null or service_ends_at > service_starts_at`).addCheckConstraint("ck_restaurant_reservation_promotions_counts", sql`max_redemptions is null or reserved_count + redeemed_count <= max_redemptions`).execute();
6086
6086
  await db.schema.createTable("restaurant_reservation_promotion_allocations").addColumn("id", "text", (col) => col.primaryKey()).addColumn("promotion_id", "text", (col) => col.notNull().references("restaurant_reservation_promotions.id").onDelete("restrict")).addColumn("promotion_version", "integer", (col) => col.notNull().check(sql`promotion_version > 0`)).addColumn("selection_id", "text", (col) => col.notNull().references("restaurant_reservation_hold_commercial_selections.id").onDelete("restrict")).addColumn("hold_id", "text", (col) => col.notNull().references("restaurant_reservation_holds.id").onDelete("restrict")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("reservation_id", "text", (col) => col.references("restaurant_reservations.id").onDelete("restrict")).addColumn("promotion_name", "text", (col) => col.notNull().check(sql`length(promotion_name) between 1 and 160`)).addColumn("code_hint", "text", (col) => col.notNull().check(sql`length(code_hint) between 1 and 8`)).addColumn("discount_type", "text", (col) => col.notNull().check(sql`discount_type in ('fixed', 'percentage')`)).addColumn("discount_value", "integer", (col) => col.notNull().check(sql`discount_value > 0`)).addColumn("max_discount_minor", "integer", (col) => col.check(sql`max_discount_minor is null or max_discount_minor > 0`)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("applies_to", "text", (col) => col.notNull().check(sql`applies_to in ('all', 'experience', 'addons')`)).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().defaultTo("held").check(sql`status in ('held', 'attached', 'redeemed', 'released')`)).addColumn("attached_at", "text").addColumn("redeemed_at", "text").addColumn("released_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_reservation_promotion_allocations_discount", sql`(discount_type = 'fixed' and max_discount_minor is null)
@@ -6142,7 +6142,7 @@ async function up$7(db) {
6142
6142
  WHERE status IN ('held', 'attached')
6143
6143
  `.execute(db);
6144
6144
  }
6145
- async function down$7(db) {
6145
+ async function down$14(db) {
6146
6146
  await db.schema.dropTable("restaurant_reservation_promotion_operations").execute();
6147
6147
  await db.schema.dropTable("restaurant_reservation_promotion_allocations").execute();
6148
6148
  await db.schema.dropTable("restaurant_reservation_promotions").execute();
@@ -6151,10 +6151,10 @@ async function down$7(db) {
6151
6151
  //#endregion
6152
6152
  //#region src/database/migrations/100_restaurant_reservation_gift_cards.ts
6153
6153
  var _100_restaurant_reservation_gift_cards_exports = /* @__PURE__ */ __exportAll({
6154
- down: () => down$6,
6155
- up: () => up$6
6154
+ down: () => down$13,
6155
+ up: () => up$13
6156
6156
  });
6157
- async function up$6(db) {
6157
+ async function up$13(db) {
6158
6158
  await db.schema.createTable("restaurant_gift_cards").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("request_hash", "text", (col) => col.notNull().check(sql`length(request_hash) = 64`)).addColumn("number_digest", "text", (col) => col.notNull().check(sql`length(number_digest) = 71 and number_digest like 'sha256:%'`)).addColumn("number_hint", "text", (col) => col.notNull().check(sql`length(number_hint) between 1 and 8`)).addColumn("pin_digest", "text", (col) => col.notNull().check(sql`length(pin_digest) = 71 and pin_digest like 'sha256:%'`)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("available_minor", "integer", (col) => col.notNull().defaultTo(0).check(sql`available_minor >= 0`)).addColumn("held_minor", "integer", (col) => col.notNull().defaultTo(0).check(sql`held_minor >= 0`)).addColumn("status", "text", (col) => col.notNull().defaultTo("active").check(sql`status in ('active', 'inactive')`)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1).check(sql`version > 0`)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_gift_cards_location_number", ["location_id", "number_digest"]).execute();
6159
6159
  await db.schema.createTable("restaurant_reservation_gift_card_allocations").addColumn("id", "text", (col) => col.primaryKey()).addColumn("gift_card_id", "text", (col) => col.notNull().references("restaurant_gift_cards.id").onDelete("restrict")).addColumn("gift_card_version", "integer", (col) => col.notNull().check(sql`gift_card_version > 0`)).addColumn("selection_id", "text", (col) => col.notNull().references("restaurant_reservation_hold_commercial_selections.id").onDelete("restrict")).addColumn("hold_id", "text", (col) => col.notNull().references("restaurant_reservation_holds.id").onDelete("restrict")).addColumn("location_id", "text", (col) => col.notNull().references("restaurant_locations.id").onDelete("restrict")).addColumn("reservation_id", "text", (col) => col.references("restaurant_reservations.id").onDelete("restrict")).addColumn("card_hint", "text", (col) => col.notNull().check(sql`length(card_hint) between 1 and 8`)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("amount_minor", "integer", (col) => col.notNull().check(sql`amount_minor > 0`)).addColumn("refunded_minor", "integer", (col) => col.notNull().defaultTo(0).check(sql`refunded_minor >= 0`)).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().defaultTo("held").check(sql`status in ('held', 'redeemed', 'released')`)).addColumn("redeemed_at", "text").addColumn("released_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1).check(sql`version > 0`)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_reservation_gift_card_allocations_refund", sql`refunded_minor <= amount_minor`).addCheckConstraint("ck_restaurant_reservation_gift_card_allocations_state", sql`(status = 'held' and reservation_id is null and redeemed_at is null and released_at is null and refunded_minor = 0)
6160
6160
  or (status = 'redeemed' and reservation_id is not null and redeemed_at is not null and released_at is null)
@@ -6233,7 +6233,7 @@ async function up$6(db) {
6233
6233
  WHERE status = 'held'
6234
6234
  `.execute(db);
6235
6235
  }
6236
- async function down$6(db) {
6236
+ async function down$13(db) {
6237
6237
  await db.schema.dropTable("restaurant_reservation_gift_card_operations").execute();
6238
6238
  await db.schema.dropTable("restaurant_gift_card_ledger_entries").execute();
6239
6239
  await db.schema.dropTable("restaurant_reservation_gift_card_allocations").execute();
@@ -6243,12 +6243,12 @@ async function down$6(db) {
6243
6243
  //#endregion
6244
6244
  //#region src/database/migrations/101_restaurant_reservation_request_payment_links.ts
6245
6245
  var _101_restaurant_reservation_request_payment_links_exports = /* @__PURE__ */ __exportAll({
6246
- down: () => down$5,
6247
- up: () => up$5
6246
+ down: () => down$12,
6247
+ up: () => up$12
6248
6248
  });
6249
6249
  const UP_TABLE$1 = "_restaurant_guest_access_101";
6250
6250
  const DOWN_TABLE$1 = "_restaurant_guest_access_101_down";
6251
- async function up$5(db) {
6251
+ async function up$12(db) {
6252
6252
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
6253
6253
  try {
6254
6254
  await createGuestAccessTable$1(db, UP_TABLE$1, true);
@@ -6262,7 +6262,7 @@ async function up$5(db) {
6262
6262
  }
6263
6263
  await assertForeignKeys$1(db);
6264
6264
  }
6265
- async function down$5(db) {
6265
+ async function down$12(db) {
6266
6266
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
6267
6267
  try {
6268
6268
  await db.schema.dropTable("restaurant_reservation_request_payment_link_deliveries").execute();
@@ -6325,12 +6325,12 @@ async function assertForeignKeys$1(db) {
6325
6325
  //#endregion
6326
6326
  //#region src/database/migrations/102_restaurant_reservation_offer_links.ts
6327
6327
  var _102_restaurant_reservation_offer_links_exports = /* @__PURE__ */ __exportAll({
6328
- down: () => down$4,
6329
- up: () => up$4
6328
+ down: () => down$11,
6329
+ up: () => up$11
6330
6330
  });
6331
6331
  const UP_TABLE = "_restaurant_guest_access_102";
6332
6332
  const DOWN_TABLE = "_restaurant_guest_access_102_down";
6333
- async function up$4(db) {
6333
+ async function up$11(db) {
6334
6334
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
6335
6335
  try {
6336
6336
  await createGuestAccessTable(db, UP_TABLE, true);
@@ -6349,7 +6349,7 @@ async function up$4(db) {
6349
6349
  }
6350
6350
  await assertForeignKeys(db);
6351
6351
  }
6352
- async function down$4(db) {
6352
+ async function down$11(db) {
6353
6353
  await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
6354
6354
  try {
6355
6355
  await db.schema.dropIndex("idx_restaurant_reservation_offers_location_created").execute();
@@ -6413,21 +6413,21 @@ async function assertForeignKeys(db) {
6413
6413
  //#endregion
6414
6414
  //#region src/database/migrations/103_restaurant_reservation_guest_details.ts
6415
6415
  var _103_restaurant_reservation_guest_details_exports = /* @__PURE__ */ __exportAll({
6416
- down: () => down$3,
6417
- up: () => up$3
6416
+ down: () => down$10,
6417
+ up: () => up$10
6418
6418
  });
6419
- async function up$3(db) {
6419
+ async function up$10(db) {
6420
6420
  await db.schema.createTable("restaurant_reservation_guest_settings").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("login_mode", "text", (column) => column.notNull().check(sql`login_mode in ('guest', 'optional', 'required')`).defaultTo("optional")).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
6421
6421
  await db.schema.createTable("restaurant_reservation_guest_fields").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("request_key", "text", (column) => column.notNull().unique()).addColumn("field_key", "text", (column) => column.notNull()).addColumn("label", "text", (column) => column.notNull()).addColumn("description", "text").addColumn("input_type", "text", (column) => column.notNull().check(sql`input_type in ('text', 'textarea', 'select', 'checkbox')`)).addColumn("required", "integer", (column) => column.notNull().check(sql`required in (0, 1)`).defaultTo(0)).addColumn("options_json", "text").addColumn("placeholder", "text").addColumn("max_length", "integer", (column) => column.check(sql`max_length is null or max_length between 1 and 2000`)).addColumn("sort_order", "integer", (column) => column.notNull().defaultTo(0)).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('active', 'inactive')`).defaultTo("active")).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_guest_fields_location_key", ["location_id", "field_key"]).execute();
6422
6422
  await db.schema.createTable("restaurant_reservation_guest_field_values").addColumn("id", "text", (column) => column.primaryKey()).addColumn("reservation_id", "text", (column) => column.notNull().references("restaurant_reservations.id").onDelete("cascade")).addColumn("field_id", "text", (column) => column.notNull().references("restaurant_reservation_guest_fields.id").onDelete("restrict")).addColumn("field_key", "text", (column) => column.notNull()).addColumn("field_label", "text", (column) => column.notNull()).addColumn("value_json", "text", (column) => column.notNull()).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_guest_field_values_reservation_field", ["reservation_id", "field_id"]).execute();
6423
- await createIndexes(db);
6423
+ await createIndexes$3(db);
6424
6424
  }
6425
- async function down$3(db) {
6425
+ async function down$10(db) {
6426
6426
  await db.schema.dropTable("restaurant_reservation_guest_field_values").execute();
6427
6427
  await db.schema.dropTable("restaurant_reservation_guest_fields").execute();
6428
6428
  await db.schema.dropTable("restaurant_reservation_guest_settings").execute();
6429
6429
  }
6430
- async function createIndexes(db) {
6430
+ async function createIndexes$3(db) {
6431
6431
  for (const [name, table, columns] of [
6432
6432
  [
6433
6433
  "idx_restaurant_reservation_guest_settings_location_id",
@@ -6460,10 +6460,10 @@ async function createIndexes(db) {
6460
6460
  //#endregion
6461
6461
  //#region src/database/migrations/104_restaurant_reservation_quote_guest_details.ts
6462
6462
  var _104_restaurant_reservation_quote_guest_details_exports = /* @__PURE__ */ __exportAll({
6463
- down: () => down$2,
6464
- up: () => up$2
6463
+ down: () => down$9,
6464
+ up: () => up$9
6465
6465
  });
6466
- async function up$2(db) {
6466
+ async function up$9(db) {
6467
6467
  await db.schema.createTable("restaurant_reservation_quote_guest_contexts").addColumn("quote_id", "text", (column) => column.primaryKey().references("restaurant_reservation_quotes.id").onDelete("cascade")).addColumn("location_id", "text", (column) => column.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("verified_user_id", "text", (column) => column.references("users.id").onDelete("set null")).addColumn("guest_profile_id", "text", (column) => column.notNull().references("restaurant_guest_profiles.id").onDelete("restrict")).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
6468
6468
  await db.schema.createTable("restaurant_reservation_quote_guest_field_values").addColumn("id", "text", (column) => column.primaryKey()).addColumn("quote_id", "text", (column) => column.notNull().references("restaurant_reservation_quotes.id").onDelete("cascade")).addColumn("field_id", "text", (column) => column.notNull().references("restaurant_reservation_guest_fields.id").onDelete("restrict")).addColumn("field_key", "text", (column) => column.notNull()).addColumn("field_label", "text", (column) => column.notNull()).addColumn("value_json", "text", (column) => column.notNull()).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_restaurant_reservation_quote_guest_field_values_quote_field", ["quote_id", "field_id"]).execute();
6469
6469
  for (const [name, table, columns] of [
@@ -6494,7 +6494,7 @@ async function up$2(db) {
6494
6494
  ]
6495
6495
  ]) await db.schema.createIndex(name).on(table).columns([...columns]).execute();
6496
6496
  }
6497
- async function down$2(db) {
6497
+ async function down$9(db) {
6498
6498
  await db.schema.dropTable("restaurant_reservation_quote_guest_field_values").execute();
6499
6499
  await db.schema.dropTable("restaurant_reservation_quote_guest_contexts").execute();
6500
6500
  }
@@ -6502,22 +6502,22 @@ async function down$2(db) {
6502
6502
  //#endregion
6503
6503
  //#region src/database/migrations/105_restaurant_reservation_language_settings.ts
6504
6504
  var _105_restaurant_reservation_language_settings_exports = /* @__PURE__ */ __exportAll({
6505
- down: () => down$1,
6506
- up: () => up$1
6505
+ down: () => down$8,
6506
+ up: () => up$8
6507
6507
  });
6508
- async function up$1(db) {
6508
+ async function up$8(db) {
6509
6509
  await db.schema.createTable("restaurant_reservation_language_settings").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("default_language", "text", (column) => column.notNull().defaultTo("en")).addColumn("enabled_languages_json", "text", (column) => column.notNull().defaultTo("[\"en\"]")).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
6510
6510
  await db.schema.createIndex("idx_restaurant_reservation_language_settings_location_id").on("restaurant_reservation_language_settings").column("location_id").execute();
6511
6511
  }
6512
- async function down$1(db) {
6512
+ async function down$8(db) {
6513
6513
  await db.schema.dropTable("restaurant_reservation_language_settings").execute();
6514
6514
  }
6515
6515
 
6516
6516
  //#endregion
6517
6517
  //#region src/database/migrations/106_restaurant_reservation_analytics.ts
6518
6518
  var _106_restaurant_reservation_analytics_exports = /* @__PURE__ */ __exportAll({
6519
- down: () => down,
6520
- up: () => up
6519
+ down: () => down$7,
6520
+ up: () => up$7
6521
6521
  });
6522
6522
  const EVENT_TYPE_CHECK = sql`event_type IN (
6523
6523
  'flow_viewed',
@@ -6531,7 +6531,7 @@ const EVENT_TYPE_CHECK = sql`event_type IN (
6531
6531
  'priority_alert_subscribed',
6532
6532
  'management_viewed'
6533
6533
  )`;
6534
- async function up(db) {
6534
+ async function up$7(db) {
6535
6535
  await db.schema.createTable("restaurant_reservation_analytics_settings").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().unique().references("restaurant_locations.id").onDelete("cascade")).addColumn("enabled", "integer", (column) => column.notNull().defaultTo(0)).addColumn("retention_days", "integer", (column) => column.notNull().defaultTo(90)).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_reservation_analytics_settings_enabled", sql`enabled IN (0, 1)`).addCheckConstraint("ck_restaurant_reservation_analytics_settings_retention_days", sql`retention_days BETWEEN 1 AND 365`).execute();
6536
6536
  await db.schema.createIndex("idx_restaurant_reservation_analytics_settings_location_id").on("restaurant_reservation_analytics_settings").column("location_id").execute();
6537
6537
  await db.schema.createTable("restaurant_reservation_analytics_events").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().references("restaurant_locations.id").onDelete("cascade")).addColumn("event_type", "text", (column) => column.notNull()).addColumn("occurred_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_restaurant_reservation_analytics_events_type", EVENT_TYPE_CHECK).execute();
@@ -6539,11 +6539,723 @@ async function up(db) {
6539
6539
  await db.schema.createIndex("idx_restaurant_reservation_analytics_events_location_occurred_at").on("restaurant_reservation_analytics_events").columns(["location_id", "occurred_at"]).execute();
6540
6540
  await db.schema.createIndex("idx_restaurant_reservation_analytics_events_location_event_type").on("restaurant_reservation_analytics_events").columns(["location_id", "event_type"]).execute();
6541
6541
  }
6542
- async function down(db) {
6542
+ async function down$7(db) {
6543
6543
  await db.schema.dropTable("restaurant_reservation_analytics_events").execute();
6544
6544
  await db.schema.dropTable("restaurant_reservation_analytics_settings").execute();
6545
6545
  }
6546
6546
 
6547
+ //#endregion
6548
+ //#region src/database/migrations/107_payment_stripe_configuration.ts
6549
+ var _107_payment_stripe_configuration_exports = /* @__PURE__ */ __exportAll({
6550
+ down: () => down$6,
6551
+ up: () => up$6
6552
+ });
6553
+ async function up$6(db) {
6554
+ await db.schema.createTable("payment_stripe_settings").addColumn("id", "text", (col) => col.primaryKey()).addColumn("default_key", "text", (col) => col.notNull().unique().defaultTo("default")).addColumn("mode", "text", (col) => col.notNull().check(sql`mode in ('test', 'live')`).defaultTo("test")).addColumn("publishable_key", "text").addColumn("configuration_status", "text", (col) => col.notNull().check(sql`configuration_status in ('unconfigured', 'unverified', 'valid', 'invalid')`).defaultTo("unconfigured")).addColumn("stripe_account_id", "text").addColumn("charges_enabled", "integer", (col) => col.check(sql`charges_enabled is null or charges_enabled in (0, 1)`)).addColumn("details_submitted", "integer", (col) => col.check(sql`details_submitted is null or details_submitted in (0, 1)`)).addColumn("tax_status", "text", (col) => col.notNull().check(sql`tax_status in ('unknown', 'active', 'pending', 'unavailable')`).defaultTo("unknown")).addColumn("validation_error_code", "text").addColumn("last_validated_at", "text").addColumn("connect_status", "text", (col) => col.notNull().check(sql`connect_status in ('not_configured', 'restricted', 'ready')`).defaultTo("not_configured")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_payment_stripe_settings_default_key", sql`default_key = 'default'`).execute();
6555
+ await sql`
6556
+ INSERT INTO payment_stripe_settings (
6557
+ id, default_key, mode, publishable_key, configuration_status,
6558
+ stripe_account_id, charges_enabled, details_submitted, tax_status,
6559
+ validation_error_code, last_validated_at, connect_status, version,
6560
+ created_at, updated_at
6561
+ )
6562
+ SELECT
6563
+ id, default_key, mode, publishable_key, configuration_status,
6564
+ stripe_account_id, charges_enabled, details_submitted, tax_status,
6565
+ validation_error_code, last_validated_at, connect_status, version,
6566
+ created_at, updated_at
6567
+ FROM restaurant_stripe_settings
6568
+ `.execute(db);
6569
+ await db.schema.createIndex("idx_payment_stripe_settings_updated_at").on("payment_stripe_settings").column("updated_at").execute();
6570
+ }
6571
+ async function down$6(db) {
6572
+ await db.schema.dropTable("payment_stripe_settings").execute();
6573
+ }
6574
+
6575
+ //#endregion
6576
+ //#region src/database/migrations/108_venue_foundation.ts
6577
+ var _108_venue_foundation_exports = /* @__PURE__ */ __exportAll({
6578
+ down: () => down$5,
6579
+ up: () => up$5
6580
+ });
6581
+ const RECORD_STATUS = sql`status in ('draft', 'active', 'archived')`;
6582
+ const SPACE_STATUS = sql`status in ('draft', 'active', 'archived')`;
6583
+ const BOOKING_MODE = sql`booking_mode in ('enquiry', 'request', 'instant')`;
6584
+ const ORDER_STATUS = sql`status in ('enquired', 'requested', 'quoted', 'negotiating', 'accepted', 'payment_pending', 'confirmed', 'declined', 'withdrawn', 'expired', 'cancelled', 'completed')`;
6585
+ const ORDER_HISTORY_TO_STATUS = sql`to_status in ('enquired', 'requested', 'quoted', 'negotiating', 'accepted', 'payment_pending', 'confirmed', 'declined', 'withdrawn', 'expired', 'cancelled', 'completed')`;
6586
+ async function up$5(db) {
6587
+ await runStep("inventory tables", () => createInventoryTables(db));
6588
+ await runStep("policy tables", () => createPolicyTables(db));
6589
+ await runStep("order tables", () => createOrderTables(db));
6590
+ await runStep("availability tables", () => createAvailabilityTables(db));
6591
+ await runStep("indexes", () => createIndexes$2(db));
6592
+ }
6593
+ async function runStep(label, action) {
6594
+ try {
6595
+ await action();
6596
+ } catch (error) {
6597
+ const message = error instanceof Error ? error.message : String(error);
6598
+ throw new Error(`Venue foundation ${label} failed: ${message}`, { cause: error });
6599
+ }
6600
+ }
6601
+ async function createInventoryTables(db) {
6602
+ await db.schema.createTable("venue_venues").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("name", "text", (col) => col.notNull()).addColumn("summary", "text").addColumn("description", "text").addColumn("status", "text", (col) => col.notNull().check(RECORD_STATUS).defaultTo("draft")).addColumn("website_url", "text").addColumn("phone", "text").addColumn("email", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
6603
+ await db.schema.createTable("venue_locations").addColumn("id", "text", (col) => col.primaryKey()).addColumn("venue_id", "text", (col) => col.notNull().references("venue_venues.id").onDelete("cascade")).addColumn("slug", "text", (col) => col.notNull()).addColumn("name", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(RECORD_STATUS).defaultTo("draft")).addColumn("timezone", "text", (col) => col.notNull()).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("address_line1", "text", (col) => col.notNull()).addColumn("address_line2", "text").addColumn("city", "text", (col) => col.notNull()).addColumn("region", "text").addColumn("postal_code", "text").addColumn("country_code", "text", (col) => col.notNull().check(sql`length(country_code) = 2`)).addColumn("latitude", "real", (col) => col.check(sql`latitude is null or latitude between -90 and 90`)).addColumn("longitude", "real", (col) => col.check(sql`longitude is null or longitude between -180 and 180`)).addColumn("phone", "text").addColumn("email", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_locations_venue_slug", ["venue_id", "slug"]).addUniqueConstraint("uq_venue_locations_venue_id", ["venue_id", "id"]).execute();
6604
+ await db.schema.createTable("venue_location_memberships").addColumn("id", "text", (col) => col.primaryKey()).addColumn("user_id", "text", (col) => col.notNull().references("users.id").onDelete("cascade")).addColumn("location_id", "text", (col) => col.references("venue_locations.id").onDelete("cascade")).addColumn("scope_key", "text", (col) => col.notNull()).addColumn("role", "text", (col) => col.notNull().check(sql`role in ('viewer', 'staff', 'manager')`)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_location_membership_scope", ["user_id", "scope_key"]).addCheckConstraint("ck_venue_location_membership_scope", sql`(location_id is null and scope_key = '*') or (location_id is not null and scope_key = location_id)`).execute();
6605
+ await db.schema.createTable("venue_spaces").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("venue_locations.id").onDelete("cascade")).addColumn("slug", "text", (col) => col.notNull()).addColumn("name", "text", (col) => col.notNull()).addColumn("summary", "text").addColumn("description", "text").addColumn("space_type", "text", (col) => col.notNull().check(sql`space_type in ('hall', 'function_room', 'bar', 'restaurant', 'hotel', 'warehouse', 'studio', 'outdoor', 'boat', 'meeting_room', 'other')`)).addColumn("privacy", "text", (col) => col.notNull().check(sql`privacy in ('private', 'semi_private', 'shared', 'whole_venue')`)).addColumn("status", "text", (col) => col.notNull().check(SPACE_STATUS).defaultTo("draft")).addColumn("booking_mode", "text", (col) => col.notNull().check(BOOKING_MODE).defaultTo("enquiry")).addColumn("minimum_party_size", "integer", (col) => col.notNull().check(sql`minimum_party_size between 1 and 100000`).defaultTo(1)).addColumn("maximum_party_size", "integer", (col) => col.notNull().check(sql`maximum_party_size between 1 and 100000`)).addColumn("minimum_duration_minutes", "integer", (col) => col.notNull().check(sql`minimum_duration_minutes between 15 and 43200`).defaultTo(60)).addColumn("maximum_duration_minutes", "integer", (col) => col.check(sql`maximum_duration_minutes is null or maximum_duration_minutes between 15 and 43200`)).addColumn("lead_minutes", "integer", (col) => col.notNull().check(sql`lead_minutes between 0 and 525600`).defaultTo(60)).addColumn("booking_horizon_days", "integer", (col) => col.notNull().check(sql`booking_horizon_days between 1 and 1095`).defaultTo(365)).addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_spaces_location_slug", ["location_id", "slug"]).addUniqueConstraint("uq_venue_spaces_location_id", ["location_id", "id"]).addCheckConstraint("ck_venue_spaces_party_size", sql`maximum_party_size >= minimum_party_size`).addCheckConstraint("ck_venue_spaces_duration", sql`maximum_duration_minutes is null or maximum_duration_minutes >= minimum_duration_minutes`).execute();
6606
+ await db.schema.createTable("venue_space_layouts").addColumn("id", "text", (col) => col.primaryKey()).addColumn("space_id", "text", (col) => col.notNull().references("venue_spaces.id").onDelete("cascade")).addColumn("layout_key", "text", (col) => col.notNull()).addColumn("layout_type", "text", (col) => col.notNull().check(sql`layout_type in ('standing', 'dining', 'theatre', 'boardroom', 'classroom', 'cabaret', 'u_shape', 'reception', 'custom')`)).addColumn("name", "text").addColumn("capacity", "integer", (col) => col.notNull().check(sql`capacity between 1 and 100000`)).addColumn("is_default", "integer", (col) => col.notNull().check(sql`is_default in (0, 1)`).defaultTo(0)).addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_space_layouts_key", ["space_id", "layout_key"]).execute();
6607
+ }
6608
+ async function createPolicyTables(db) {
6609
+ await db.schema.createTable("venue_rate_plans").addColumn("id", "text", (col) => col.primaryKey()).addColumn("space_id", "text", (col) => col.notNull().references("venue_spaces.id").onDelete("cascade")).addColumn("name", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'archived')`).defaultTo("active")).addColumn("price_basis", "text", (col) => col.notNull().check(sql`price_basis in ('hire_fee', 'minimum_spend', 'per_person')`)).addColumn("unit", "text", (col) => col.notNull().check(sql`unit in ('hour', 'session', 'day', 'person')`)).addColumn("amount_minor", "integer", (col) => col.notNull().check(sql`amount_minor >= 0`)).addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("tax_behavior", "text", (col) => col.notNull().check(sql`tax_behavior in ('exclusive', 'inclusive')`).defaultTo("exclusive")).addColumn("refundable_deposit_minor", "integer", (col) => col.notNull().check(sql`refundable_deposit_minor >= 0`).defaultTo(0)).addColumn("cleaning_fee_minor", "integer", (col) => col.notNull().check(sql`cleaning_fee_minor >= 0`).defaultTo(0)).addColumn("minimum_units", "integer", (col) => col.notNull().check(sql`minimum_units between 1 and 100000`).defaultTo(1)).addColumn("session_duration_minutes", "integer", (col) => col.check(sql`session_duration_minutes is null or session_duration_minutes between 15 and 43200`)).addColumn("days_of_week_json", "text", (col) => col.notNull().defaultTo("[0,1,2,3,4,5,6]")).addColumn("local_start_time", "text").addColumn("local_end_time", "text").addColumn("valid_from", "text").addColumn("valid_until", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_rate_plans_session", sql`(unit = 'session' and session_duration_minutes is not null) or (unit <> 'session' and session_duration_minutes is null)`).addCheckConstraint("ck_venue_rate_plans_time_window", sql`(local_start_time is null and local_end_time is null) or (local_start_time is not null and local_end_time is not null and local_end_time > local_start_time)`).execute();
6610
+ await db.schema.createTable("venue_booking_policies").addColumn("id", "text", (col) => col.primaryKey()).addColumn("space_id", "text", (col) => col.notNull().unique().references("venue_spaces.id").onDelete("cascade")).addColumn("payment_collection", "text", (col) => col.notNull().check(sql`payment_collection in ('full', 'deposit', 'scheduled', 'pay_later', 'offline')`).defaultTo("pay_later")).addColumn("deposit_type", "text", (col) => col.notNull().check(sql`deposit_type in ('none', 'fixed', 'percentage')`).defaultTo("none")).addColumn("deposit_value", "integer", (col) => col.notNull().check(sql`deposit_value >= 0`).defaultTo(0)).addColumn("balance_due_days", "integer", (col) => col.check(sql`balance_due_days is null or balance_due_days between 0 and 1095`)).addColumn("provisional_hold_minutes", "integer", (col) => col.notNull().check(sql`provisional_hold_minutes between 1 and 10080`).defaultTo(30)).addColumn("request_response_hours", "integer", (col) => col.notNull().check(sql`request_response_hours between 1 and 720`).defaultTo(48)).addColumn("requires_quote", "integer", (col) => col.notNull().check(sql`requires_quote in (0, 1)`).defaultTo(0)).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_booking_policies_deposit", sql`(
6611
+ (payment_collection = 'deposit' and deposit_type in ('fixed', 'percentage') and deposit_value > 0)
6612
+ or (payment_collection <> 'deposit' and deposit_type = 'none' and deposit_value = 0)
6613
+ )`).addCheckConstraint("ck_venue_booking_policies_percentage", sql`deposit_type <> 'percentage' or deposit_value between 1 and 10000`).addCheckConstraint("ck_venue_booking_policies_balance", sql`(payment_collection = 'scheduled' and balance_due_days is not null) or (payment_collection <> 'scheduled' and balance_due_days is null)`).execute();
6614
+ }
6615
+ async function createOrderTables(db) {
6616
+ await db.schema.createTable("venue_orders").addColumn("id", "text", (col) => col.primaryKey()).addColumn("location_id", "text", (col) => col.notNull().references("venue_locations.id").onDelete("restrict")).addColumn("space_id", "text", (col) => col.notNull().references("venue_spaces.id").onDelete("restrict")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("public_reference", "text", (col) => col.notNull().unique()).addColumn("source", "text", (col) => col.notNull().check(sql`source in ('public', 'admin', 'mcp', 'federation', 'import')`).defaultTo("public")).addColumn("booking_mode", "text", (col) => col.notNull().check(BOOKING_MODE)).addColumn("status", "text", (col) => col.notNull().check(ORDER_STATUS)).addColumn("customer_user_id", "text", (col) => col.references("users.id").onDelete("set null")).addColumn("guest_name", "text", (col) => col.notNull()).addColumn("guest_email", "text").addColumn("guest_phone", "text").addColumn("event_type", "text", (col) => col.notNull()).addColumn("starts_at", "text", (col) => col.notNull()).addColumn("ends_at", "text", (col) => col.notNull()).addColumn("timezone", "text", (col) => col.notNull()).addColumn("party_size", "integer", (col) => col.notNull().check(sql`party_size between 1 and 100000`)).addColumn("customer_message", "text").addColumn("currency", "text", (col) => col.notNull().check(sql`length(currency) = 3`)).addColumn("rate_plan_id", "text", (col) => col.references("venue_rate_plans.id").onDelete("set null")).addColumn("rate_plan_version", "integer").addColumn("booking_policy_version", "integer", (col) => col.notNull()).addColumn("pricing_snapshot_json", "text", (col) => col.notNull()).addColumn("subtotal_minor", "integer", (col) => col.notNull().check(sql`subtotal_minor >= 0`)).addColumn("tax_minor", "integer", (col) => col.notNull().check(sql`tax_minor >= 0`).defaultTo(0)).addColumn("fees_minor", "integer", (col) => col.notNull().check(sql`fees_minor >= 0`).defaultTo(0)).addColumn("refundable_deposit_minor", "integer", (col) => col.notNull().check(sql`refundable_deposit_minor >= 0`).defaultTo(0)).addColumn("total_minor", "integer", (col) => col.notNull().check(sql`total_minor >= 0`)).addColumn("payment_collection", "text", (col) => col.notNull().check(sql`payment_collection in ('full', 'deposit', 'scheduled', 'pay_later', 'offline')`)).addColumn("payment_status", "text", (col) => col.notNull().check(sql`payment_status in ('not_required', 'pending', 'authorized', 'partially_paid', 'paid', 'partially_refunded', 'refunded', 'failed')`).defaultTo("not_required")).addColumn("quote_status", "text", (col) => col.notNull().check(sql`quote_status in ('not_required', 'pending', 'issued', 'negotiating', 'accepted', 'declined', 'expired')`).defaultTo("not_required")).addColumn("accepted_at", "text").addColumn("confirmed_at", "text").addColumn("declined_at", "text").addColumn("withdrawn_at", "text").addColumn("expired_at", "text").addColumn("cancelled_at", "text").addColumn("completed_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_orders_time", sql`ends_at > starts_at`).addCheckConstraint("ck_venue_orders_contact", sql`customer_user_id is not null or guest_email is not null or guest_phone is not null`).addCheckConstraint("ck_venue_orders_rate_plan", sql`(rate_plan_id is null and rate_plan_version is null) or (rate_plan_id is not null and rate_plan_version is not null)`).execute();
6617
+ await db.schema.createTable("venue_order_status_history").addColumn("id", "text", (col) => col.primaryKey()).addColumn("order_id", "text", (col) => col.notNull().references("venue_orders.id").onDelete("cascade")).addColumn("from_status", "text").addColumn("to_status", "text", (col) => col.notNull().check(ORDER_HISTORY_TO_STATUS)).addColumn("actor_type", "text", (col) => col.notNull().check(sql`actor_type in ('user', 'api_token', 'guest', 'system')`)).addColumn("actor_id", "text").addColumn("reason_code", "text").addColumn("occurred_at", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_order_status_history_from_status", sql`from_status is null or from_status in ('enquired', 'requested', 'quoted', 'negotiating', 'accepted', 'payment_pending', 'confirmed', 'declined', 'withdrawn', 'expired', 'cancelled', 'completed')`).execute();
6618
+ await db.schema.createTable("venue_booking_holds").addColumn("id", "text", (col) => col.primaryKey()).addColumn("space_id", "text", (col) => col.notNull().references("venue_spaces.id").onDelete("cascade")).addColumn("order_id", "text", (col) => col.unique().references("venue_orders.id").onDelete("set null")).addColumn("request_key", "text", (col) => col.notNull().unique()).addColumn("starts_at", "text", (col) => col.notNull()).addColumn("ends_at", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'committed', 'released', 'expired')`).defaultTo("active")).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("committed_at", "text").addColumn("released_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_booking_holds_time", sql`ends_at > starts_at`).addCheckConstraint("ck_venue_booking_holds_state", sql`(
6619
+ (status = 'active' and committed_at is null and released_at is null)
6620
+ or (status = 'committed' and order_id is not null and committed_at is not null and released_at is null)
6621
+ or (status in ('released', 'expired') and released_at is not null)
6622
+ )`).execute();
6623
+ }
6624
+ async function createAvailabilityTables(db) {
6625
+ await db.schema.createTable("venue_availability_rules").addColumn("id", "text", (col) => col.primaryKey()).addColumn("space_id", "text", (col) => col.notNull().references("venue_spaces.id").onDelete("cascade")).addColumn("weekday", "integer", (col) => col.notNull().check(sql`weekday between 0 and 6`)).addColumn("local_start_time", "text", (col) => col.notNull().check(sql`length(local_start_time) = 5`)).addColumn("local_end_time", "text", (col) => col.notNull().check(sql`length(local_end_time) = 5`)).addColumn("slot_minutes", "integer", (col) => col.notNull().check(sql`slot_minutes between 5 and 1440`).defaultTo(30)).addColumn("valid_from", "text").addColumn("valid_until", "text").addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'inactive')`).defaultTo("active")).addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_availability_rules_time", sql`local_end_time > local_start_time`).addCheckConstraint("ck_venue_availability_rules_dates", sql`valid_until is null or valid_from is null or valid_until >= valid_from`).addUniqueConstraint("uq_venue_availability_rule_window", [
6626
+ "space_id",
6627
+ "weekday",
6628
+ "local_start_time",
6629
+ "local_end_time"
6630
+ ]).execute();
6631
+ await db.schema.createTable("venue_availability_blocks").addColumn("id", "text", (col) => col.primaryKey()).addColumn("space_id", "text", (col) => col.notNull().references("venue_spaces.id").onDelete("cascade")).addColumn("order_id", "text", (col) => col.references("venue_orders.id").onDelete("set null")).addColumn("hold_id", "text", (col) => col.references("venue_booking_holds.id").onDelete("set null")).addColumn("block_type", "text", (col) => col.notNull().check(sql`block_type in ('closure', 'external', 'provisional', 'confirmed', 'maintenance')`)).addColumn("starts_at", "text", (col) => col.notNull()).addColumn("ends_at", "text", (col) => col.notNull()).addColumn("reason", "text").addColumn("source_reference", "text").addColumn("status", "text", (col) => col.notNull().check(sql`status in ('active', 'released')`).defaultTo("active")).addColumn("released_at", "text").addColumn("version", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_availability_blocks_time", sql`ends_at > starts_at`).addCheckConstraint("ck_venue_availability_blocks_state", sql`(status = 'active' and released_at is null) or (status = 'released' and released_at is not null)`).addCheckConstraint("ck_venue_availability_blocks_subject", sql`hold_id is null or order_id is not null`).execute();
6632
+ }
6633
+ async function createIndexes$2(db) {
6634
+ for (const [name, table, columns] of [
6635
+ [
6636
+ "idx_venue_venues_status_updated",
6637
+ "venue_venues",
6638
+ ["status", "updated_at"]
6639
+ ],
6640
+ [
6641
+ "idx_venue_locations_venue_status",
6642
+ "venue_locations",
6643
+ ["venue_id", "status"]
6644
+ ],
6645
+ [
6646
+ "idx_venue_locations_city",
6647
+ "venue_locations",
6648
+ ["country_code", "city"]
6649
+ ],
6650
+ [
6651
+ "idx_venue_location_memberships_user",
6652
+ "venue_location_memberships",
6653
+ ["user_id"]
6654
+ ],
6655
+ [
6656
+ "idx_venue_location_memberships_location",
6657
+ "venue_location_memberships",
6658
+ ["location_id"]
6659
+ ],
6660
+ [
6661
+ "idx_venue_spaces_location_status",
6662
+ "venue_spaces",
6663
+ ["location_id", "status"]
6664
+ ],
6665
+ [
6666
+ "idx_venue_spaces_booking_mode",
6667
+ "venue_spaces",
6668
+ ["booking_mode", "status"]
6669
+ ],
6670
+ [
6671
+ "idx_venue_space_layouts_space",
6672
+ "venue_space_layouts",
6673
+ ["space_id", "sort_order"]
6674
+ ],
6675
+ [
6676
+ "idx_venue_rate_plans_space_status",
6677
+ "venue_rate_plans",
6678
+ ["space_id", "status"]
6679
+ ],
6680
+ [
6681
+ "idx_venue_orders_space_status",
6682
+ "venue_orders",
6683
+ ["space_id", "status"]
6684
+ ],
6685
+ [
6686
+ "idx_venue_orders_location_status",
6687
+ "venue_orders",
6688
+ ["location_id", "status"]
6689
+ ],
6690
+ [
6691
+ "idx_venue_orders_customer",
6692
+ "venue_orders",
6693
+ ["customer_user_id", "created_at"]
6694
+ ],
6695
+ [
6696
+ "idx_venue_orders_interval",
6697
+ "venue_orders",
6698
+ [
6699
+ "space_id",
6700
+ "starts_at",
6701
+ "ends_at"
6702
+ ]
6703
+ ],
6704
+ [
6705
+ "idx_venue_order_status_history_order",
6706
+ "venue_order_status_history",
6707
+ ["order_id", "occurred_at"]
6708
+ ],
6709
+ [
6710
+ "idx_venue_booking_holds_interval",
6711
+ "venue_booking_holds",
6712
+ [
6713
+ "space_id",
6714
+ "status",
6715
+ "starts_at",
6716
+ "ends_at"
6717
+ ]
6718
+ ],
6719
+ [
6720
+ "idx_venue_booking_holds_expiry",
6721
+ "venue_booking_holds",
6722
+ ["status", "expires_at"]
6723
+ ],
6724
+ [
6725
+ "idx_venue_availability_rules_space",
6726
+ "venue_availability_rules",
6727
+ [
6728
+ "space_id",
6729
+ "weekday",
6730
+ "status"
6731
+ ]
6732
+ ],
6733
+ [
6734
+ "idx_venue_availability_blocks_interval",
6735
+ "venue_availability_blocks",
6736
+ [
6737
+ "space_id",
6738
+ "status",
6739
+ "starts_at",
6740
+ "ends_at"
6741
+ ]
6742
+ ],
6743
+ [
6744
+ "idx_venue_availability_blocks_order",
6745
+ "venue_availability_blocks",
6746
+ ["order_id"]
6747
+ ]
6748
+ ]) try {
6749
+ await db.schema.createIndex(name).on(table).columns([...columns]).execute();
6750
+ } catch (error) {
6751
+ const message = error instanceof Error ? error.message : String(error);
6752
+ throw new Error(`Index ${name} failed: ${message}`, { cause: error });
6753
+ }
6754
+ }
6755
+ async function down$5(db) {
6756
+ await db.schema.dropTable("venue_availability_blocks").execute();
6757
+ await db.schema.dropTable("venue_availability_rules").execute();
6758
+ await db.schema.dropTable("venue_booking_holds").execute();
6759
+ await db.schema.dropTable("venue_order_status_history").execute();
6760
+ await db.schema.dropTable("venue_orders").execute();
6761
+ await db.schema.dropTable("venue_booking_policies").execute();
6762
+ await db.schema.dropTable("venue_rate_plans").execute();
6763
+ await db.schema.dropTable("venue_space_layouts").execute();
6764
+ await db.schema.dropTable("venue_spaces").execute();
6765
+ await db.schema.dropTable("venue_location_memberships").execute();
6766
+ await db.schema.dropTable("venue_locations").execute();
6767
+ await db.schema.dropTable("venue_venues").execute();
6768
+ }
6769
+
6770
+ //#endregion
6771
+ //#region src/database/migrations/109_venue_commercial_lifecycle.ts
6772
+ var _109_venue_commercial_lifecycle_exports = /* @__PURE__ */ __exportAll({
6773
+ down: () => down$4,
6774
+ up: () => up$4
6775
+ });
6776
+ async function up$4(db) {
6777
+ await createCancellationTables(db);
6778
+ await createQuoteTables(db);
6779
+ await createPaymentTables(db);
6780
+ await createIndexes$1(db);
6781
+ }
6782
+ async function createCancellationTables(db) {
6783
+ await db.schema.createTable("venue_cancellation_policies").addColumn("id", "text", (column) => column.primaryKey()).addColumn("space_id", "text", (column) => column.notNull().references("venue_spaces.id").onDelete("cascade")).addColumn("policy_version", "integer", (column) => column.notNull().check(sql`policy_version > 0`)).addColumn("name", "text", (column) => column.notNull()).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('active', 'archived')`).defaultTo("active")).addColumn("grace_minutes", "integer", (column) => column.notNull().check(sql`grace_minutes between 0 and 10080`).defaultTo(0)).addColumn("refund_fees", "integer", (column) => column.notNull().check(sql`refund_fees in (0, 1)`).defaultTo(0)).addColumn("refund_refundable_deposit", "integer", (column) => column.notNull().check(sql`refund_refundable_deposit in (0, 1)`).defaultTo(1)).addColumn("record_version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_cancellation_policy_version", ["space_id", "policy_version"]).execute();
6784
+ await db.schema.createTable("venue_cancellation_policy_tiers").addColumn("id", "text", (column) => column.primaryKey()).addColumn("policy_id", "text", (column) => column.notNull().references("venue_cancellation_policies.id").onDelete("cascade")).addColumn("cutoff_minutes", "integer", (column) => column.notNull().check(sql`cutoff_minutes >= 0`)).addColumn("refund_basis_points", "integer", (column) => column.notNull().check(sql`refund_basis_points between 0 and 10000`)).addColumn("sort_order", "integer", (column) => column.notNull().defaultTo(0)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_cancellation_policy_tier_cutoff", ["policy_id", "cutoff_minutes"]).execute();
6785
+ await db.schema.createTable("venue_order_cancellation_snapshots").addColumn("order_id", "text", (column) => column.primaryKey().references("venue_orders.id").onDelete("cascade")).addColumn("policy_id", "text", (column) => column.notNull().references("venue_cancellation_policies.id").onDelete("restrict")).addColumn("policy_version", "integer", (column) => column.notNull().check(sql`policy_version > 0`)).addColumn("snapshot_json", "text", (column) => column.notNull()).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
6786
+ }
6787
+ async function createQuoteTables(db) {
6788
+ await db.schema.createTable("venue_quotes").addColumn("id", "text", (column) => column.primaryKey()).addColumn("order_id", "text", (column) => column.notNull().references("venue_orders.id").onDelete("cascade")).addColumn("revision", "integer", (column) => column.notNull().check(sql`revision > 0`)).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('draft', 'issued', 'accepted', 'declined', 'expired', 'superseded')`).defaultTo("draft")).addColumn("currency", "text", (column) => column.notNull().check(sql`length(currency) = 3`)).addColumn("subtotal_minor", "integer", (column) => column.notNull().check(sql`subtotal_minor >= 0`)).addColumn("discount_minor", "integer", (column) => column.notNull().check(sql`discount_minor between 0 and subtotal_minor`).defaultTo(0)).addColumn("tax_minor", "integer", (column) => column.notNull().check(sql`tax_minor >= 0`).defaultTo(0)).addColumn("fees_minor", "integer", (column) => column.notNull().check(sql`fees_minor >= 0`).defaultTo(0)).addColumn("refundable_deposit_minor", "integer", (column) => column.notNull().check(sql`refundable_deposit_minor >= 0`).defaultTo(0)).addColumn("total_minor", "integer", (column) => column.notNull().check(sql`total_minor >= 0`)).addColumn("payment_collection", "text", (column) => column.notNull().check(sql`payment_collection in ('full', 'deposit', 'scheduled', 'pay_later', 'offline')`)).addColumn("initial_due_minor", "integer", (column) => column.notNull().check(sql`initial_due_minor between 0 and total_minor`)).addColumn("snapshot_json", "text", (column) => column.notNull()).addColumn("expires_at", "text", (column) => column.notNull()).addColumn("issued_at", "text").addColumn("accepted_at", "text").addColumn("declined_at", "text").addColumn("superseded_at", "text").addColumn("created_by_type", "text", (column) => column.notNull().check(sql`created_by_type in ('user', 'api_token', 'guest', 'system')`)).addColumn("created_by_id", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_quote_revision", ["order_id", "revision"]).addCheckConstraint("ck_venue_quote_total", sql`total_minor = subtotal_minor - discount_minor + tax_minor + fees_minor + refundable_deposit_minor`).addCheckConstraint("ck_venue_quote_state_timestamps", sql`(status = 'draft' and issued_at is null and accepted_at is null and declined_at is null and superseded_at is null)
6789
+ or (status = 'issued' and issued_at is not null and accepted_at is null and declined_at is null and superseded_at is null)
6790
+ or (status = 'accepted' and issued_at is not null and accepted_at is not null and declined_at is null and superseded_at is null)
6791
+ or (status = 'declined' and issued_at is not null and accepted_at is null and declined_at is not null and superseded_at is null)
6792
+ or (status = 'expired' and issued_at is not null and accepted_at is null and declined_at is null and superseded_at is null)
6793
+ or (status = 'superseded' and issued_at is not null and accepted_at is null and declined_at is null and superseded_at is not null)`).execute();
6794
+ await db.schema.createTable("venue_quote_lines").addColumn("id", "text", (column) => column.primaryKey()).addColumn("quote_id", "text", (column) => column.notNull().references("venue_quotes.id").onDelete("cascade")).addColumn("line_index", "integer", (column) => column.notNull().check(sql`line_index >= 0`)).addColumn("line_type", "text", (column) => column.notNull().check(sql`line_type in ('hire_fee', 'minimum_spend', 'per_person', 'fee', 'tax', 'refundable_deposit', 'discount', 'custom')`)).addColumn("label", "text", (column) => column.notNull()).addColumn("quantity", "integer", (column) => column.notNull().check(sql`quantity > 0`)).addColumn("unit_amount_minor", "integer", (column) => column.notNull().check(sql`unit_amount_minor >= 0`)).addColumn("total_minor", "integer", (column) => column.notNull().check(sql`total_minor >= 0`)).addColumn("currency", "text", (column) => column.notNull().check(sql`length(currency) = 3`)).addColumn("source_id", "text").addColumn("source_version", "integer").addColumn("metadata_json", "text", (column) => column.notNull().defaultTo("{}")).addUniqueConstraint("uq_venue_quote_line_index", ["quote_id", "line_index"]).addCheckConstraint("ck_venue_quote_line_source", sql`(source_id is null and source_version is null)
6795
+ or (source_id is not null and source_version is not null and source_version > 0)`).execute();
6796
+ }
6797
+ async function createPaymentTables(db) {
6798
+ await db.schema.createTable("venue_payment_allocations").addColumn("id", "text", (column) => column.primaryKey()).addColumn("order_id", "text", (column) => column.notNull().references("venue_orders.id").onDelete("cascade")).addColumn("quote_id", "text", (column) => column.references("venue_quotes.id").onDelete("restrict")).addColumn("sequence", "integer", (column) => column.notNull().check(sql`sequence > 0`)).addColumn("allocation_type", "text", (column) => column.notNull().check(sql`allocation_type in ('full', 'deposit', 'balance', 'refundable_deposit', 'adjustment')`)).addColumn("label", "text", (column) => column.notNull()).addColumn("currency", "text", (column) => column.notNull().check(sql`length(currency) = 3`)).addColumn("amount_minor", "integer", (column) => column.notNull().check(sql`amount_minor >= 0`)).addColumn("captured_minor", "integer", (column) => column.notNull().check(sql`captured_minor >= 0`).defaultTo(0)).addColumn("refunded_minor", "integer", (column) => column.notNull().check(sql`refunded_minor >= 0`).defaultTo(0)).addColumn("due_at", "text").addColumn("status", "text", (column) => column.notNull().check(sql`status in ('scheduled', 'due', 'pending', 'paid', 'partially_refunded', 'refunded', 'waived', 'cancelled')`).defaultTo("scheduled")).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_payment_allocation_sequence", ["order_id", "sequence"]).addCheckConstraint("ck_venue_payment_allocation_amounts", sql`refunded_minor <= captured_minor and captured_minor <= amount_minor`).execute();
6799
+ await db.schema.createTable("venue_payments").addColumn("id", "text", (column) => column.primaryKey()).addColumn("order_id", "text", (column) => column.notNull().references("venue_orders.id").onDelete("restrict")).addColumn("allocation_id", "text", (column) => column.references("venue_payment_allocations.id").onDelete("restrict")).addColumn("operation_key", "text", (column) => column.notNull().unique()).addColumn("provider", "text", (column) => column.notNull().check(sql`provider in ('stripe', 'offline')`)).addColumn("payment_flow", "text", (column) => column.notNull().check(sql`payment_flow in ('checkout', 'payment_element', 'offline')`)).addColumn("provider_session_id", "text").addColumn("provider_payment_id", "text").addColumn("status", "text", (column) => column.notNull().check(sql`status in ('requires_action', 'processing', 'authorized', 'succeeded', 'partially_refunded', 'refunded', 'failed', 'cancelled')`)).addColumn("currency", "text", (column) => column.notNull().check(sql`length(currency) = 3`)).addColumn("amount_requested_minor", "integer", (column) => column.notNull().check(sql`amount_requested_minor >= 0`)).addColumn("amount_authorized_minor", "integer", (column) => column.notNull().check(sql`amount_authorized_minor >= 0`).defaultTo(0)).addColumn("amount_captured_minor", "integer", (column) => column.notNull().check(sql`amount_captured_minor >= 0`).defaultTo(0)).addColumn("amount_refunded_minor", "integer", (column) => column.notNull().check(sql`amount_refunded_minor >= 0`).defaultTo(0)).addColumn("failure_code", "text").addColumn("failure_message", "text").addColumn("provider_context_json", "text", (column) => column.notNull().defaultTo("{}")).addColumn("processed_at", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_payment_provider_session", ["provider", "provider_session_id"]).addUniqueConstraint("uq_venue_payment_provider_payment", ["provider", "provider_payment_id"]).addCheckConstraint("ck_venue_payment_amounts", sql`amount_refunded_minor <= amount_captured_minor
6800
+ and amount_captured_minor <= amount_authorized_minor
6801
+ and amount_authorized_minor <= amount_requested_minor`).addCheckConstraint("ck_venue_payment_provider_flow", sql`(provider = 'offline' and payment_flow = 'offline')
6802
+ or (provider = 'stripe' and payment_flow in ('checkout', 'payment_element'))`).execute();
6803
+ await db.schema.createTable("venue_refunds").addColumn("id", "text", (column) => column.primaryKey()).addColumn("order_id", "text", (column) => column.notNull().references("venue_orders.id").onDelete("restrict")).addColumn("payment_id", "text", (column) => column.notNull().references("venue_payments.id").onDelete("restrict")).addColumn("allocation_id", "text", (column) => column.references("venue_payment_allocations.id").onDelete("restrict")).addColumn("operation_key", "text", (column) => column.notNull().unique()).addColumn("provider_refund_id", "text", (column) => column.unique()).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('pending', 'succeeded', 'failed', 'cancelled')`)).addColumn("currency", "text", (column) => column.notNull().check(sql`length(currency) = 3`)).addColumn("amount_minor", "integer", (column) => column.notNull().check(sql`amount_minor > 0`)).addColumn("reason_code", "text", (column) => column.notNull()).addColumn("failure_code", "text").addColumn("failure_message", "text").addColumn("completed_at", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_refund_completed", sql`(status = 'pending' and completed_at is null)
6804
+ or (status in ('succeeded', 'failed', 'cancelled') and completed_at is not null)`).execute();
6805
+ await db.schema.createTable("venue_payment_events").addColumn("id", "text", (column) => column.primaryKey()).addColumn("provider", "text", (column) => column.notNull().check(sql`provider in ('stripe')`)).addColumn("provider_event_id", "text", (column) => column.notNull()).addColumn("event_type", "text", (column) => column.notNull()).addColumn("payload_hash", "text", (column) => column.notNull()).addColumn("payment_id", "text", (column) => column.references("venue_payments.id").onDelete("set null")).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('received', 'processed', 'failed', 'ignored')`).defaultTo("received")).addColumn("error_message", "text").addColumn("received_at", "text", (column) => column.notNull()).addColumn("processed_at", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_payment_event_provider", ["provider", "provider_event_id"]).execute();
6806
+ }
6807
+ async function createIndexes$1(db) {
6808
+ for (const [name, table, columns] of [
6809
+ [
6810
+ "idx_venue_cancellation_policy_space_status",
6811
+ "venue_cancellation_policies",
6812
+ ["space_id", "status"]
6813
+ ],
6814
+ [
6815
+ "idx_venue_cancellation_tier_policy",
6816
+ "venue_cancellation_policy_tiers",
6817
+ ["policy_id", "sort_order"]
6818
+ ],
6819
+ [
6820
+ "idx_venue_order_cancellation_policy",
6821
+ "venue_order_cancellation_snapshots",
6822
+ ["policy_id"]
6823
+ ],
6824
+ [
6825
+ "idx_venue_quote_order_status",
6826
+ "venue_quotes",
6827
+ [
6828
+ "order_id",
6829
+ "status",
6830
+ "revision"
6831
+ ]
6832
+ ],
6833
+ [
6834
+ "idx_venue_quote_expiry",
6835
+ "venue_quotes",
6836
+ ["status", "expires_at"]
6837
+ ],
6838
+ [
6839
+ "idx_venue_quote_line_quote",
6840
+ "venue_quote_lines",
6841
+ ["quote_id", "line_index"]
6842
+ ],
6843
+ [
6844
+ "idx_venue_allocation_order_status",
6845
+ "venue_payment_allocations",
6846
+ [
6847
+ "order_id",
6848
+ "status",
6849
+ "sequence"
6850
+ ]
6851
+ ],
6852
+ [
6853
+ "idx_venue_allocation_due",
6854
+ "venue_payment_allocations",
6855
+ ["status", "due_at"]
6856
+ ],
6857
+ [
6858
+ "idx_venue_payment_order_status",
6859
+ "venue_payments",
6860
+ [
6861
+ "order_id",
6862
+ "status",
6863
+ "created_at"
6864
+ ]
6865
+ ],
6866
+ [
6867
+ "idx_venue_payment_allocation",
6868
+ "venue_payments",
6869
+ ["allocation_id"]
6870
+ ],
6871
+ [
6872
+ "idx_venue_refund_order_status",
6873
+ "venue_refunds",
6874
+ [
6875
+ "order_id",
6876
+ "status",
6877
+ "created_at"
6878
+ ]
6879
+ ],
6880
+ [
6881
+ "idx_venue_refund_payment",
6882
+ "venue_refunds",
6883
+ ["payment_id"]
6884
+ ],
6885
+ [
6886
+ "idx_venue_payment_event_status",
6887
+ "venue_payment_events",
6888
+ ["status", "received_at"]
6889
+ ],
6890
+ [
6891
+ "idx_venue_payment_event_payment",
6892
+ "venue_payment_events",
6893
+ ["payment_id"]
6894
+ ]
6895
+ ]) await db.schema.createIndex(name).on(table).columns([...columns]).execute();
6896
+ }
6897
+ async function down$4(db) {
6898
+ await db.schema.dropTable("venue_payment_events").execute();
6899
+ await db.schema.dropTable("venue_refunds").execute();
6900
+ await db.schema.dropTable("venue_payments").execute();
6901
+ await db.schema.dropTable("venue_payment_allocations").execute();
6902
+ await db.schema.dropTable("venue_quote_lines").execute();
6903
+ await db.schema.dropTable("venue_quotes").execute();
6904
+ await db.schema.dropTable("venue_order_cancellation_snapshots").execute();
6905
+ await db.schema.dropTable("venue_cancellation_policy_tiers").execute();
6906
+ await db.schema.dropTable("venue_cancellation_policies").execute();
6907
+ }
6908
+
6909
+ //#endregion
6910
+ //#region src/database/migrations/110_venue_communications_reviews.ts
6911
+ var _110_venue_communications_reviews_exports = /* @__PURE__ */ __exportAll({
6912
+ down: () => down$3,
6913
+ up: () => up$3
6914
+ });
6915
+ async function up$3(db) {
6916
+ await createConversationTables(db);
6917
+ await createNotificationTables(db);
6918
+ await createReviewTables(db);
6919
+ await createIndexes(db);
6920
+ }
6921
+ async function createConversationTables(db) {
6922
+ await db.schema.createTable("venue_conversations").addColumn("id", "text", (column) => column.primaryKey()).addColumn("order_id", "text", (column) => column.notNull().unique().references("venue_orders.id").onDelete("cascade")).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('open', 'closed')`).defaultTo("open")).addColumn("subject", "text", (column) => column.notNull().check(sql`length(subject) between 1 and 255`)).addColumn("last_message_at", "text").addColumn("customer_unread_count", "integer", (column) => column.notNull().check(sql`customer_unread_count >= 0`).defaultTo(0)).addColumn("manager_unread_count", "integer", (column) => column.notNull().check(sql`manager_unread_count >= 0`).defaultTo(0)).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
6923
+ await db.schema.createTable("venue_messages").addColumn("id", "text", (column) => column.primaryKey()).addColumn("conversation_id", "text", (column) => column.notNull().references("venue_conversations.id").onDelete("cascade")).addColumn("sender_type", "text", (column) => column.notNull().check(sql`sender_type in ('user', 'api_token', 'guest', 'system')`)).addColumn("sender_id", "text").addColumn("sender_role", "text", (column) => column.notNull().check(sql`sender_role in ('customer', 'manager', 'system')`)).addColumn("body", "text", (column) => column.notNull().check(sql`length(body) between 1 and 10000`)).addColumn("attachments_json", "text", (column) => column.notNull().defaultTo("[]")).addColumn("sent_at", "text", (column) => column.notNull()).addColumn("edited_at", "text").addColumn("redacted_at", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_message_sender", sql`(sender_type = 'system' and sender_id is null and sender_role = 'system')
6924
+ or (sender_type != 'system' and sender_id is not null and sender_role != 'system')`).execute();
6925
+ await db.schema.createTable("venue_conversation_reads").addColumn("id", "text", (column) => column.primaryKey()).addColumn("conversation_id", "text", (column) => column.notNull().references("venue_conversations.id").onDelete("cascade")).addColumn("reader_type", "text", (column) => column.notNull().check(sql`reader_type in ('user', 'api_token', 'guest')`)).addColumn("reader_id", "text", (column) => column.notNull()).addColumn("reader_role", "text", (column) => column.notNull().check(sql`reader_role in ('customer', 'manager')`)).addColumn("last_read_message_id", "text", (column) => column.references("venue_messages.id").onDelete("set null")).addColumn("last_read_at", "text", (column) => column.notNull()).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addUniqueConstraint("uq_venue_conversation_reader", [
6926
+ "conversation_id",
6927
+ "reader_type",
6928
+ "reader_id",
6929
+ "reader_role"
6930
+ ]).execute();
6931
+ }
6932
+ async function createNotificationTables(db) {
6933
+ await db.schema.createTable("venue_notification_settings").addColumn("location_id", "text", (column) => column.primaryKey().references("venue_locations.id").onDelete("cascade")).addColumn("email_enabled", "integer", (column) => column.notNull().check(sql`email_enabled in (0, 1)`).defaultTo(1)).addColumn("manager_recipients_json", "text", (column) => column.notNull().defaultTo("[]")).addColumn("customer_event_types_json", "text", (column) => column.notNull().defaultTo("[]")).addColumn("manager_event_types_json", "text", (column) => column.notNull().defaultTo("[]")).addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
6934
+ await db.schema.createTable("venue_outbox_events").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().references("venue_locations.id").onDelete("restrict")).addColumn("order_id", "text", (column) => column.references("venue_orders.id").onDelete("restrict")).addColumn("aggregate_type", "text", (column) => column.notNull().check(sql`length(aggregate_type) between 1 and 64`)).addColumn("aggregate_id", "text", (column) => column.notNull().check(sql`length(aggregate_id) between 1 and 255`)).addColumn("event_type", "text", (column) => column.notNull().check(sql`length(event_type) between 1 and 128`)).addColumn("dedupe_key", "text", (column) => column.notNull().unique()).addColumn("payload_json", "text", (column) => column.notNull().defaultTo("{}")).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('pending', 'processing', 'delivered', 'failed')`).defaultTo("pending")).addColumn("attempt_count", "integer", (column) => column.notNull().check(sql`attempt_count >= 0`).defaultTo(0)).addColumn("retryable", "integer", (column) => column.notNull().check(sql`retryable in (0, 1)`).defaultTo(1)).addColumn("available_at", "text", (column) => column.notNull()).addColumn("locked_until", "text").addColumn("last_error_code", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).execute();
6935
+ await db.schema.createTable("venue_guest_access").addColumn("id", "text", (column) => column.primaryKey()).addColumn("location_id", "text", (column) => column.notNull().references("venue_locations.id").onDelete("restrict")).addColumn("order_id", "text", (column) => column.notNull().references("venue_orders.id").onDelete("restrict")).addColumn("token_id", "text", (column) => column.notNull().unique()).addColumn("token_hash", "text", (column) => column.notNull().unique()).addColumn("purpose", "text", (column) => column.notNull().check(sql`purpose = 'booking_manage'`)).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('active', 'revoked')`).defaultTo("active")).addColumn("expires_at", "text", (column) => column.notNull()).addColumn("revoked_at", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_guest_access_state", sql`(status = 'active' and revoked_at is null)
6936
+ or (status = 'revoked' and revoked_at is not null)`).execute();
6937
+ }
6938
+ async function createReviewTables(db) {
6939
+ await db.schema.createTable("venue_review_invitations").addColumn("id", "text", (column) => column.primaryKey()).addColumn("order_id", "text", (column) => column.notNull().unique().references("venue_orders.id").onDelete("restrict")).addColumn("customer_user_id", "text", (column) => column.references("users.id").onDelete("set null")).addColumn("guest_email_digest", "text").addColumn("token_digest", "text", (column) => column.notNull().unique()).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('pending', 'sent', 'completed', 'expired', 'revoked')`).defaultTo("pending")).addColumn("eligible_at", "text", (column) => column.notNull()).addColumn("expires_at", "text", (column) => column.notNull()).addColumn("sent_at", "text").addColumn("completed_at", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_review_invitation_subject", sql`customer_user_id is not null or guest_email_digest is not null`).addCheckConstraint("ck_venue_review_invitation_state", sql`(status = 'pending' and sent_at is null and completed_at is null)
6940
+ or (status = 'sent' and sent_at is not null and completed_at is null)
6941
+ or (status = 'completed' and sent_at is not null and completed_at is not null)
6942
+ or (status in ('expired', 'revoked') and completed_at is null)`).execute();
6943
+ await db.schema.createTable("venue_reviews").addColumn("id", "text", (column) => column.primaryKey()).addColumn("order_id", "text", (column) => column.notNull().unique().references("venue_orders.id").onDelete("restrict")).addColumn("location_id", "text", (column) => column.notNull().references("venue_locations.id").onDelete("restrict")).addColumn("space_id", "text", (column) => column.notNull().references("venue_spaces.id").onDelete("restrict")).addColumn("customer_user_id", "text", (column) => column.references("users.id").onDelete("set null")).addColumn("guest_email_digest", "text").addColumn("rating", "integer", (column) => column.notNull().check(sql`rating between 1 and 5`)).addColumn("communication_rating", "integer", (column) => column.check(sql`communication_rating is null or communication_rating between 1 and 5`)).addColumn("service_rating", "integer", (column) => column.check(sql`service_rating is null or service_rating between 1 and 5`)).addColumn("value_rating", "integer", (column) => column.check(sql`value_rating is null or value_rating between 1 and 5`)).addColumn("title", "text").addColumn("body", "text", (column) => column.notNull().check(sql`length(body) between 1 and 10000`)).addColumn("verified_booking", "integer", (column) => column.notNull().check(sql`verified_booking = 1`).defaultTo(1)).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('pending', 'published', 'rejected', 'removed')`).defaultTo("pending")).addColumn("submitted_at", "text", (column) => column.notNull()).addColumn("published_at", "text").addColumn("moderated_by_type", "text", (column) => column.check(sql`moderated_by_type is null or moderated_by_type in ('user', 'api_token', 'system')`)).addColumn("moderated_by_id", "text").addColumn("moderation_note", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_review_subject", sql`customer_user_id is not null or guest_email_digest is not null`).addCheckConstraint("ck_venue_review_publication", sql`(status = 'published' and published_at is not null)
6944
+ or (status != 'published' and published_at is null)`).execute();
6945
+ await db.schema.createTable("venue_review_responses").addColumn("id", "text", (column) => column.primaryKey()).addColumn("review_id", "text", (column) => column.notNull().unique().references("venue_reviews.id").onDelete("cascade")).addColumn("body", "text", (column) => column.notNull().check(sql`length(body) between 1 and 10000`)).addColumn("status", "text", (column) => column.notNull().check(sql`status in ('draft', 'published', 'removed')`).defaultTo("draft")).addColumn("created_by_type", "text", (column) => column.notNull().check(sql`created_by_type in ('user', 'api_token', 'system')`)).addColumn("created_by_id", "text").addColumn("published_at", "text").addColumn("version", "integer", (column) => column.notNull().defaultTo(1)).addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addCheckConstraint("ck_venue_review_response_publication", sql`(status = 'published' and published_at is not null)
6946
+ or (status != 'published' and published_at is null)`).execute();
6947
+ }
6948
+ async function createIndexes(db) {
6949
+ for (const [name, table, columns] of [
6950
+ [
6951
+ "idx_venue_conversation_order_status",
6952
+ "venue_conversations",
6953
+ ["order_id", "status"]
6954
+ ],
6955
+ [
6956
+ "idx_venue_conversation_activity",
6957
+ "venue_conversations",
6958
+ ["last_message_at", "id"]
6959
+ ],
6960
+ [
6961
+ "idx_venue_message_conversation_sent",
6962
+ "venue_messages",
6963
+ [
6964
+ "conversation_id",
6965
+ "sent_at",
6966
+ "id"
6967
+ ]
6968
+ ],
6969
+ [
6970
+ "idx_venue_conversation_read_actor",
6971
+ "venue_conversation_reads",
6972
+ ["reader_type", "reader_id"]
6973
+ ],
6974
+ [
6975
+ "idx_venue_outbox_delivery_queue",
6976
+ "venue_outbox_events",
6977
+ [
6978
+ "status",
6979
+ "available_at",
6980
+ "created_at",
6981
+ "id"
6982
+ ]
6983
+ ],
6984
+ [
6985
+ "idx_venue_outbox_location_status",
6986
+ "venue_outbox_events",
6987
+ ["location_id", "status"]
6988
+ ],
6989
+ [
6990
+ "idx_venue_outbox_aggregate",
6991
+ "venue_outbox_events",
6992
+ ["aggregate_type", "aggregate_id"]
6993
+ ],
6994
+ [
6995
+ "idx_venue_guest_access_order_status",
6996
+ "venue_guest_access",
6997
+ ["order_id", "status"]
6998
+ ],
6999
+ [
7000
+ "idx_venue_guest_access_location_status",
7001
+ "venue_guest_access",
7002
+ ["location_id", "status"]
7003
+ ],
7004
+ [
7005
+ "idx_venue_guest_access_expiry",
7006
+ "venue_guest_access",
7007
+ ["expires_at", "status"]
7008
+ ],
7009
+ [
7010
+ "idx_venue_review_invitation_status",
7011
+ "venue_review_invitations",
7012
+ ["status", "eligible_at"]
7013
+ ],
7014
+ [
7015
+ "idx_venue_review_location_status",
7016
+ "venue_reviews",
7017
+ [
7018
+ "location_id",
7019
+ "status",
7020
+ "submitted_at"
7021
+ ]
7022
+ ],
7023
+ [
7024
+ "idx_venue_review_space_status",
7025
+ "venue_reviews",
7026
+ [
7027
+ "space_id",
7028
+ "status",
7029
+ "submitted_at"
7030
+ ]
7031
+ ]
7032
+ ]) await db.schema.createIndex(name).on(table).columns([...columns]).execute();
7033
+ }
7034
+ async function down$3(db) {
7035
+ await db.schema.dropTable("venue_review_responses").execute();
7036
+ await db.schema.dropTable("venue_reviews").execute();
7037
+ await db.schema.dropTable("venue_review_invitations").execute();
7038
+ await db.schema.dropTable("venue_guest_access").execute();
7039
+ await db.schema.dropTable("venue_outbox_events").execute();
7040
+ await db.schema.dropTable("venue_notification_settings").execute();
7041
+ await db.schema.dropTable("venue_conversation_reads").execute();
7042
+ await db.schema.dropTable("venue_messages").execute();
7043
+ await db.schema.dropTable("venue_conversations").execute();
7044
+ }
7045
+
7046
+ //#endregion
7047
+ //#region src/database/migrations/111_content_release_grants.ts
7048
+ var _111_content_release_grants_exports = /* @__PURE__ */ __exportAll({
7049
+ down: () => down$2,
7050
+ up: () => up$2
7051
+ });
7052
+ async function up$2(db) {
7053
+ await db.schema.createTable("_dineway_content_release_grants").addColumn("id", "text", (column) => column.primaryKey()).addColumn("status", "text", (column) => column.notNull().defaultTo("active").check(sql`status in ('active', 'consumed', 'revoked', 'expired')`)).addColumn("collection", "text", (column) => column.notNull()).addColumn("entry_id", "text", (column) => column.notNull()).addColumn("scope", "text", (column) => column.notNull()).addColumn("live_revision_id", "text").addColumn("draft_revision_id", "text").addColumn("reviewed_rev", "text", (column) => column.notNull()).addColumn("editorial_review_request_id", "text", (column) => column.notNull().references("_dineway_review_requests.id").onDelete("restrict")).addColumn("release_hitl_request_id", "text", (column) => column.references("_dineway_hitl_requests.id").onDelete("restrict")).addColumn("operation", "text", (column) => column.notNull().check(sql`operation in ('publish', 'schedule')`)).addColumn("scheduled_at", "text").addColumn("published_at", "text").addColumn("site_timezone", "text", (column) => column.notNull()).addColumn("action_hash", "text", (column) => column.notNull()).addColumn("policy_contributions", "text", (column) => column.notNull().defaultTo("[]")).addColumn("authorization_method", "text", (column) => column.notNull().check(sql`authorization_method in ('human_action', 'approved_hitl')`)).addColumn("authorized_by_actor_type", "text", (column) => column.notNull().check(sql`authorized_by_actor_type in ('user', 'api_token', 'system')`)).addColumn("authorized_by_actor_id", "text", (column) => column.notNull()).addColumn("authorized_auth_metadata", "text").addColumn("expires_at", "text").addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("consumed_at", "text").addColumn("revoked_at", "text").addColumn("revocation_reason", "text").addCheckConstraint("ck_dineway_content_release_grants_operation_time", sql`(operation = 'publish' and scheduled_at is null)
7054
+ or (operation = 'schedule' and scheduled_at is not null and published_at is null)`).addCheckConstraint("ck_dineway_content_release_grants_authorization", sql`(authorization_method = 'human_action' and release_hitl_request_id is null)
7055
+ or (authorization_method = 'approved_hitl' and release_hitl_request_id is not null)`).addCheckConstraint("ck_dineway_content_release_grants_terminal_state", sql`(status = 'active' and consumed_at is null and revoked_at is null)
7056
+ or (status = 'consumed' and consumed_at is not null and revoked_at is null)
7057
+ or (status = 'revoked' and consumed_at is null and revoked_at is not null)
7058
+ or (status = 'expired' and consumed_at is null and revoked_at is null)`).execute();
7059
+ await db.schema.createIndex("idx_dineway_content_release_grants_due").on("_dineway_content_release_grants").columns([
7060
+ "status",
7061
+ "operation",
7062
+ "scheduled_at"
7063
+ ]).execute();
7064
+ await db.schema.createIndex("idx_dineway_content_release_grants_target").on("_dineway_content_release_grants").columns([
7065
+ "collection",
7066
+ "entry_id",
7067
+ "status",
7068
+ "created_at"
7069
+ ]).execute();
7070
+ await db.schema.createIndex("idx_dineway_content_release_grants_editorial_review").on("_dineway_content_release_grants").column("editorial_review_request_id").execute();
7071
+ await db.schema.createIndex("idx_dineway_content_release_grants_release_hitl").on("_dineway_content_release_grants").column("release_hitl_request_id").execute();
7072
+ await db.schema.createIndex("idx_dineway_content_release_grants_action_hash").on("_dineway_content_release_grants").column("action_hash").execute();
7073
+ await sql`
7074
+ CREATE UNIQUE INDEX idx_dineway_content_release_grants_active_target
7075
+ ON _dineway_content_release_grants (collection, entry_id, operation)
7076
+ WHERE status = 'active'
7077
+ `.execute(db);
7078
+ }
7079
+ async function down$2(db) {
7080
+ await db.schema.dropTable("_dineway_content_release_grants").execute();
7081
+ }
7082
+
7083
+ //#endregion
7084
+ //#region src/database/migrations/114_assignment_overdue.ts
7085
+ var _114_assignment_overdue_exports = /* @__PURE__ */ __exportAll({
7086
+ down: () => down$1,
7087
+ up: () => up$1
7088
+ });
7089
+ const ACTOR_TYPES = [
7090
+ "user",
7091
+ "api_token",
7092
+ "system"
7093
+ ];
7094
+ const ACTIVE_STATUSES = [
7095
+ "pending",
7096
+ "accepted",
7097
+ "in_progress",
7098
+ "blocked"
7099
+ ];
7100
+ const TERMINAL_STATUSES = [
7101
+ "completed",
7102
+ "declined",
7103
+ "cancelled"
7104
+ ];
7105
+ const PRIORITIES = [
7106
+ "low",
7107
+ "normal",
7108
+ "high",
7109
+ "urgent"
7110
+ ];
7111
+ async function up$1(db) {
7112
+ if (isSqlite(db)) {
7113
+ await rebuildSqliteAssignments(db, true);
7114
+ return;
7115
+ }
7116
+ await db.schema.alterTable("_dineway_assignments").addColumn("overdue_at", "text").execute();
7117
+ await replacePostgresStatusConstraint(db, [
7118
+ ...ACTIVE_STATUSES,
7119
+ ...TERMINAL_STATUSES,
7120
+ "overdue"
7121
+ ]);
7122
+ }
7123
+ async function down$1(db) {
7124
+ if (isSqlite(db)) {
7125
+ await rebuildSqliteAssignments(db, false);
7126
+ return;
7127
+ }
7128
+ await sql`
7129
+ UPDATE _dineway_assignments
7130
+ SET status = 'cancelled', cancelled_at = coalesce(cancelled_at, overdue_at)
7131
+ WHERE status = 'overdue'
7132
+ `.execute(db);
7133
+ await replacePostgresStatusConstraint(db, [...ACTIVE_STATUSES, ...TERMINAL_STATUSES]);
7134
+ await db.schema.alterTable("_dineway_assignments").dropColumn("overdue_at").execute();
7135
+ }
7136
+ async function rebuildSqliteAssignments(db, includeOverdue) {
7137
+ await sql.raw("PRAGMA foreign_keys = OFF").execute(db);
7138
+ try {
7139
+ await db.schema.dropTable("_dineway_assignments_new").ifExists().execute();
7140
+ await createAssignmentTable(db, includeOverdue);
7141
+ if (includeOverdue) await sql`
7142
+ INSERT INTO _dineway_assignments_new (
7143
+ id, scope, assignment_type, status, priority, title, summary, details,
7144
+ assigned_by_actor_type, assigned_by_actor_id, assigned_to_actor_type,
7145
+ assigned_to_actor_id, metadata, related_handoff_snapshot_id,
7146
+ related_hitl_request_id, due_at, created_at, updated_at, accepted_at,
7147
+ started_at, blocked_at, completed_at, declined_at, cancelled_at, overdue_at
7148
+ )
7149
+ SELECT
7150
+ id, scope, assignment_type, status, priority, title, summary, details,
7151
+ assigned_by_actor_type, assigned_by_actor_id, assigned_to_actor_type,
7152
+ assigned_to_actor_id, metadata, related_handoff_snapshot_id,
7153
+ related_hitl_request_id, due_at, created_at, updated_at, accepted_at,
7154
+ started_at, blocked_at, completed_at, declined_at, cancelled_at, null
7155
+ FROM _dineway_assignments
7156
+ `.execute(db);
7157
+ else await sql`
7158
+ INSERT INTO _dineway_assignments_new (
7159
+ id, scope, assignment_type, status, priority, title, summary, details,
7160
+ assigned_by_actor_type, assigned_by_actor_id, assigned_to_actor_type,
7161
+ assigned_to_actor_id, metadata, related_handoff_snapshot_id,
7162
+ related_hitl_request_id, due_at, created_at, updated_at, accepted_at,
7163
+ started_at, blocked_at, completed_at, declined_at, cancelled_at
7164
+ )
7165
+ SELECT
7166
+ id, scope, assignment_type,
7167
+ CASE WHEN status = 'overdue' THEN 'cancelled' ELSE status END,
7168
+ priority, title, summary, details, assigned_by_actor_type,
7169
+ assigned_by_actor_id, assigned_to_actor_type, assigned_to_actor_id,
7170
+ metadata, related_handoff_snapshot_id, related_hitl_request_id, due_at,
7171
+ created_at, updated_at, accepted_at, started_at, blocked_at, completed_at,
7172
+ declined_at,
7173
+ CASE WHEN status = 'overdue' THEN coalesce(cancelled_at, overdue_at) ELSE cancelled_at END
7174
+ FROM _dineway_assignments
7175
+ `.execute(db);
7176
+ await db.schema.dropTable("_dineway_assignments").execute();
7177
+ await sql`ALTER TABLE _dineway_assignments_new RENAME TO _dineway_assignments`.execute(db);
7178
+ await createAssignmentIndexes(db);
7179
+ } finally {
7180
+ await sql.raw("PRAGMA foreign_keys = ON").execute(db);
7181
+ }
7182
+ }
7183
+ async function createAssignmentTable(db, includeOverdue) {
7184
+ const statuses = includeOverdue ? [
7185
+ ...ACTIVE_STATUSES,
7186
+ ...TERMINAL_STATUSES,
7187
+ "overdue"
7188
+ ] : [...ACTIVE_STATUSES, ...TERMINAL_STATUSES];
7189
+ const actorTypesSql = sql.join(ACTOR_TYPES.map((value) => sql.lit(value)), sql`, `);
7190
+ const statusesSql = sql.join(statuses.map((value) => sql.lit(value)), sql`, `);
7191
+ const prioritiesSql = sql.join(PRIORITIES.map((value) => sql.lit(value)), sql`, `);
7192
+ let builder = db.schema.createTable("_dineway_assignments_new").addColumn("id", "text", (column) => column.primaryKey()).addColumn("scope", "text", (column) => column.notNull()).addColumn("assignment_type", "text", (column) => column.notNull()).addColumn("status", "text", (column) => column.notNull().defaultTo("pending").check(sql`status in (${statusesSql})`)).addColumn("priority", "text", (column) => column.notNull().defaultTo("normal").check(sql`priority in (${prioritiesSql})`)).addColumn("title", "text", (column) => column.notNull()).addColumn("summary", "text").addColumn("details", "text").addColumn("assigned_by_actor_type", "text", (column) => column.notNull().check(sql`assigned_by_actor_type in (${actorTypesSql})`)).addColumn("assigned_by_actor_id", "text", (column) => column.notNull()).addColumn("assigned_to_actor_type", "text", (column) => column.check(sql`assigned_to_actor_type is null or assigned_to_actor_type in (${actorTypesSql})`)).addColumn("assigned_to_actor_id", "text").addColumn("metadata", "text", (column) => column.notNull().defaultTo("{}")).addColumn("related_handoff_snapshot_id", "text", (column) => column.references("_dineway_handoff_snapshots.id").onDelete("set null")).addColumn("related_hitl_request_id", "text", (column) => column.references("_dineway_hitl_requests.id").onDelete("set null")).addColumn("due_at", "text").addColumn("created_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (column) => column.notNull().defaultTo(currentTimestamp$1(db))).addColumn("accepted_at", "text").addColumn("started_at", "text").addColumn("blocked_at", "text").addColumn("completed_at", "text").addColumn("declined_at", "text").addColumn("cancelled_at", "text");
7193
+ if (includeOverdue) builder = builder.addColumn("overdue_at", "text");
7194
+ await builder.execute();
7195
+ }
7196
+ async function createAssignmentIndexes(db) {
7197
+ await db.schema.createIndex("idx_dineway_assignment_status_created").on("_dineway_assignments").columns(["status", "created_at"]).execute();
7198
+ await db.schema.createIndex("idx_dineway_assignment_scope_status").on("_dineway_assignments").columns([
7199
+ "scope",
7200
+ "status",
7201
+ "created_at"
7202
+ ]).execute();
7203
+ await db.schema.createIndex("idx_dineway_assignment_type_status").on("_dineway_assignments").columns([
7204
+ "assignment_type",
7205
+ "status",
7206
+ "created_at"
7207
+ ]).execute();
7208
+ await db.schema.createIndex("idx_dineway_assignment_assigned_to").on("_dineway_assignments").columns([
7209
+ "assigned_to_actor_type",
7210
+ "assigned_to_actor_id",
7211
+ "status",
7212
+ "created_at"
7213
+ ]).execute();
7214
+ await db.schema.createIndex("idx_dineway_assignment_assigned_by").on("_dineway_assignments").columns([
7215
+ "assigned_by_actor_type",
7216
+ "assigned_by_actor_id",
7217
+ "status",
7218
+ "created_at"
7219
+ ]).execute();
7220
+ await db.schema.createIndex("idx_dineway_assignment_priority_created").on("_dineway_assignments").columns(["priority", "created_at"]).execute();
7221
+ await db.schema.createIndex("idx_dineway_assignment_due_at").on("_dineway_assignments").column("due_at").execute();
7222
+ await db.schema.createIndex("idx_dineway_assignment_handoff").on("_dineway_assignments").column("related_handoff_snapshot_id").execute();
7223
+ await db.schema.createIndex("idx_dineway_assignment_hitl").on("_dineway_assignments").column("related_hitl_request_id").execute();
7224
+ }
7225
+ async function replacePostgresStatusConstraint(db, statuses) {
7226
+ const constraints = await sql`
7227
+ SELECT constraint_record.conname
7228
+ FROM pg_constraint AS constraint_record
7229
+ WHERE constraint_record.conrelid = '_dineway_assignments'::regclass
7230
+ AND constraint_record.contype = 'c'
7231
+ AND pg_get_constraintdef(constraint_record.oid) ILIKE '%status%'
7232
+ `.execute(db);
7233
+ for (const constraint of constraints.rows) await sql`
7234
+ ALTER TABLE ${sql.ref("_dineway_assignments")}
7235
+ DROP CONSTRAINT ${sql.ref(constraint.conname)}
7236
+ `.execute(db);
7237
+ const statusesSql = sql.join(statuses.map((value) => sql.lit(value)), sql`, `);
7238
+ await sql`
7239
+ ALTER TABLE ${sql.ref("_dineway_assignments")}
7240
+ ADD CONSTRAINT ${sql.ref("ck_dineway_assignment_status")}
7241
+ CHECK (status in (${statusesSql}))
7242
+ `.execute(db);
7243
+ }
7244
+
7245
+ //#endregion
7246
+ //#region src/database/migrations/115_integration_credentials.ts
7247
+ var _115_integration_credentials_exports = /* @__PURE__ */ __exportAll({
7248
+ down: () => down,
7249
+ up: () => up
7250
+ });
7251
+ async function up(db) {
7252
+ await db.schema.createTable("_dineway_integration_credentials").addColumn("provider", "text", (col) => col.primaryKey()).addColumn("credential_type", "text", (col) => col.notNull()).addColumn("encryption_version", "integer", (col) => col.notNull()).addColumn("key_id", "text", (col) => col.notNull()).addColumn("nonce", "text", (col) => col.notNull()).addColumn("ciphertext", "text", (col) => col.notNull()).addColumn("fingerprint", "text", (col) => col.notNull()).addColumn("source", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp$1(db))).execute();
7253
+ await db.schema.createIndex("idx_dineway_integration_credentials_updated_at").on("_dineway_integration_credentials").column("updated_at").execute();
7254
+ }
7255
+ async function down(db) {
7256
+ await db.schema.dropTable("_dineway_integration_credentials").execute();
7257
+ }
7258
+
6547
7259
  //#endregion
6548
7260
  //#region src/database/migrations/runner.ts
6549
7261
  const MIGRATIONS = Object.freeze({
@@ -6651,7 +7363,14 @@ const MIGRATIONS = Object.freeze({
6651
7363
  "103_restaurant_reservation_guest_details": _103_restaurant_reservation_guest_details_exports,
6652
7364
  "104_restaurant_reservation_quote_guest_details": _104_restaurant_reservation_quote_guest_details_exports,
6653
7365
  "105_restaurant_reservation_language_settings": _105_restaurant_reservation_language_settings_exports,
6654
- "106_restaurant_reservation_analytics": _106_restaurant_reservation_analytics_exports
7366
+ "106_restaurant_reservation_analytics": _106_restaurant_reservation_analytics_exports,
7367
+ "107_payment_stripe_configuration": _107_payment_stripe_configuration_exports,
7368
+ "108_venue_foundation": _108_venue_foundation_exports,
7369
+ "109_venue_commercial_lifecycle": _109_venue_commercial_lifecycle_exports,
7370
+ "110_venue_communications_reviews": _110_venue_communications_reviews_exports,
7371
+ "111_content_release_grants": _111_content_release_grants_exports,
7372
+ "114_assignment_overdue": _114_assignment_overdue_exports,
7373
+ "115_integration_credentials": _115_integration_credentials_exports
6655
7374
  });
6656
7375
  const MIGRATION_NAMES = Object.freeze(Object.keys(MIGRATIONS).toSorted());
6657
7376
  /** Total number of registered migrations. Exported for use in tests. */