@myrialabs/clopen 0.4.49 → 0.4.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/backend/chat/attachments.test.ts +106 -17
- package/backend/chat/attachments.ts +131 -34
- package/backend/chat/background-wait.test.ts +28 -0
- package/backend/chat/engine-handoff.ts +42 -6
- package/backend/chat/message-pages.test.ts +17 -0
- package/backend/chat/message-pages.ts +6 -2
- package/backend/chat/stream-manager.ts +114 -19
- package/backend/containers/actions.ts +22 -0
- package/backend/control/actions/projects.ts +93 -37
- package/backend/control/folders.test.ts +27 -2
- package/backend/control/index.ts +2 -1
- package/backend/database/migrations/056_support_mssql_driver.ts +7 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +7 -0
- package/backend/database/migrations/086_single_owner.ts +66 -73
- package/backend/database/migrations/088_create_messages_fts_map.ts +52 -0
- package/backend/database/migrations/089_add_memory_layout_tiles.ts +58 -0
- package/backend/database/migrations/090_create_storage_tables.ts +83 -0
- package/backend/database/migrations/index.ts +25 -2
- package/backend/database/queries/graph-queries.ts +392 -135
- package/backend/database/queries/integration-queries.ts +10 -0
- package/backend/database/queries/memory-queue-queries.ts +11 -0
- package/backend/database/queries/message-fts.test.ts +120 -0
- package/backend/database/queries/message-queries.ts +45 -9
- package/backend/database/queries/project-queries.ts +6 -0
- package/backend/database/queries/session-queries.ts +6 -2
- package/backend/database/queries/utils-queries.ts +3 -0
- package/backend/database/utils/migration-runner.test.ts +196 -0
- package/backend/database/utils/migration-runner.ts +61 -16
- package/backend/database/utils/seeder-runner.ts +22 -16
- package/backend/engine/adapters/claude/environment.ts +4 -0
- package/backend/engine/adapters/claude/input-gate.test.ts +59 -0
- package/backend/engine/adapters/claude/input-gate.ts +74 -0
- package/backend/engine/adapters/claude/message-converter.test.ts +16 -0
- package/backend/engine/adapters/claude/message-converter.ts +8 -0
- package/backend/engine/adapters/claude/stream.ts +20 -0
- package/backend/engine/adapters/cursor/environment.ts +1 -1
- package/backend/engine/adapters/qwen/session-store.ts +10 -1
- package/backend/engine/types.ts +7 -0
- package/backend/git/identity/cli.ts +35 -0
- package/backend/git/identity/env.test.ts +52 -1
- package/backend/git/identity/env.ts +69 -10
- package/backend/git/identity/index.ts +25 -6
- package/backend/git/identity/resolve.ts +2 -1
- package/backend/git/identity/scope-config.test.ts +7 -4
- package/backend/git/identity/scope-config.ts +13 -7
- package/backend/git-hosts/accounts.ts +106 -0
- package/backend/git-hosts/auth/client-ids.ts +34 -0
- package/backend/git-hosts/auth/connect.ts +110 -0
- package/backend/git-hosts/auth/endpoints.ts +130 -0
- package/backend/git-hosts/auth/flows.ts +355 -0
- package/backend/git-hosts/auth/local.ts +152 -0
- package/backend/git-hosts/ci.ts +18 -0
- package/backend/git-hosts/cli.test.ts +82 -0
- package/backend/git-hosts/cli.ts +342 -0
- package/backend/git-hosts/credentials.ts +173 -0
- package/backend/git-hosts/git-credential.ts +30 -0
- package/backend/git-hosts/health.ts +39 -0
- package/backend/git-hosts/http.ts +174 -0
- package/backend/git-hosts/index.ts +34 -0
- package/backend/git-hosts/providers/bitbucket.ts +186 -0
- package/backend/git-hosts/providers/gitea.ts +208 -0
- package/backend/git-hosts/providers/github.ts +270 -0
- package/backend/git-hosts/providers/gitlab-client.ts +70 -0
- package/backend/git-hosts/providers/gitlab.ts +285 -0
- package/backend/git-hosts/providers/locators.test.ts +68 -0
- package/backend/git-hosts/registry.ts +50 -0
- package/backend/git-hosts/service.ts +432 -0
- package/backend/git-hosts/types.ts +82 -0
- package/backend/git-hosts/urls.test.ts +42 -0
- package/backend/git-hosts/urls.ts +69 -0
- package/backend/index.ts +84 -17
- package/backend/integrations/accounts.ts +50 -3
- package/backend/integrations/registry/define.ts +9 -0
- package/backend/integrations/registry/index.ts +11 -0
- package/backend/integrations/registry/providers/bitbucket.ts +51 -0
- package/backend/integrations/registry/providers/gitea.ts +53 -0
- package/backend/integrations/registry/providers/github.ts +24 -7
- package/backend/integrations/registry/providers/gitlab.ts +57 -0
- package/backend/integrations/registry/types.ts +13 -1
- package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +115 -31
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -0
- package/backend/memory/README.md +7 -4
- package/backend/memory/layout.test.ts +377 -0
- package/backend/memory/layout.ts +1029 -265
- package/backend/memory/view.ts +257 -386
- package/backend/mentions/diff.ts +63 -0
- package/backend/mentions/index.ts +109 -0
- package/backend/mentions/mentions.test.ts +27 -0
- package/backend/mentions/shared.ts +82 -0
- package/backend/mentions/sources/ai-changes.ts +140 -0
- package/backend/mentions/sources/chats.ts +122 -0
- package/backend/mentions/sources/database.ts +211 -0
- package/backend/mentions/sources/files.ts +240 -0
- package/backend/mentions/sources/git.ts +308 -0
- package/backend/mentions/sources/notes-memory.ts +121 -0
- package/backend/mentions/sources/ops.ts +125 -0
- package/backend/mentions/sources/preview.ts +153 -0
- package/backend/mentions/sources/projects.ts +114 -0
- package/backend/mentions/sources/system.ts +135 -0
- package/backend/mentions/sources/terminal.ts +50 -0
- package/backend/mentions/types.ts +75 -0
- package/backend/preview/browser/bot-check-frames.test.ts +49 -0
- package/backend/preview/browser/bot-check-frames.ts +66 -0
- package/backend/preview/browser/browser-dialog-handler.ts +6 -5
- package/backend/preview/browser/browser-host-bridge.ts +4 -2
- package/backend/preview/browser/browser-native-ui-handler.ts +21 -0
- package/backend/preview/browser/browser-pool.ts +26 -17
- package/backend/preview/browser/browser-preview-service.ts +164 -2
- package/backend/preview/browser/browser-screenshot.test.ts +113 -0
- package/backend/preview/browser/browser-screenshot.ts +396 -0
- package/backend/preview/browser/browser-tab-manager.ts +35 -186
- package/backend/preview/browser/browser-video-capture.ts +12 -17
- package/backend/preview/browser/element-describe.ts +125 -0
- package/backend/preview/browser/page-binding.ts +141 -0
- package/backend/preview/browser/screenshot-files.test.ts +117 -0
- package/backend/preview/browser/screenshot-files.ts +134 -0
- package/backend/preview/browser/user-agent.test.ts +25 -0
- package/backend/preview/browser/user-agent.ts +100 -0
- package/backend/project/status-manager.ts +4 -2
- package/backend/projects/engine-transcripts.ts +153 -0
- package/backend/projects/folder-guard.ts +55 -0
- package/backend/projects/move.test.ts +208 -0
- package/backend/projects/move.ts +277 -0
- package/backend/projects/project-cleanup.integration.test.ts +3 -1
- package/backend/projects/project-cleanup.ts +10 -0
- package/backend/storage/actions.ts +260 -0
- package/backend/storage/chats.test.ts +57 -0
- package/backend/storage/chats.ts +170 -0
- package/backend/storage/database.ts +105 -0
- package/backend/storage/engine-homes.ts +145 -0
- package/backend/storage/fs-size.ts +111 -0
- package/backend/storage/history.ts +39 -0
- package/backend/storage/policy.ts +156 -0
- package/backend/storage/preview-profiles.ts +169 -0
- package/backend/storage/purge.ts +158 -0
- package/backend/storage/scanner.ts +339 -0
- package/backend/storage/session-index.ts +208 -0
- package/backend/storage/snapshots.ts +99 -0
- package/backend/storage/storage-flow.test.ts +137 -0
- package/backend/storage/transcripts/aliases.ts +75 -0
- package/backend/storage/transcripts/claude-dedupe.test.ts +101 -0
- package/backend/storage/transcripts/claude-dedupe.ts +152 -0
- package/backend/storage/transcripts/claude.ts +155 -0
- package/backend/storage/transcripts/cursor.ts +165 -0
- package/backend/storage/transcripts/file-stores.ts +224 -0
- package/backend/storage/transcripts/index.ts +207 -0
- package/backend/storage/transcripts/opencode.ts +124 -0
- package/backend/storage/transcripts/references.ts +42 -0
- package/backend/storage/transcripts/types.ts +58 -0
- package/backend/storage/worktrees.ts +114 -0
- package/backend/terminal/ptykit.ts +25 -0
- package/backend/update/registry.ts +24 -0
- package/backend/update/release-notes.test.ts +110 -0
- package/backend/update/release-notes.ts +132 -0
- package/backend/update/restart.ts +159 -0
- package/backend/utils/env.test.ts +64 -0
- package/backend/utils/env.ts +23 -55
- package/backend/utils/port-utils.ts +13 -0
- package/backend/work/index.ts +13 -2
- package/backend/work/providers/github/actions-logs.ts +1 -1
- package/backend/work/providers/github/adapter.ts +32 -1
- package/backend/work/providers/github/client.ts +7 -3
- package/backend/work/providers/gitlab/adapter.ts +770 -0
- package/backend/work/providers/gitlab/system-notes.test.ts +24 -0
- package/backend/work/service.ts +60 -36
- package/backend/work/start-work.ts +1 -1
- package/backend/work/types.ts +4 -0
- package/backend/worktrees/index.ts +1 -0
- package/backend/worktrees/service.ts +23 -2
- package/backend/ws/chat/composer.ts +47 -6
- package/backend/ws/chat/stream.ts +19 -10
- package/backend/ws/files/search.ts +1 -1
- package/backend/ws/files/write.ts +27 -0
- package/backend/ws/hosting/index.ts +231 -0
- package/backend/ws/index.ts +12 -2
- package/backend/ws/integrations/crud.ts +31 -5
- package/backend/ws/integrations/hosting-auth.ts +227 -0
- package/backend/ws/integrations/index.ts +2 -0
- package/backend/ws/memory/crud.ts +118 -81
- package/backend/ws/mentions/index.ts +81 -0
- package/backend/ws/messages/crud.ts +3 -1
- package/backend/ws/preview/browser/screenshot.ts +184 -0
- package/backend/ws/preview/index.ts +23 -0
- package/backend/ws/projects/crud.ts +66 -58
- package/backend/ws/sessions/crud.ts +7 -95
- package/backend/ws/snapshot/changes.ts +3 -3
- package/backend/ws/storage/index.ts +102 -0
- package/backend/ws/system/index.ts +7 -0
- package/backend/ws/system/operations.ts +125 -69
- package/backend/ws/work/context.ts +3 -4
- package/backend/ws/work/crud.ts +33 -0
- package/backend/ws/work/schemas.ts +4 -1
- package/bin/clopen.ts +18 -18
- package/dist/assets/{index-DD0-3EWg.js → index-B9rHDvjg.js} +1 -1
- package/dist/assets/index-B9rHDvjg.js.br +0 -0
- package/dist/assets/index-B9rHDvjg.js.gz +0 -0
- package/dist/assets/{index-CrVWZH_D.js → index-DFlwOd7k.js} +1 -1
- package/dist/assets/index-DFlwOd7k.js.br +0 -0
- package/dist/assets/index-DFlwOd7k.js.gz +0 -0
- package/dist/assets/main-Bz_brxxS.css +1 -0
- package/dist/assets/main-Bz_brxxS.css.br +0 -0
- package/dist/assets/main-Bz_brxxS.css.gz +0 -0
- package/dist/assets/main-DRcX9SHx.js +1273 -0
- package/dist/assets/main-DRcX9SHx.js.br +0 -0
- package/dist/assets/main-DRcX9SHx.js.gz +0 -0
- package/dist/assets/pdf-DfwfQPLy.js +57 -0
- package/dist/assets/pdf-DfwfQPLy.js.br +0 -0
- package/dist/assets/pdf-DfwfQPLy.js.gz +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.br +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.gz +0 -0
- package/dist/assets/pdf.worker.min-BOrSNwfp.js +1 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-H.bcmap +6 -0
- package/dist/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/LICENSE +36 -0
- package/dist/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/dist/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
- package/dist/vendor/pdfjs/iccs/LICENSE +116 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QUICKJS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QUICKJS +22 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js +16 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.gz +0 -0
- package/package.json +8 -9
- package/scripts/start.ts +21 -4
- package/shared/constants/binary-extensions.ts +20 -4
- package/shared/constants/support.test.ts +27 -0
- package/shared/constants/support.ts +79 -0
- package/shared/constants/tool-icons.ts +7 -1
- package/shared/types/database/schema.ts +6 -0
- package/shared/types/git-hosting.ts +241 -0
- package/shared/types/integrations.ts +51 -1
- package/shared/types/memory.ts +96 -73
- package/shared/types/mentions.ts +96 -0
- package/shared/types/release-notes.ts +31 -0
- package/shared/types/storage.ts +175 -0
- package/shared/types/stores/settings.ts +16 -0
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +26 -1
- package/shared/types/unified/stream.ts +22 -1
- package/shared/types/unified/tool.ts +4 -0
- package/shared/types/work.ts +6 -0
- package/shared/utils/attachment-mentions.test.ts +39 -0
- package/shared/utils/attachment-mentions.ts +100 -0
- package/shared/utils/context-document.test.ts +53 -0
- package/shared/utils/context-document.ts +226 -0
- package/shared/utils/device-frame.test.ts +73 -0
- package/shared/utils/device-frame.ts +320 -0
- package/shared/utils/fuzzy.ts +79 -0
- package/shared/utils/launcher-fingerprint.test.ts +73 -0
- package/shared/utils/launcher-fingerprint.ts +108 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/page-colors.test.ts +17 -0
- package/shared/utils/page-colors.ts +24 -0
- package/shared/utils/process-supervisor.test.ts +88 -1
- package/shared/utils/process-supervisor.ts +123 -29
- package/shared/utils/process-tree.ts +99 -0
- package/shared/utils/restart-intent.test.ts +57 -0
- package/shared/utils/restart-intent.ts +80 -0
- package/shared/utils/semver.test.ts +33 -0
- package/shared/utils/semver.ts +35 -0
- package/shared/utils/supervised-child.ts +44 -0
- package/shared/utils/supervisor-protocol.ts +20 -0
- package/.env.example +0 -9
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js +0 -1
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
- package/dist/assets/index-CrVWZH_D.js.br +0 -0
- package/dist/assets/index-CrVWZH_D.js.gz +0 -0
- package/dist/assets/index-DD0-3EWg.js.br +0 -0
- package/dist/assets/index-DD0-3EWg.js.gz +0 -0
- package/dist/assets/main-D2_TmcwQ.js +0 -1240
- package/dist/assets/main-D2_TmcwQ.js.br +0 -0
- package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
- package/dist/assets/main-Yucigcmf.css +0 -1
- package/dist/assets/main-Yucigcmf.css.br +0 -0
- package/dist/assets/main-Yucigcmf.css.gz +0 -0
|
@@ -154,6 +154,16 @@ export const integrationAccountQueries = {
|
|
|
154
154
|
);
|
|
155
155
|
},
|
|
156
156
|
|
|
157
|
+
/** Record how the account's credential was obtained — a reconnect can change it. */
|
|
158
|
+
setAuthMethod(id: string, authMethod: IntegrationAuthMethod): void {
|
|
159
|
+
const db = getDatabase();
|
|
160
|
+
db.prepare(`UPDATE integration_accounts SET auth_method = ?, updated_at = ? WHERE id = ?`).run(
|
|
161
|
+
authMethod,
|
|
162
|
+
new Date().toISOString(),
|
|
163
|
+
id
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
|
|
157
167
|
/**
|
|
158
168
|
* Rename an account.
|
|
159
169
|
*
|
|
@@ -336,6 +336,17 @@ export const memoryQueueQueries = {
|
|
|
336
336
|
return Number(result.changes ?? 0);
|
|
337
337
|
},
|
|
338
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Follow a project to its new folder. Only rows for its main tree change: a
|
|
341
|
+
* turn that ran in a worktree carries the worktree's own path, which a move
|
|
342
|
+
* of the project folder leaves where it is.
|
|
343
|
+
*/
|
|
344
|
+
repointProject(projectId: string, oldPath: string, newPath: string): void {
|
|
345
|
+
getDatabase()
|
|
346
|
+
.prepare(`UPDATE memory_extraction_queue SET project_path = ? WHERE project_id = ? AND project_path = ?`)
|
|
347
|
+
.run(newPath, projectId, oldPath);
|
|
348
|
+
},
|
|
349
|
+
|
|
339
350
|
/** Drop everything queued, for "clear all data" and for tests. */
|
|
340
351
|
clear(): void {
|
|
341
352
|
getDatabase().prepare(`DELETE FROM memory_extraction_queue`).run();
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The messages_fts index stays in step with messages through every write and
|
|
3
|
+
* delete path, and every delete finds its rows through messages_fts_map
|
|
4
|
+
* (by rowid) instead of scanning the index for a message id.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeAll, afterAll } from 'bun:test';
|
|
8
|
+
import { initializeDatabase, closeDatabase, getDatabase } from '$backend/database';
|
|
9
|
+
import { messageQueries, projectQueries, sessionQueries } from '$backend/database/queries';
|
|
10
|
+
import type { UnifiedMessage } from '$shared/types/unified';
|
|
11
|
+
|
|
12
|
+
let projectId: string;
|
|
13
|
+
|
|
14
|
+
const engine = { type: 'claude-code', provider: '', model: { id: '', name: '' }, account: { id: 0, name: '' } };
|
|
15
|
+
const user = (text: string) => ({
|
|
16
|
+
type: 'user',
|
|
17
|
+
createdAt: '',
|
|
18
|
+
messageId: '',
|
|
19
|
+
sessionId: null,
|
|
20
|
+
parent: { messageId: null, sessionId: null, toolUseId: null },
|
|
21
|
+
engine,
|
|
22
|
+
content: [{ type: 'text', text }]
|
|
23
|
+
}) as unknown as UnifiedMessage;
|
|
24
|
+
|
|
25
|
+
function newSession(): string {
|
|
26
|
+
return sessionQueries.create({ project_id: projectId, engine: 'claude-code', started_at: new Date().toISOString() } as never).id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function save(sessionId: string, text: string, timestamp?: string): string {
|
|
30
|
+
return messageQueries.create({ session_id: sessionId, message: user(text), timestamp }).id;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** FTS rows and map rows of a session, plus whether they point at each other. */
|
|
34
|
+
function indexOf(sessionId: string) {
|
|
35
|
+
const db = getDatabase();
|
|
36
|
+
const fts = db.prepare('SELECT rowid, message_id FROM messages_fts WHERE session_id = ?').all(sessionId) as { rowid: number; message_id: string }[];
|
|
37
|
+
const map = db.prepare('SELECT message_id, fts_rowid FROM messages_fts_map WHERE session_id = ?').all(sessionId) as { message_id: string; fts_rowid: number }[];
|
|
38
|
+
const consistent = fts.length === map.length && map.every((m) => fts.some((f) => f.rowid === m.fts_rowid && f.message_id === m.message_id));
|
|
39
|
+
return { fts, map, consistent };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
beforeAll(async () => {
|
|
43
|
+
await initializeDatabase();
|
|
44
|
+
projectId = projectQueries.create({ name: 'message-fts', path: `/tmp/message-fts-${crypto.randomUUID()}`, created_at: new Date().toISOString(), last_opened_at: new Date().toISOString() } as never).id;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterAll(() => {
|
|
48
|
+
sessionQueries.deleteAllByProjectId(projectId);
|
|
49
|
+
projectQueries.deleteProject(projectId);
|
|
50
|
+
closeDatabase();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('messages_fts through messages_fts_map', () => {
|
|
54
|
+
it('indexes a saved message and maps it to its FTS row', () => {
|
|
55
|
+
const session = newSession();
|
|
56
|
+
const id = save(session, 'quokka sunrise');
|
|
57
|
+
const { fts, map, consistent } = indexOf(session);
|
|
58
|
+
expect(fts.map((r) => r.message_id)).toEqual([id]);
|
|
59
|
+
expect(map.map((r) => r.message_id)).toEqual([id]);
|
|
60
|
+
expect(consistent).toBe(true);
|
|
61
|
+
expect(sessionQueries.searchByMessageContent(projectId, 'quokka').map((r) => r.sessionId)).toContain(session);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('leaves no FTS or map row for a message without searchable text', () => {
|
|
65
|
+
const session = newSession();
|
|
66
|
+
save(session, ' ');
|
|
67
|
+
expect(indexOf(session).fts).toHaveLength(0);
|
|
68
|
+
expect(indexOf(session).map).toHaveLength(0);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('removes exactly the deleted message', () => {
|
|
72
|
+
const session = newSession();
|
|
73
|
+
const keep = save(session, 'keep this one');
|
|
74
|
+
const drop = save(session, 'drop this one');
|
|
75
|
+
messageQueries.delete(drop);
|
|
76
|
+
const { fts, consistent } = indexOf(session);
|
|
77
|
+
expect(fts.map((r) => r.message_id)).toEqual([keep]);
|
|
78
|
+
expect(consistent).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('removes messages cut by deleteAfterTimestamp', () => {
|
|
82
|
+
const session = newSession();
|
|
83
|
+
const early = save(session, 'early message', '2026-01-01T00:00:00.000Z');
|
|
84
|
+
save(session, 'late message one', '2026-01-02T00:00:00.000Z');
|
|
85
|
+
save(session, 'late message two', '2026-01-03T00:00:00.000Z');
|
|
86
|
+
messageQueries.deleteAfterTimestamp(session, '2026-01-02T00:00:00.000Z');
|
|
87
|
+
const { fts, consistent } = indexOf(session);
|
|
88
|
+
expect(fts.map((r) => r.message_id)).toEqual([early]);
|
|
89
|
+
expect(consistent).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('removes a whole session, through either delete path', () => {
|
|
93
|
+
const a = newSession();
|
|
94
|
+
const b = newSession();
|
|
95
|
+
save(a, 'session a text');
|
|
96
|
+
save(b, 'session b text');
|
|
97
|
+
messageQueries.deleteBySessionId(a);
|
|
98
|
+
sessionQueries.delete(b);
|
|
99
|
+
expect(indexOf(a).fts).toHaveLength(0);
|
|
100
|
+
expect(indexOf(a).map).toHaveLength(0);
|
|
101
|
+
expect(indexOf(b).fts).toHaveLength(0);
|
|
102
|
+
expect(indexOf(b).map).toHaveLength(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('removes every session of a deleted project, and only those', async () => {
|
|
106
|
+
const otherProject = projectQueries.create({ name: 'message-fts-other', path: `/tmp/message-fts-other-${crypto.randomUUID()}`, created_at: new Date().toISOString(), last_opened_at: new Date().toISOString() } as never).id;
|
|
107
|
+
const other = sessionQueries.create({ project_id: otherProject, engine: 'claude-code', started_at: new Date().toISOString() } as never).id;
|
|
108
|
+
const mine = newSession();
|
|
109
|
+
save(other, 'other project text');
|
|
110
|
+
save(mine, 'my project text');
|
|
111
|
+
|
|
112
|
+
sessionQueries.deleteAllByProjectId(otherProject);
|
|
113
|
+
projectQueries.deleteProject(otherProject);
|
|
114
|
+
|
|
115
|
+
expect(indexOf(other).fts).toHaveLength(0);
|
|
116
|
+
expect(indexOf(other).map).toHaveLength(0);
|
|
117
|
+
expect(indexOf(mine).fts).toHaveLength(1);
|
|
118
|
+
expect(indexOf(mine).consistent).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -26,10 +26,47 @@ function extractSearchableText(msg: UnifiedMessage): string {
|
|
|
26
26
|
.join('\n');
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The messages_fts mirror is written and deleted only through these helpers.
|
|
31
|
+
*
|
|
32
|
+
* FTS5 cannot look a row up by `message_id` (an UNINDEXED column), so a delete
|
|
33
|
+
* by it walked the whole index on every message save — seconds on a large
|
|
34
|
+
* database, on the server's only thread. `messages_fts_map` records each
|
|
35
|
+
* message's FTS rowid, so every delete here is a direct lookup (migration 088).
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/** Remove the FTS rows of the given messages. */
|
|
39
|
+
export function removeMessagesFts(ids: string[]): void {
|
|
40
|
+
if (ids.length === 0) return;
|
|
41
|
+
const db = getDatabase();
|
|
42
|
+
for (let start = 0; start < ids.length; start += 500) {
|
|
43
|
+
const chunk = ids.slice(start, start + 500);
|
|
44
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
45
|
+
db.prepare(`
|
|
46
|
+
DELETE FROM messages_fts
|
|
47
|
+
WHERE rowid IN (SELECT fts_rowid FROM messages_fts_map WHERE message_id IN (${placeholders}))
|
|
48
|
+
`).run(...chunk);
|
|
49
|
+
db.prepare(`DELETE FROM messages_fts_map WHERE message_id IN (${placeholders})`).run(...chunk);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Remove the FTS rows of whole sessions, named by a subquery that returns
|
|
55
|
+
* session ids (e.g. `SELECT id FROM chat_sessions WHERE project_id = ?`).
|
|
56
|
+
*/
|
|
57
|
+
export function removeSessionsFts(sessionIdsQuery: string, ...params: unknown[]): void {
|
|
58
|
+
const db = getDatabase();
|
|
59
|
+
db.prepare(`
|
|
60
|
+
DELETE FROM messages_fts
|
|
61
|
+
WHERE rowid IN (SELECT fts_rowid FROM messages_fts_map WHERE session_id IN (${sessionIdsQuery}))
|
|
62
|
+
`).run(...(params as never[]));
|
|
63
|
+
db.prepare(`DELETE FROM messages_fts_map WHERE session_id IN (${sessionIdsQuery})`).run(...(params as never[]));
|
|
64
|
+
}
|
|
65
|
+
|
|
29
66
|
/** Keep the messages_fts mirror in sync with a message's current text content. */
|
|
30
67
|
function syncMessageFts(id: string, sessionId: string, msg: UnifiedMessage): void {
|
|
31
68
|
const db = getDatabase();
|
|
32
|
-
|
|
69
|
+
removeMessagesFts([id]);
|
|
33
70
|
|
|
34
71
|
const text = extractSearchableText(msg).trim();
|
|
35
72
|
if (!text) return;
|
|
@@ -37,10 +74,12 @@ function syncMessageFts(id: string, sessionId: string, msg: UnifiedMessage): voi
|
|
|
37
74
|
const session = db.prepare('SELECT project_id FROM chat_sessions WHERE id = ?').get(sessionId) as { project_id: string } | null;
|
|
38
75
|
if (!session) return;
|
|
39
76
|
|
|
40
|
-
db.prepare(`
|
|
77
|
+
const inserted = db.prepare(`
|
|
41
78
|
INSERT INTO messages_fts (message_id, session_id, project_id, text)
|
|
42
79
|
VALUES (?, ?, ?, ?)
|
|
43
|
-
`).run(id, sessionId, session.project_id, text);
|
|
80
|
+
`).run(id, sessionId, session.project_id, text) as { lastInsertRowid: number | bigint };
|
|
81
|
+
db.prepare('INSERT OR REPLACE INTO messages_fts_map (message_id, session_id, fts_rowid) VALUES (?, ?, ?)')
|
|
82
|
+
.run(id, sessionId, Number(inserted.lastInsertRowid));
|
|
44
83
|
}
|
|
45
84
|
|
|
46
85
|
export const messageQueries = {
|
|
@@ -194,13 +233,13 @@ export const messageQueries = {
|
|
|
194
233
|
delete(id: string): void {
|
|
195
234
|
const db = getDatabase();
|
|
196
235
|
db.prepare('DELETE FROM messages WHERE id = ?').run(id);
|
|
197
|
-
|
|
236
|
+
removeMessagesFts([id]);
|
|
198
237
|
},
|
|
199
238
|
|
|
200
239
|
deleteBySessionId(sessionId: string): void {
|
|
201
240
|
const db = getDatabase();
|
|
202
241
|
db.prepare('DELETE FROM messages WHERE session_id = ?').run(sessionId);
|
|
203
|
-
|
|
242
|
+
removeSessionsFts('?', sessionId);
|
|
204
243
|
},
|
|
205
244
|
|
|
206
245
|
deleteAfterTimestamp(sessionId: string, timestamp: string): void {
|
|
@@ -214,10 +253,7 @@ export const messageQueries = {
|
|
|
214
253
|
WHERE session_id = ? AND created_at >= ?
|
|
215
254
|
`).run(sessionId, timestamp);
|
|
216
255
|
|
|
217
|
-
|
|
218
|
-
const placeholders = ids.map(() => '?').join(',');
|
|
219
|
-
db.prepare(`DELETE FROM messages_fts WHERE message_id IN (${placeholders})`).run(...ids.map(r => r.id));
|
|
220
|
-
}
|
|
256
|
+
removeMessagesFts(ids.map(r => r.id));
|
|
221
257
|
},
|
|
222
258
|
|
|
223
259
|
/**
|
|
@@ -73,6 +73,12 @@ export const projectQueries = {
|
|
|
73
73
|
`).run(now, id);
|
|
74
74
|
},
|
|
75
75
|
|
|
76
|
+
/** Point a project at another folder. Its name is always its folder's. */
|
|
77
|
+
relocate(id: string, path: string, name: string): void {
|
|
78
|
+
const db = getDatabase();
|
|
79
|
+
db.prepare(`UPDATE projects SET path = ?, name = ? WHERE id = ?`).run(path, name, id);
|
|
80
|
+
},
|
|
81
|
+
|
|
76
82
|
/** The project-wide default profile, or null. */
|
|
77
83
|
getDefaultProfileId(id: string): number | null {
|
|
78
84
|
const db = getDatabase();
|
|
@@ -3,6 +3,7 @@ import type { ChatSession, Branch, DatabaseMessage } from '$shared/types/databas
|
|
|
3
3
|
import { loadMessage } from '$shared/utils/message-formatter';
|
|
4
4
|
import { extractMessageText } from '../../snapshot/helpers';
|
|
5
5
|
import { debug } from '$shared/utils/logger';
|
|
6
|
+
import { removeSessionsFts } from './message-queries';
|
|
6
7
|
|
|
7
8
|
/** ChatSession plus an optional FTS snippet, set only for message-content matches. */
|
|
8
9
|
export interface SessionSearchResult extends ChatSession {
|
|
@@ -156,6 +157,9 @@ export const sessionQueries = {
|
|
|
156
157
|
const sets: string[] = [
|
|
157
158
|
'message_count = COALESCE(message_count, 0) + 1',
|
|
158
159
|
'last_message_at = ?',
|
|
160
|
+
// A slimmed chat that is picked up again is a live chat: its new engine
|
|
161
|
+
// transcripts must be protected like any other (see storage/chats.ts).
|
|
162
|
+
'slimmed_at = NULL',
|
|
159
163
|
];
|
|
160
164
|
const params: (string | number | null)[] = [opts.timestamp];
|
|
161
165
|
|
|
@@ -398,7 +402,7 @@ export const sessionQueries = {
|
|
|
398
402
|
db.prepare('DELETE FROM message_snapshots WHERE session_id = ?').run(id);
|
|
399
403
|
db.prepare('DELETE FROM session_relationships WHERE parent_session_id = ? OR child_session_id = ?').run(id, id);
|
|
400
404
|
db.prepare('DELETE FROM messages WHERE session_id = ?').run(id);
|
|
401
|
-
|
|
405
|
+
removeSessionsFts('?', id);
|
|
402
406
|
db.prepare('DELETE FROM unread_sessions WHERE session_id = ?').run(id);
|
|
403
407
|
// Clear current_session_id references in workspace_projects
|
|
404
408
|
db.prepare('UPDATE workspace_projects SET current_session_id = NULL WHERE current_session_id = ?').run(id);
|
|
@@ -426,7 +430,7 @@ export const sessionQueries = {
|
|
|
426
430
|
OR child_session_id IN (SELECT id FROM chat_sessions WHERE project_id = ?)
|
|
427
431
|
`).run(projectId, projectId);
|
|
428
432
|
db.prepare('DELETE FROM messages WHERE session_id IN (SELECT id FROM chat_sessions WHERE project_id = ?)').run(projectId);
|
|
429
|
-
|
|
433
|
+
removeSessionsFts('SELECT id FROM chat_sessions WHERE project_id = ?', projectId);
|
|
430
434
|
db.prepare('DELETE FROM unread_sessions WHERE project_id = ?').run(projectId);
|
|
431
435
|
// Clear current_session_id references in workspace_projects for this project
|
|
432
436
|
db.prepare('UPDATE workspace_projects SET current_session_id = NULL WHERE project_id = ?').run(projectId);
|
|
@@ -2,6 +2,8 @@ import { getDatabase } from '../index';
|
|
|
2
2
|
import type { DatabaseMessage } from '$shared/types/database/schema';
|
|
3
3
|
|
|
4
4
|
import { debug } from '$shared/utils/logger';
|
|
5
|
+
import { removeSessionsFts } from './message-queries';
|
|
6
|
+
|
|
5
7
|
export const dbUtils = {
|
|
6
8
|
// Get dashboard statistics
|
|
7
9
|
getStats(): {
|
|
@@ -51,6 +53,7 @@ export const dbUtils = {
|
|
|
51
53
|
|
|
52
54
|
for (const session of oldSessions) {
|
|
53
55
|
db.prepare('DELETE FROM messages WHERE session_id = ?').run(session.id);
|
|
56
|
+
removeSessionsFts('?', session.id);
|
|
54
57
|
db.prepare('DELETE FROM chat_sessions WHERE id = ?').run(session.id);
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migrations either happen completely or not at all, so a start that is
|
|
3
|
+
* interrupted halfway — a crash, Ctrl+C, a restart from the UI — leaves a
|
|
4
|
+
* schema the next start can still migrate.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from 'bun:test';
|
|
8
|
+
import { Database } from 'bun:sqlite';
|
|
9
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
12
|
+
import { MigrationRunner, type Migration } from './migration-runner';
|
|
13
|
+
import { migrations } from '../migrations';
|
|
14
|
+
|
|
15
|
+
/** As production opens it (backend/database/utils/connection.ts). */
|
|
16
|
+
function freshDb(): Database {
|
|
17
|
+
const db = new Database(':memory:');
|
|
18
|
+
db.exec('PRAGMA foreign_keys = ON');
|
|
19
|
+
return db;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function runner(db: Database, list: Migration[]): MigrationRunner {
|
|
23
|
+
const migrationRunner = new MigrationRunner(db as unknown as DatabaseConnection);
|
|
24
|
+
for (const migration of list) migrationRunner.addMigration(migration);
|
|
25
|
+
return migrationRunner;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function tableExists(db: Database, name: string): boolean {
|
|
29
|
+
return !!db.query(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`).get(name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('MigrationRunner', () => {
|
|
33
|
+
test('every migration runs on an empty database', async () => {
|
|
34
|
+
const db = freshDb();
|
|
35
|
+
const migrationRunner = runner(db, migrations as Migration[]);
|
|
36
|
+
await migrationRunner.runMigrations();
|
|
37
|
+
expect(migrationRunner.getPendingMigrations()).toEqual([]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('a migration that fails halfway leaves nothing behind, and runs again next time', async () => {
|
|
41
|
+
const db = freshDb();
|
|
42
|
+
let fail = true;
|
|
43
|
+
const migration: Migration = {
|
|
44
|
+
id: '001',
|
|
45
|
+
description: 'two steps',
|
|
46
|
+
up: (conn) => {
|
|
47
|
+
conn.exec('CREATE TABLE first_step (id TEXT)');
|
|
48
|
+
if (fail) throw new Error('interrupted');
|
|
49
|
+
conn.exec('CREATE TABLE second_step (id TEXT)');
|
|
50
|
+
},
|
|
51
|
+
down: () => {}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
await expect(runner(db, [migration]).runMigrations()).rejects.toThrow('interrupted');
|
|
55
|
+
expect(tableExists(db, 'first_step')).toBe(false);
|
|
56
|
+
expect(runner(db, [migration]).getExecutedMigrations()).toEqual([]);
|
|
57
|
+
|
|
58
|
+
fail = false;
|
|
59
|
+
await runner(db, [migration]).runMigrations();
|
|
60
|
+
expect(tableExists(db, 'first_step')).toBe(true);
|
|
61
|
+
expect(tableExists(db, 'second_step')).toBe(true);
|
|
62
|
+
expect(runner(db, [migration]).getExecutedMigrations()).toEqual(['001']);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('a table rebuild with foreignKeysOff keeps the rows that reference the table', async () => {
|
|
66
|
+
const seeded = () => {
|
|
67
|
+
const db = freshDb();
|
|
68
|
+
db.exec('CREATE TABLE parent (id TEXT PRIMARY KEY, kind TEXT)');
|
|
69
|
+
db.exec('CREATE TABLE child (id TEXT PRIMARY KEY, parent_id TEXT REFERENCES parent(id) ON DELETE CASCADE)');
|
|
70
|
+
db.exec(`INSERT INTO parent VALUES ('p1', 'a')`);
|
|
71
|
+
db.exec(`INSERT INTO child VALUES ('c1', 'p1')`);
|
|
72
|
+
return db;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const rebuild = (foreignKeysOff: boolean): Migration => ({
|
|
76
|
+
id: '001',
|
|
77
|
+
description: 'rebuild parent',
|
|
78
|
+
foreignKeysOff,
|
|
79
|
+
up: (conn) => {
|
|
80
|
+
conn.exec('CREATE TABLE parent_new (id TEXT PRIMARY KEY, kind TEXT NOT NULL)');
|
|
81
|
+
conn.exec('INSERT INTO parent_new SELECT id, kind FROM parent');
|
|
82
|
+
conn.exec('DROP TABLE parent');
|
|
83
|
+
conn.exec('ALTER TABLE parent_new RENAME TO parent');
|
|
84
|
+
},
|
|
85
|
+
down: () => {}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Why the flag exists: with foreign keys on, dropping the old table
|
|
89
|
+
// cascade-deletes the children.
|
|
90
|
+
const unsafe = seeded();
|
|
91
|
+
await runner(unsafe, [rebuild(false)]).runMigrations();
|
|
92
|
+
expect(unsafe.query('SELECT id FROM child').all()).toEqual([]);
|
|
93
|
+
|
|
94
|
+
const db = seeded();
|
|
95
|
+
await runner(db, [rebuild(true)]).runMigrations();
|
|
96
|
+
expect(db.query('SELECT id FROM child').all()).toEqual([{ id: 'c1' }]);
|
|
97
|
+
// And foreign keys are enforced again afterwards.
|
|
98
|
+
expect((db.query('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys).toBe(1);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('a rebuild that fails with foreignKeysOff rolls back and turns foreign keys back on', async () => {
|
|
102
|
+
const db = freshDb();
|
|
103
|
+
const migration: Migration = {
|
|
104
|
+
id: '001',
|
|
105
|
+
description: 'fails',
|
|
106
|
+
foreignKeysOff: true,
|
|
107
|
+
up: (conn) => {
|
|
108
|
+
conn.exec('CREATE TABLE half (id TEXT)');
|
|
109
|
+
throw new Error('interrupted');
|
|
110
|
+
},
|
|
111
|
+
down: () => {}
|
|
112
|
+
};
|
|
113
|
+
await expect(runner(db, [migration]).runMigrations()).rejects.toThrow('interrupted');
|
|
114
|
+
expect(tableExists(db, 'half')).toBe(false);
|
|
115
|
+
expect((db.query('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys).toBe(1);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('migration sources', () => {
|
|
120
|
+
const dir = join(import.meta.dir, '../migrations');
|
|
121
|
+
const files = readdirSync(dir).filter(file => /^\d{3}_.*\.ts$/.test(file) && !file.endsWith('.test.ts'));
|
|
122
|
+
|
|
123
|
+
const TURNS_OFF_FOREIGN_KEYS = /PRAGMA\s+foreign_keys\s*=\s*OFF/i;
|
|
124
|
+
const OPENS_TRANSACTION = /exec\(\s*['"`]\s*(BEGIN|COMMIT|ROLLBACK)\b/i;
|
|
125
|
+
|
|
126
|
+
test.each(files)('%s declares foreignKeysOff exactly when its SQL turns them off', (file) => {
|
|
127
|
+
const source = readFileSync(join(dir, file), 'utf-8');
|
|
128
|
+
const entry = (migrations as Migration[]).find(migration => migration.id === file.slice(0, 3));
|
|
129
|
+
expect(entry).toBeDefined();
|
|
130
|
+
expect(!!entry!.foreignKeysOff).toBe(TURNS_OFF_FOREIGN_KEYS.test(source));
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test.each(files)('%s leaves the transaction to the runner', (file) => {
|
|
134
|
+
// A migration's own BEGIN fails inside the runner's, and its own COMMIT
|
|
135
|
+
// would separate the change from its record again.
|
|
136
|
+
expect(OPENS_TRANSACTION.test(readFileSync(join(dir, file), 'utf-8'))).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The migrations that did not use to be wrapped, run over data rather than an
|
|
142
|
+
* empty database: the rebuild in 056 must keep the rows that cascade from the
|
|
143
|
+
* table it rebuilds, and 086 must still reduce two accounts to the owner.
|
|
144
|
+
*/
|
|
145
|
+
describe('existing migrations over data', () => {
|
|
146
|
+
async function migratedTo(lastBefore: string): Promise<Database> {
|
|
147
|
+
const db = freshDb();
|
|
148
|
+
await runner(db, (migrations as Migration[]).filter(migration => migration.id < lastBefore)).runMigrations();
|
|
149
|
+
return db;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Insert a row, filling the NOT NULL columns the test does not care about. */
|
|
153
|
+
function insert(db: Database, table: string, values: Record<string, string | null>): void {
|
|
154
|
+
const columns = db.query(`PRAGMA table_info(${table})`).all() as { name: string; notnull: number; dflt_value: unknown; pk: number }[];
|
|
155
|
+
const row: Record<string, string | null> = { ...values };
|
|
156
|
+
for (const column of columns) {
|
|
157
|
+
if (!column.notnull || column.dflt_value !== null || column.pk || column.name in row) continue;
|
|
158
|
+
row[column.name] = column.name.endsWith('_at') ? new Date().toISOString() : `${table}-${column.name}`;
|
|
159
|
+
}
|
|
160
|
+
const keys = Object.keys(row);
|
|
161
|
+
db.prepare(`INSERT INTO ${table} (${keys.join(', ')}) VALUES (${keys.map(() => '?').join(', ')})`).run(...keys.map(key => row[key]));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function migrateRest(db: Database): Promise<void> {
|
|
165
|
+
const migrationRunner = runner(db, migrations as Migration[]);
|
|
166
|
+
await migrationRunner.runMigrations();
|
|
167
|
+
expect(migrationRunner.getPendingMigrations()).toEqual([]);
|
|
168
|
+
expect((db.query('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys).toBe(1);
|
|
169
|
+
expect(db.query('PRAGMA foreign_key_check').all()).toEqual([]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
test('056 keeps the query history of the connection table it rebuilds', async () => {
|
|
173
|
+
const db = await migratedTo('056');
|
|
174
|
+
insert(db, 'db_client_connections', { id: 'c1', name: 'pg', driver: 'postgres' });
|
|
175
|
+
insert(db, 'db_client_query_history', { id: 'h1', connection_id: 'c1', status: 'success' });
|
|
176
|
+
|
|
177
|
+
await migrateRest(db);
|
|
178
|
+
expect(db.query('SELECT id FROM db_client_connections').all()).toEqual([{ id: 'c1' }]);
|
|
179
|
+
expect(db.query('SELECT id FROM db_client_query_history').all()).toEqual([{ id: 'h1' }]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('086 reduces two accounts to the owner and keeps the chats', async () => {
|
|
183
|
+
const db = await migratedTo('086');
|
|
184
|
+
insert(db, 'users', { id: 'owner', role: 'admin', created_at: '2020-01-01T00:00:00Z' });
|
|
185
|
+
insert(db, 'users', { id: 'member', role: 'member', created_at: '2021-01-01T00:00:00Z' });
|
|
186
|
+
insert(db, 'projects', { id: 'p1', name: 'Repo', path: '/tmp/clopen-migration-test-repo', kind: 'project', owner_user_id: null });
|
|
187
|
+
insert(db, 'chat_sessions', { id: 's1', project_id: 'p1' });
|
|
188
|
+
insert(db, 'auth_sessions', { id: 'a-member', user_id: 'member', token_hash: 'h-member' });
|
|
189
|
+
insert(db, 'auth_sessions', { id: 'a-owner', user_id: 'owner', token_hash: 'h-owner' });
|
|
190
|
+
|
|
191
|
+
await migrateRest(db);
|
|
192
|
+
expect(db.query('SELECT id FROM users').all()).toEqual([{ id: 'owner' }]);
|
|
193
|
+
expect(db.query('SELECT id FROM auth_sessions').all()).toEqual([{ id: 'a-owner' }]);
|
|
194
|
+
expect(db.query('SELECT id FROM chat_sessions').all()).toEqual([{ id: 's1' }]);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -1,11 +1,58 @@
|
|
|
1
1
|
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
2
|
|
|
3
3
|
import { debug } from '$shared/utils/logger';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
export interface Migration {
|
|
5
6
|
id: string;
|
|
6
7
|
description: string;
|
|
7
8
|
up: (db: DatabaseConnection) => void;
|
|
8
9
|
down: (db: DatabaseConnection) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Run with foreign keys off, for a migration that rebuilds a table (SQLite
|
|
12
|
+
* cannot alter a constraint in place). Dropping the old table with foreign
|
|
13
|
+
* keys on would cascade-delete every row that references it. The pragma is
|
|
14
|
+
* a no-op inside a transaction, so the migration cannot switch it itself —
|
|
15
|
+
* the runner switches it before opening the transaction and back after,
|
|
16
|
+
* the order SQLite documents for a table rebuild. migration-runner.test.ts
|
|
17
|
+
* keeps this flag in agreement with each migration's SQL.
|
|
18
|
+
*/
|
|
19
|
+
foreignKeysOff?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Run `step` so that it either happens completely or not at all — a
|
|
24
|
+
* migration with its record, or a seeder with its record.
|
|
25
|
+
*
|
|
26
|
+
* A migration that stopped halfway — a crash, an error, Ctrl+C, a restart —
|
|
27
|
+
* used to leave its first statements applied and itself unrecorded, so the
|
|
28
|
+
* next start ran it again over a half-changed schema and failed for good
|
|
29
|
+
* ("table already exists"). Inside one transaction with its record, an
|
|
30
|
+
* interrupted migration simply has not happened, and the next start does it.
|
|
31
|
+
*/
|
|
32
|
+
export function atomically(db: DatabaseConnection, step: () => void, options: { foreignKeysOff?: boolean } = {}): void {
|
|
33
|
+
// Put back what the connection had, rather than assume it was on.
|
|
34
|
+
const foreignKeysWere = options.foreignKeysOff
|
|
35
|
+
? (db.prepare('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys
|
|
36
|
+
: null;
|
|
37
|
+
if (foreignKeysWere !== null) db.exec('PRAGMA foreign_keys = OFF');
|
|
38
|
+
try {
|
|
39
|
+
db.exec('BEGIN IMMEDIATE');
|
|
40
|
+
try {
|
|
41
|
+
step();
|
|
42
|
+
db.exec('COMMIT');
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Some failures (a full disk) end the transaction themselves; the
|
|
45
|
+
// ROLLBACK then fails too, and must not hide the error that matters.
|
|
46
|
+
try {
|
|
47
|
+
db.exec('ROLLBACK');
|
|
48
|
+
} catch {
|
|
49
|
+
// Already rolled back.
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
if (foreignKeysWere !== null) db.exec(`PRAGMA foreign_keys = ${foreignKeysWere ? 'ON' : 'OFF'}`);
|
|
55
|
+
}
|
|
9
56
|
}
|
|
10
57
|
|
|
11
58
|
export class MigrationRunner {
|
|
@@ -51,14 +98,13 @@ export class MigrationRunner {
|
|
|
51
98
|
debug.log('database', `📋 Running migration: ${migration.id} - ${migration.description}`);
|
|
52
99
|
|
|
53
100
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
`).run(migration.id, migration.description, new Date().toISOString());
|
|
101
|
+
atomically(this.db, () => {
|
|
102
|
+
migration.up(this.db);
|
|
103
|
+
this.db.prepare(`
|
|
104
|
+
INSERT INTO migrations (id, description, executed_at)
|
|
105
|
+
VALUES (?, ?, ?)
|
|
106
|
+
`).run(migration.id, migration.description, new Date().toISOString());
|
|
107
|
+
}, migration);
|
|
62
108
|
|
|
63
109
|
executedCount++;
|
|
64
110
|
debug.log('database', `✅ Migration ${migration.id} completed`);
|
|
@@ -85,13 +131,12 @@ export class MigrationRunner {
|
|
|
85
131
|
}
|
|
86
132
|
|
|
87
133
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
`).run(migrationId);
|
|
134
|
+
atomically(this.db, () => {
|
|
135
|
+
migration.down(this.db);
|
|
136
|
+
this.db.prepare(`
|
|
137
|
+
DELETE FROM migrations WHERE id = ?
|
|
138
|
+
`).run(migrationId);
|
|
139
|
+
}, migration);
|
|
95
140
|
|
|
96
141
|
debug.log('database', `✅ Migration ${migrationId} rolled back successfully`);
|
|
97
142
|
} catch (error) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
2
|
|
|
3
3
|
import { debug } from '$shared/utils/logger';
|
|
4
|
+
import { atomically } from './migration-runner';
|
|
5
|
+
|
|
4
6
|
interface Seeder {
|
|
5
7
|
name: string;
|
|
6
8
|
description: string;
|
|
@@ -47,22 +49,26 @@ export class SeederRunner {
|
|
|
47
49
|
debug.log('database', `🌱 Running seeder: ${seeder.name} - ${seeder.description}`);
|
|
48
50
|
|
|
49
51
|
try {
|
|
50
|
-
//
|
|
51
|
-
seeder
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
// The seeder and its record together, like a migration: an
|
|
53
|
+
// interrupted seeder must not leave half its rows behind and
|
|
54
|
+
// then run again on top of them.
|
|
55
|
+
atomically(this.db, () => {
|
|
56
|
+
seeder.seed(this.db);
|
|
57
|
+
|
|
58
|
+
// Record seeder as executed (replace if force)
|
|
59
|
+
if (force && executedNames.has(seeder.name)) {
|
|
60
|
+
this.db.prepare(`
|
|
61
|
+
UPDATE seeders
|
|
62
|
+
SET description = ?, executed_at = ?
|
|
63
|
+
WHERE name = ?
|
|
64
|
+
`).run(seeder.description, new Date().toISOString(), seeder.name);
|
|
65
|
+
} else {
|
|
66
|
+
this.db.prepare(`
|
|
67
|
+
INSERT OR REPLACE INTO seeders (name, description, executed_at)
|
|
68
|
+
VALUES (?, ?, ?)
|
|
69
|
+
`).run(seeder.name, seeder.description, new Date().toISOString());
|
|
70
|
+
}
|
|
71
|
+
});
|
|
66
72
|
|
|
67
73
|
executedCount++;
|
|
68
74
|
debug.log('database', `✅ Seeder ${seeder.name} completed`);
|