diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml deleted file mode 100644 index e6cb58c28..000000000 --- a/.github/workflows/release-please.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Release Please - -on: - push: - branches: - - main - workflow_dispatch: - -permissions: - contents: write - issues: write - pull-requests: write - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - release-please: - runs-on: ubuntu-latest - steps: - - name: Check release token - env: - RELEASE_PLEASE_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }} - run: | - if [ -z "$RELEASE_PLEASE_TOKEN" ]; then - echo "RELEASE_PLEASE_TOKEN must be set to a fine-grained PAT so release-please tags can trigger release.yml." >&2 - exit 1 - fi - - - name: Run release-please - uses: googleapis/release-please-action@v4 - with: - # Use a fine-grained PAT so generated tags trigger release.yml. - token: ${{ secrets.RELEASE_PLEASE_TOKEN }} - config-file: release-please-config.json - manifest-file: .release-please-manifest.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fb2a4399a..7c6ec2811 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,9 @@ name: Release on: push: tags: - - "v*.*.*" + # Calendar tags only (26.09, 26.09.1, 26.09-rc.1); legacy v0.x tags + # are rejected by scripts/release_version.sh and must not start a run. + - "[1-9][0-9].*" workflow_dispatch: concurrency: @@ -31,9 +33,17 @@ jobs: outputs: version: ${{ steps.version.outputs.version }} tag: ${{ steps.version.outputs.tag }} - major_minor: ${{ steps.version.outputs.major_minor }} + series: ${{ steps.version.outputs.series }} is_prerelease: ${{ steps.version.outputs.is_prerelease }} + previous_tag: ${{ steps.version.outputs.previous_tag }} steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + # Previous-release detection walks tags reachable from the release commit. + fetch-depth: 0 + fetch-tags: true + - name: Extract version id: version env: @@ -43,27 +53,16 @@ jobs: if [ "$EVENT_NAME" = "workflow_dispatch" ]; then echo "tag=" >> "$GITHUB_OUTPUT" echo "version=manual-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" - echo "major_minor=" >> "$GITHUB_OUTPUT" + echo "series=" >> "$GITHUB_OUTPUT" echo "is_prerelease=false" >> "$GITHUB_OUTPUT" exit 0 fi - if [[ ! "$REF_NAME" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)(-rc\.[0-9]+)?$ ]]; then - echo "Unsupported release tag format: $REF_NAME" >&2 - exit 1 - fi - - version="${BASH_REMATCH[1]}${BASH_REMATCH[2]}" - major_minor="${BASH_REMATCH[1]%.*}" - is_prerelease=false - if [ -n "${BASH_REMATCH[2]}" ]; then - is_prerelease=true - fi - - echo "tag=${REF_NAME}" >> "$GITHUB_OUTPUT" - echo "version=${version}" >> "$GITHUB_OUTPUT" - echo "major_minor=${major_minor}" >> "$GITHUB_OUTPUT" - echo "is_prerelease=${is_prerelease}" >> "$GITHUB_OUTPUT" + bash scripts/release_version.sh version "$REF_NAME" >> "$GITHUB_OUTPUT" + # Release notes span from the previous stable release, not the last + # release candidate. An empty value lets GitHub pick the range. + previous_tag="$(bash scripts/release_version.sh previous-tag . || true)" + echo "previous_tag=${previous_tag}" >> "$GITHUB_OUTPUT" build-frontend: name: Build Frontend @@ -251,6 +250,9 @@ jobs: tag_name: ${{ needs.prepare.outputs.tag }} name: ${{ needs.prepare.outputs.tag }} prerelease: ${{ needs.prepare.outputs.is_prerelease == 'true' }} + make_latest: ${{ needs.prepare.outputs.is_prerelease != 'true' }} + generate_release_notes: true + previous_tag: ${{ needs.prepare.outputs.previous_tag }} files: artifacts/* build-push: @@ -334,6 +336,9 @@ jobs: contents: read packages: write steps: + - name: Checkout code + uses: actions/checkout@v6 + - name: Download digests uses: actions/download-artifact@v4 with: @@ -360,23 +365,16 @@ jobs: - name: Create manifest list and push working-directory: /tmp/digests run: | - version="${{ needs.prepare.outputs.version }}" - if [ "${{ needs.prepare.outputs.is_prerelease }}" = "true" ]; then - docker buildx imagetools create \ - -t "neosmemo/memos:${version}" \ - -t "ghcr.io/usememos/memos:${version}" \ - $(printf 'neosmemo/memos@sha256:%s ' *) - exit 0 - fi - - docker buildx imagetools create \ - -t "neosmemo/memos:${version}" \ - -t "neosmemo/memos:${{ needs.prepare.outputs.major_minor }}" \ - -t "neosmemo/memos:stable" \ - -t "ghcr.io/usememos/memos:${version}" \ - -t "ghcr.io/usememos/memos:${{ needs.prepare.outputs.major_minor }}" \ - -t "ghcr.io/usememos/memos:stable" \ - $(printf 'neosmemo/memos@sha256:%s ' *) + tags="$(bash "$GITHUB_WORKSPACE/scripts/release_version.sh" image-tags "${{ needs.prepare.outputs.tag }}")" + args=() + while IFS= read -r tag; do + args+=(-t "neosmemo/memos:${tag}" -t "ghcr.io/usememos/memos:${tag}") + done <<< "$tags" + digests=() + for digest in *; do + digests+=("neosmemo/memos@sha256:${digest}") + done + docker buildx imagetools create "${args[@]}" "${digests[@]}" - name: Inspect images run: | diff --git a/.github/workflows/upgrade-smoke.yml b/.github/workflows/upgrade-smoke.yml index 347ccf2fd..e0110b6a6 100644 --- a/.github/workflows/upgrade-smoke.yml +++ b/.github/workflows/upgrade-smoke.yml @@ -17,6 +17,7 @@ on: # Anything that can change how an existing database is opened or upgraded. - "store/migration/**" - "store/migrator.go" + - "store/schema_version*.go" - "store/db/**" - "store/test/containers.go" - "store/test/migrator*_test.go" @@ -25,6 +26,9 @@ on: - "scripts/Dockerfile" - "scripts/entrypoint.sh" - "scripts/release_smoke_test.sh" + - "scripts/release_version*" + - "scripts/install*" + - ".github/workflows/release.yml" - ".github/workflows/upgrade-smoke.yml" concurrency: @@ -58,6 +62,9 @@ jobs: cache: true cache-dependency-path: go.sum + - name: Test release versioning and installer + run: go test -v ./scripts/... + # No -race here: testcontainers has known races in its reaper, which is why # store/test/migrator_test.go documents skipping the race detector. - name: Run migration and upgrade tests diff --git a/.release-please-manifest.json b/.release-please-manifest.json deleted file mode 100644 index 8e3d9554b..000000000 --- a/.release-please-manifest.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - ".": "0.31.0" -} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index b62b79ac0..000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,407 +0,0 @@ -# Changelog - -## [0.31.0](https://github.com/usememos/memos/compare/v0.30.0...v0.31.0) (2026-09-20) - -Memos 0.31 adds Spaces for collaboration, Calendar and Map views for browsing your notes, and tools to move your memos between instances. Writing, search, attachments, and navigation also receive improvements throughout the app. - -This stable release includes the changes since `0.30.0`, including both `0.31.0` release candidates. - -### Highlights - -* **Spaces:** Organize memos in shared Spaces, invite people through their inbox, move memos between Spaces, and choose custom icons or emoji. Space-only visibility limits a memo's audience to active Space members, with the administrator access described below. ([#6228](https://github.com/usememos/memos/pull/6228), [#6266](https://github.com/usememos/memos/pull/6266), [#6285](https://github.com/usememos/memos/pull/6285), [#6287](https://github.com/usememos/memos/pull/6287)) -* **Calendar and Map:** Browse memos by month, open a day to read or add notes for that date, and explore memos with location data on a dedicated map. ([#6277](https://github.com/usememos/memos/pull/6277), [#6280](https://github.com/usememos/memos/pull/6280), [map page](https://github.com/usememos/memos/commit/bc89ec00060623cff52eacbc2c3ca82038e5c924)) -* **Views and search:** Save reusable filters as Views with custom icons. Filter by Space or location, find memos outside any Space, use expressions in Quick Find, and see search matches highlighted in memo content. ([#6167](https://github.com/usememos/memos/pull/6167), [#6181](https://github.com/usememos/memos/pull/6181), [#6267](https://github.com/usememos/memos/pull/6267), [#6276](https://github.com/usememos/memos/pull/6276), [#6305](https://github.com/usememos/memos/pull/6305), [#6335](https://github.com/usememos/memos/pull/6335)) -* **Export and import:** Move your memos between instances from Settings → Export & Import using Memos Export Format (ZIP). Exports include archived memos, comments you wrote, and attachment files. Older export files remain importable. This is a personal export; instance settings and other users' data are not included. ([#6334](https://github.com/usememos/memos/pull/6334), [export format](https://github.com/usememos/memos/commit/eab07d8081e7a196834f896e91cfebb0c1a73fb5)) -* **Attachments:** Configure multiple named storage backends, insert attachment images into memo content, upload files in smaller chunks, and see your attachment storage usage in account settings. ([#6184](https://github.com/usememos/memos/pull/6184), [#6172](https://github.com/usememos/memos/pull/6172), [chunked uploads](https://github.com/usememos/memos/commit/b3e67399b83bc32cb27dda1f0eaa448b2108e211), [#6326](https://github.com/usememos/memos/pull/6326)) -* **Writing and navigation:** Create memos from the sidebar, use Markdown formatting shortcuts, resize the desktop sidebar, and keep your Space and filters when navigating to a memo and back. ([#6219](https://github.com/usememos/memos/pull/6219), [#6258](https://github.com/usememos/memos/pull/6258), [#6148](https://github.com/usememos/memos/pull/6148), [Space navigation](https://github.com/usememos/memos/commit/af008b21533bdc50fae5ad6a438347ad84bb9419)) - -### Fixes and polish - -* **Editor:** Improved IME and Windows emoji input, restored native mobile text assistance, attached pasted files correctly, preserved timestamp edits, and expanded tag autocomplete to more editing contexts. ([IME input](https://github.com/usememos/memos/commit/14d757ce1fb31c78590f374bc042f8dbedbc20d7), [emoji input](https://github.com/usememos/memos/commit/b4fefa94d72cd381ccdd1dcb359ade0371203cce), [#6248](https://github.com/usememos/memos/pull/6248), [pasted files](https://github.com/usememos/memos/commit/8701d93fc0a55500c3c3c27a737fb9d60dd8a82f), [timestamp edits](https://github.com/usememos/memos/commit/0716eaac2c07b00cc4c36682ad7880a1ef072162), [#6327](https://github.com/usememos/memos/pull/6327)) -* **Markdown:** Improved tag recognition, stopped currency amounts from being interpreted as inline math, fixed numbered task-list toggles, and enabled telephone and SMS links. ([#6132](https://github.com/usememos/memos/pull/6132), [#6216](https://github.com/usememos/memos/pull/6216), [#6346](https://github.com/usememos/memos/pull/6346), [#6341](https://github.com/usememos/memos/pull/6341)) -* **Map and media:** Restored keyless OpenStreetMap tiles, fixed navigation away from the Map after a WebGL failure, improved HEIC/HEIF detection, and added 0.5× and 0.75× audio playback. ([#6242](https://github.com/usememos/memos/pull/6242), [WebGL cleanup](https://github.com/usememos/memos/commit/305310cdd18345acc25466d24e800b3f85c49593), [#6246](https://github.com/usememos/memos/pull/6246), [audio speeds](https://github.com/usememos/memos/commit/b88a71540a1a4079c8211edeac3e81b0fb4a6a13)) -* **Interface and languages:** Refined memo navigation and comment menus, corrected focus-mode and right-to-left layouts, matched the installed app's status bar to dark mode, added Azerbaijani and Hebrew, and synchronized translations across supported languages. ([#6261](https://github.com/usememos/memos/pull/6261), [comment menus](https://github.com/usememos/memos/commit/7e3d3c63156c206209fdc8e75a4fb117b1aaf1fb), [#6310](https://github.com/usememos/memos/pull/6310), [#6215](https://github.com/usememos/memos/pull/6215), [#6320](https://github.com/usememos/memos/pull/6320), [#6278](https://github.com/usememos/memos/pull/6278), [#6203](https://github.com/usememos/memos/pull/6203), [translations](https://github.com/usememos/memos/commit/2204eceeef34625cfd3e74fea7ad71769c9abc43)) - -### Administration and integrations - -* **Security and reliability:** Added rate limits and tighter request, image-processing, and import limits; strengthened remote-fetch validation; protected S3 uploads from object-key collisions; and corrected attachment cleanup. ([#6315](https://github.com/usememos/memos/pull/6315), [hardening](https://github.com/usememos/memos/commit/471745b4314820dcb4b8b451095679ee6cfc71c3), [remote-fetch protection](https://github.com/usememos/memos/commit/f4d97fafcdab534e7e01c376d2b06a3c6aa98a33)) -* **Sessions and private files:** Changing your password signs out your other sessions; an administrator password reset signs out all sessions for that account. S3 attachments are served through authenticated file routes. ([session revocation](https://github.com/usememos/memos/commit/471745b4314820dcb4b8b451095679ee6cfc71c3), [#6210](https://github.com/usememos/memos/pull/6210)) -* **Access mode:** Public/private instance access is now stored independently of the instance URL. ([#6225](https://github.com/usememos/memos/pull/6225)) -* **Integrations:** Added Space operations to MCP and corrected tool schemas, fixed scheduled-job day matching, and added `-V` and `--version` to the CLI. ([MCP Spaces](https://github.com/usememos/memos/commit/619eb8d6b), [MCP schemas](https://github.com/usememos/memos/commit/652957c0f98b5e66fb7b369ddef9f40ee439ef69), [#6306](https://github.com/usememos/memos/pull/6306), [#6321](https://github.com/usememos/memos/pull/6321)) - -### Upgrade notes - -* **Administrator access:** Active instance administrators can now read and manage individual memos, including private and Space-only memos, without being their author or a Space member. Collection listings still apply audience filtering; administrators do not automatically become Space members. ([permission changes](https://github.com/usememos/memos/commit/4f4652375)) -* **Views and API clients:** Existing Shortcuts are migrated to Views. Integrations using the old Shortcut API must move to the `UserService` View operations under `/api/v1/users/{user}/views`. The reaction API also removes `contentId`; reactions remain scoped to their memo. ([#6167](https://github.com/usememos/memos/pull/6167), [View operations](https://github.com/usememos/memos/commit/e02899e51), [#6221](https://github.com/usememos/memos/pull/6221)) -* **Account email:** Email remains optional. Addresses are trimmed, lowercased, and unique per instance. Upgrades clear invalid addresses and keep a duplicate address only on the oldest account; affected usernames are logged. ([#6314](https://github.com/usememos/memos/pull/6314)) -* **RSS:** RSS feed support has been removed. Existing feed URLs no longer provide feeds. ([#6243](https://github.com/usememos/memos/pull/6243)) - -## [0.31.0-rc.2](https://github.com/usememos/memos/compare/v0.31.0-rc.1...v0.31.0-rc.2) (2026-09-15) - -### Highlights - -* **Calendar:** Browse your memos by month and open a day to read or add memos for that date. ([#6277](https://github.com/usememos/memos/pull/6277)) ([#6280](https://github.com/usememos/memos/pull/6280)) -* **Map:** Explore memos with location data on a dedicated map page. ([bc89ec0](https://github.com/usememos/memos/commit/bc89ec00060623cff52eacbc2c3ca82038e5c924)) -* **Spaces:** Move memos between Spaces, receive invitations in your inbox, and personalize Spaces with icons or emoji. ([#6285](https://github.com/usememos/memos/pull/6285)) ([#6266](https://github.com/usememos/memos/pull/6266)) ([#6287](https://github.com/usememos/memos/pull/6287)) -* **Space navigation:** Space selection is now part of the URL. Switching Spaces preserves the current page and filters, and returning from a memo restores its original context. ([af008b2](https://github.com/usememos/memos/commit/af008b21533bdc50fae5ad6a438347ad84bb9419)) -* **Views and search:** Give saved Views custom icons, filter by Space or find memos outside any Space, and use expressions in Quick Find for advanced searches. ([#6305](https://github.com/usememos/memos/pull/6305)) ([#6267](https://github.com/usememos/memos/pull/6267)) ([#6276](https://github.com/usememos/memos/pull/6276)) -* **Attachments:** Upload files in smaller chunks to reduce memory use, and see your attachment storage usage in account settings. ([b3e6739](https://github.com/usememos/memos/commit/b3e67399b83bc32cb27dda1f0eaa448b2108e211)) ([#6326](https://github.com/usememos/memos/pull/6326)) -* **Writing:** Use keyboard shortcuts for Markdown formatting. On desktop, the Home editor is focused automatically on initial load. ([#6258](https://github.com/usememos/memos/pull/6258)) ([#6275](https://github.com/usememos/memos/pull/6275)) -* **Audio:** Added 0.5× and 0.75× playback speeds. ([b88a715](https://github.com/usememos/memos/commit/b88a71540a1a4079c8211edeac3e81b0fb4a6a13)) -* **Languages:** Added Azerbaijani and made Chinese sensitive-content labels consistent. ([#6278](https://github.com/usememos/memos/pull/6278)) ([#6274](https://github.com/usememos/memos/pull/6274)) - -### Fixes and polish - -* **Memo navigation:** Redesigned the memo detail sidebar and made active filters easier to distinguish from the current page. ([#6261](https://github.com/usememos/memos/pull/6261)) ([aba1f73](https://github.com/usememos/memos/commit/aba1f7384d44d020ce8e4d9036c7cececb3c6c13)) -* **Sidebar:** Refined spacing, simplified the account footer, and prevented navigation labels from being truncated in narrow sidebars. ([191ec01](https://github.com/usememos/memos/commit/191ec01d11186db7ab4840b41d6fe008e3729909)) ([5a65350](https://github.com/usememos/memos/commit/5a65350400f0b5f6c726a1187458ca3d91f4e38e)) ([88f1505](https://github.com/usememos/memos/commit/88f150502c9a1ec6050ff4bdd8f439f646829ab3)) -* **Memo controls:** Refined compact navigation and memo actions, aligned author spacing, and made metadata controls appear when hovering over their row. ([ce0dd23](https://github.com/usememos/memos/commit/ce0dd23d2f40d5613fd40f284264fc21e5e4ae82)) ([2e33e7a](https://github.com/usememos/memos/commit/2e33e7a5619f04efd9f713b0f855c6c60641ef8c)) ([#6324](https://github.com/usememos/memos/pull/6324)) -* **Editor input:** Restored native mobile text assistance and made pasted files appear as attachments. Tag suggestions now work inside code, links, and escaped text, including unfinished nested tag paths. ([#6248](https://github.com/usememos/memos/pull/6248)) ([8701d93](https://github.com/usememos/memos/commit/8701d93fc0a55500c3c3c27a737fb9d60dd8a82f)) ([#6327](https://github.com/usememos/memos/pull/6327)) -* **Memo timestamps:** Preserved timestamp edits when closing the date and time popover. ([0716eaa](https://github.com/usememos/memos/commit/0716eaac2c07b00cc4c36682ad7880a1ef072162)) -* **Focus mode and blurred content:** Fixed editor focus mode being constrained by the memo grid, improved overlay dimming, and kept blurred memo headers and reactions interactive. ([#6310](https://github.com/usememos/memos/pull/6310)) ([#6269](https://github.com/usememos/memos/pull/6269)) -* **Dark mode:** Matched the installed web app’s status bar to the dark theme. ([#6320](https://github.com/usememos/memos/pull/6320)) - -### Administration and integrations - -* **Account email:** Email remains optional. Addresses are now validated, trimmed, lowercased, and unique per instance. During upgrades, the oldest account keeps a duplicate address; it is cleared from other accounts, with affected usernames logged. ([#6314](https://github.com/usememos/memos/pull/6314)) -* **Abuse protection:** Added rate limits for sign-in, sign-up, remote fetches, uploads, and writes. Webhook validation now also blocks unspecified destination addresses. ([#6315](https://github.com/usememos/memos/pull/6315)) ([#6284](https://github.com/usememos/memos/pull/6284)) -* **MCP:** Corrected JSON Schema formats in tool definitions for better client compatibility. ([652957c](https://github.com/usememos/memos/commit/652957c0f98b5e66fb7b369ddef9f40ee439ef69)) -* **Scheduled jobs:** Corrected cron matching for day-of-month and day-of-week fields. ([#6306](https://github.com/usememos/memos/pull/6306)) - -## [0.31.0-rc.1](https://github.com/usememos/memos/compare/v0.30.0...v0.31.0-rc.1) (2026-08-30) - - -### Features - -* **filter:** support memo location filters ([#6181](https://github.com/usememos/memos/issues/6181)) ([57bfe0a](https://github.com/usememos/memos/commit/57bfe0a70fd2375a8be140833399a663a08581d6)) -* insert attachment images into memo content ([#6172](https://github.com/usememos/memos/issues/6172)) ([9a928c2](https://github.com/usememos/memos/commit/9a928c286861958f0a08f2c2d173d073972afa7f)) -* **instance:** persist access mode independently of URL ([#6225](https://github.com/usememos/memos/issues/6225)) ([76a7629](https://github.com/usememos/memos/commit/76a762924306e782871204f131f4033be5e8e41a)) -* **link-preview:** support standards-based metadata ([#6206](https://github.com/usememos/memos/issues/6206)) ([16cd310](https://github.com/usememos/memos/commit/16cd3107bf324dc159ec5d1894d6c11dec7edd96)) -* **markdown:** unify tag syntax and recognition ([#6132](https://github.com/usememos/memos/issues/6132)) ([c68e3d5](https://github.com/usememos/memos/commit/c68e3d5bf98394d90c7137f29d0ae378de17e824)) -* persist and display client media metadata ([#6180](https://github.com/usememos/memos/issues/6180)) ([da81b6b](https://github.com/usememos/memos/commit/da81b6b48f8e6cdd35d0a38745914da0ce9b3e53)) -* **sidebar:** make the desktop rail resizable ([#6148](https://github.com/usememos/memos/issues/6148)) ([abe87d9](https://github.com/usememos/memos/commit/abe87d9440783cb43c433b6fa7d35f1cc2450b4b)) -* **space:** add client-defined UIDs and identity cues ([9d2b77c](https://github.com/usememos/memos/commit/9d2b77ced8ef5c4797be2345a27bc0eb35b1787b)) -* **spaces:** add consent-based member invitations ([#6232](https://github.com/usememos/memos/issues/6232)) ([05f882e](https://github.com/usememos/memos/commit/05f882e43aee1d3125b66f6e8eb1d7d506de0000)) -* **spaces:** add multi-space memo collaboration ([#6228](https://github.com/usememos/memos/issues/6228)) ([6da8461](https://github.com/usememos/memos/commit/6da8461e1d9b591c500e8031a716d66e2322b394)) -* **spaces:** add settings management ([#6234](https://github.com/usememos/memos/issues/6234)) ([854d893](https://github.com/usememos/memos/commit/854d893fc6021505ade0d3ea5fe7ccad06a2ae56)) -* **spaces:** add space-aware UI and filtering ([#6230](https://github.com/usememos/memos/issues/6230)) ([66b9cb4](https://github.com/usememos/memos/commit/66b9cb49c14e34e8e3c1f996f43d0360864ab4db)) -* **spaces:** unify collection scope across resource pages ([cdd13ca](https://github.com/usememos/memos/commit/cdd13ca24ebde1c1ee46565ba2899d68f0d66b21)) -* **storage:** add named attachment storage drivers ([#6184](https://github.com/usememos/memos/issues/6184)) ([7d971b1](https://github.com/usememos/memos/commit/7d971b1c6187c13b8804ad74e3321b1445ed0363)) -* support memo-scoped Markdown attachment images ([#6169](https://github.com/usememos/memos/issues/6169)) ([bd636a4](https://github.com/usememos/memos/commit/bd636a43652222089a0aa485a1db720042690e77)) -* **user:** define username format and mention syntax ([#6134](https://github.com/usememos/memos/issues/6134)) ([8648b97](https://github.com/usememos/memos/commit/8648b97b9e0ba3fe0de16362d8f99a5ee7f167b0)) -* **web:** add a global memo composer to the sidebar ([#6219](https://github.com/usememos/memos/issues/6219)) ([f36ca93](https://github.com/usememos/memos/commit/f36ca9317dad153c89643f8b8abee619df9a3aeb)) -* **web:** unify navigation in a route-aware sidebar ([#6144](https://github.com/usememos/memos/issues/6144)) ([4d26679](https://github.com/usememos/memos/commit/4d2667983fd3387e6db76fb05b51dfe376899161)) - - -### Bug Fixes - -* align memo outline links with rendered headings ([#6159](https://github.com/usememos/memos/issues/6159)) ([e5ed6e7](https://github.com/usememos/memos/commit/e5ed6e7ec60e141d6e354f3ab59906c2c47dccac)) -* **api:** omit unset message fields from gateway JSON ([#6156](https://github.com/usememos/memos/issues/6156)) ([bdf87e8](https://github.com/usememos/memos/commit/bdf87e8699a68f92a4f703ce365042b662f166d0)) -* **attachment:** detect heic/heif mime type from filename extension ([#6246](https://github.com/usememos/memos/issues/6246)) ([d5849bd](https://github.com/usememos/memos/commit/d5849bdf52c05b522729319091666a52dc26601c)) -* **attachments:** link media to source memos ([c4221c6](https://github.com/usememos/memos/commit/c4221c6dfe51902d0c5f482802e670fda1b72751)) -* **editor:** match tag autocomplete on path segments ([bbb2395](https://github.com/usememos/memos/commit/bbb23958b22063b7e663b51812e7775eca3f23ae)), closes [#6190](https://github.com/usememos/memos/issues/6190) -* **editor:** preserve IME composition during content sync ([14d757c](https://github.com/usememos/memos/commit/14d757ce1fb31c78590f374bc042f8dbedbc20d7)) -* **editor:** restore Windows emoji input ([b4fefa9](https://github.com/usememos/memos/commit/b4fefa94d72cd381ccdd1dcb359ade0371203cce)) -* **editor:** scope view toggles to inline presentations ([#6227](https://github.com/usememos/memos/issues/6227)) ([fc6cbab](https://github.com/usememos/memos/commit/fc6cbab7d0d0bb90cdd4cd96e4b2e45109ab6b47)) -* **i18n:** complete Traditional Chinese space translations ([#6241](https://github.com/usememos/memos/issues/6241)) ([9fd3885](https://github.com/usememos/memos/commit/9fd3885e43594536e2a2ec1a7818e3fe2b3b61b4)) -* **i18n:** correct French memo link label ([#6182](https://github.com/usememos/memos/issues/6182)) ([bba1d6d](https://github.com/usememos/memos/commit/bba1d6d4975a44cf60abee63a85fc1b2e2a3dea5)) -* **map:** restore keyless OpenStreetMap tiles ([#6242](https://github.com/usememos/memos/issues/6242)) ([171687c](https://github.com/usememos/memos/commit/171687c456b22d42fe98e4dbfda042f985b320a0)) -* **markdown:** avoid parsing currency as inline math ([#6216](https://github.com/usememos/memos/issues/6216)) ([e99ae78](https://github.com/usememos/memos/commit/e99ae78012f24108ea20574be6737f846b4b5ede)) -* **markdown:** support word-internal apostrophes in tags ([#6135](https://github.com/usememos/memos/issues/6135)) ([d617f65](https://github.com/usememos/memos/commit/d617f652b01086b9619500a46dc1eb9b13e84046)) -* **settings:** validate memo content length limit ([45c3a79](https://github.com/usememos/memos/commit/45c3a79b1215ecd8912b699d9d635055147041c3)) -* **sidebar:** stop the month calendar growing with the rail ([d722608](https://github.com/usememos/memos/commit/d7226089476e72e4329f29d3bbe3cb1243dcc19b)) -* **spaces:** add context to summary query errors ([fc7970a](https://github.com/usememos/memos/commit/fc7970a2d1244c040ea1768d7991165835b5e3e2)) -* **storage:** proxy S3 attachments through authenticated routes ([#6210](https://github.com/usememos/memos/issues/6210)) ([38412eb](https://github.com/usememos/memos/commit/38412eb75afc24df3c60fed91d498fc1bce6b232)) -* **store:** begin sqlite memo mutations with BEGIN IMMEDIATE ([#6192](https://github.com/usememos/memos/issues/6192)) ([f954434](https://github.com/usememos/memos/commit/f9544349202d931b90e38c01982e42245ca1c605)) -* **store:** harden 0.31 migration upgrades ([#6247](https://github.com/usememos/memos/issues/6247)) ([a720870](https://github.com/usememos/memos/commit/a7208701d10bfe73a216f36d314caa1bf4976b79)) -* **ui:** keep select menus above parent popovers ([9328413](https://github.com/usememos/memos/commit/93284137970d2ac1bda29f9a8feb6da9c69e3db8)) -* **ui:** refine space labels and sidebar menus ([22a5f33](https://github.com/usememos/memos/commit/22a5f3385b9fc5bdf282eb597aa3db79798aa5ab)) -* upgrade golang.org/x/crypto to 0.52.0 (CVE-2026-39829) ([#6152](https://github.com/usememos/memos/issues/6152)) ([3b8d255](https://github.com/usememos/memos/commit/3b8d2558edccaf194c06e5f34fff2f6681fcb76b)) -* **web:** correct RTL layout behavior ([#6215](https://github.com/usememos/memos/issues/6215)) ([e67ec79](https://github.com/usememos/memos/commit/e67ec7935199c12c15053119262dc9aef074d85e)) -* **web:** keep share token on shared-memo attachment thumbnails ([#6155](https://github.com/usememos/memos/issues/6155)) ([3f567fd](https://github.com/usememos/memos/commit/3f567fda4592f9f552623bd0da0dec3c622c6359)) -* **web:** keep task checkboxes controlled so check-all updates render ([5192732](https://github.com/usememos/memos/commit/5192732cee40020f84c1e57dbcc53ea3d9eaa42f)) -* **web:** make archived independent of space scope ([040f9ae](https://github.com/usememos/memos/commit/040f9ae717675c2206856afaf52ece67911d71ea)) -* **web:** preserve memo scope across global navigation ([83eab44](https://github.com/usememos/memos/commit/83eab44695ec95205990e4e0c1045dbfa6caf4f3)) -* **web:** restore sidebar and outline behavior ([#6161](https://github.com/usememos/memos/issues/6161)) ([f75d49f](https://github.com/usememos/memos/commit/f75d49f9b617e1ac1370e36e71b1869d3c52e6ca)) - - -### Performance Improvements - -* **sse:** reduce redundant connections and fanout overhead ([dd18002](https://github.com/usememos/memos/commit/dd18002b12b8632d11b57fa3d33de244bba91476)) - -## [0.30.0](https://github.com/usememos/memos/compare/v0.29.1...v0.30.0) (2026-07-26) - - -### Summary - -Memos 0.30 delivers a major writing and navigation refresh, centered on the new -CodeMirror editor, richer memo detail views, configurable multi-column feeds, and -faster Explore and feed rendering. It also replaces the MCP integration with a -curated OpenAPI-driven tool surface, expands deployment-time configuration, and -strengthens authentication, sharing, and private-instance access boundaries. - -This stable release includes all changes shipped through `0.30.0-rc.1` and -`0.30.0-rc.2`, plus the final authentication, SSO, sharing, and MCP fixes listed -below. - -### ⚠ BREAKING CHANGES - -* **Access control:** Instances without `--instance-url` (or `MEMOS_INSTANCE_URL`) now run in private mode. Anonymous visitors are sent to sign-in, anonymous API access is limited to setup, authentication, and shared-memo routes, and RSS feeds are unavailable. Set the instance URL to retain the previous public behavior. ([d1cef7a](https://github.com/usememos/memos/commit/d1cef7a9ab23e8c93f76b2f32661c720c733536d)) ([415a3ec](https://github.com/usememos/memos/commit/415a3ec73d7abee4496eab39b4d135a89387cdc6)) -* **Shared memo API:** `GetMemoByShare` and `GET /api/v1/shares/{share_id}` have been replaced by `GetSharedMemo` and `GET /api/v1/shares/{share_token}/memo`. API clients must update the RPC, request type, field name, and REST path. Share-token responses are limited to the shared memo and its attachments and no longer expose the surrounding parent, comments, or relation graph. ([0d2cbd4](https://github.com/usememos/memos/commit/0d2cbd4f5a410a8edc2093b8834f8f13f6ca9ad6)) ([415a3ec](https://github.com/usememos/memos/commit/415a3ec73d7abee4496eab39b4d135a89387cdc6)) -* **Filters:** `now()` has been replaced by the `now` timestamp variable, and time fields now use CEL timestamps. Update saved shortcuts to use expressions such as `created_ts >= now - duration("24h")` or `timestamp()` instead of comparing time fields with bare epoch values. ([26f4b73](https://github.com/usememos/memos/commit/26f4b73cb9a996f9232daad2b5daa34360742697)) -* **MCP:** The MCP server is now a stateless, tools-only endpoint generated from the OpenAPI schema. The previous prompts, resources, tool-filtering headers and route aliases, and unprefixed tool names have been removed. Clients must switch to `/mcp` and the new service-prefixed tool names. Tool errors now use `isError` and text content rather than a non-standard `structuredContent.error` payload. ([#6026](https://github.com/usememos/memos/issues/6026)) ([03e34bd](https://github.com/usememos/memos/commit/03e34bd0da2f225addbd00d6a7bb5a472c83aed8)) - -### Highlights - -* **Markdown editor:** Rebuilt the editor as a single CodeMirror 6 decorated-source editor. Markdown is preserved verbatim while headings, formatting, tags, and mentions are styled in place. The editor adds tag completion, list indentation, improved keyboard shortcuts, focus mode, and a toggleable formatting toolbar for headings, lists, task lists, code blocks, bold, italic, strikethrough, and inline code. ([5a73d7](https://github.com/usememos/memos/commit/5a73d7d3e56f853a965207ac709e8f5e84918959)) ([e3c231f](https://github.com/usememos/memos/commit/e3c231fcac5691f9590a5d685bdebec23b73be35)) -* **Memo detail and navigation:** Redesigned the memo detail sidebar as a property rail with quick actions, editable visibility, memo metadata, attachments, relations, and a scroll-aware outline. Feed scroll position is restored when navigating back from another page. ([d4b5a16](https://github.com/usememos/memos/commit/d4b5a1695b9acf4da3ef72f600789a4a0f90e4d5)) ([e497895](https://github.com/usememos/memos/commit/e497895bf3b72cdae92e5bab6cd5b691c8eedc15)) -* **Memo feeds:** Added persisted controls for one, two, three, or automatically fitted columns, compact mode, and link previews. Compact rendering is opt-in in single-column feeds so full memo content is shown by default. Multi-column feeds stay balanced as cards resize, while newly created memos remain easy to find above pinned content. ([177d65a](https://github.com/usememos/memos/commit/177d65a90e321fa975a7cf19bd3c075143af5c10)) ([e3e4ae1](https://github.com/usememos/memos/commit/e3e4ae10512f514f71729779b5096d0d591c8cf4)) ([cafa56f](https://github.com/usememos/memos/commit/cafa56f1a8c9091062a4b220284e8ca697b050e8)) -* **MCP:** Replaced the hand-written MCP implementation with a curated OpenAPI-driven tool surface that reuses the public API's authentication and authorization. The final toolset includes memo, comment, relation, reaction, shortcut, identity, and attachment operations, including attachment uploads. Canonical and nested resource names can be passed directly to follow-up tools. ([777d227](https://github.com/usememos/memos/commit/777d227eb992c4feccd5d78c781cf8e9094e38de)) ([0e1d821](https://github.com/usememos/memos/commit/0e1d821fb84310feff40b90d899403d45bced596)) ([390126f](https://github.com/usememos/memos/commit/390126f1cd5f6aca55a17faf031655da4354b60b)) -* **Deployment configuration:** Identity providers and supported instance settings can be supplied as validated JSON files under `/etc/secrets`. File-backed settings act as runtime overrides and cannot be changed through the UI or API until the files are removed. ([0038295](https://github.com/usememos/memos/commit/0038295bbc772b38425b6c7f9ca814e4d1e44260)) -* **Webhooks:** Added Standard Webhooks HMAC-SHA256 signing secrets, webhook editing, and a signing-status indicator. Secrets are generated server-side, shown after creation, and can be revealed later from the edit dialog; malformed secrets now fail validation. ([#6013](https://github.com/usememos/memos/issues/6013)) ([#6027](https://github.com/usememos/memos/issues/6027)) -* **Filters and tag settings:** Expanded CEL shortcuts with string matching, regular expressions, collection predicates, timestamp accessors, set operations, and an untagged-memos example. Tag colors and content-blur rules are now per-user, with existing instance tag settings copied during migration. ([f0e4a56](https://github.com/usememos/memos/commit/f0e4a5624f4371e08fb0c41510891c9f8cce6ba0)) ([b787bfa](https://github.com/usememos/memos/commit/b787bfa75f74d8ee5ec271bd308c2e5a0389ed35)) ([#6017](https://github.com/usememos/memos/issues/6017)) -* **Settings and access tokens:** Refreshed settings navigation and expanded the access-token page with practical guidance, a copyable API example, safety notes, and last-used timestamps. Access tokens now default to no expiration, and the About page and documentation surface the Memos Web Clipper. ([715306e](https://github.com/usememos/memos/commit/715306ea66306a91765d3f7c3ede8bc815d2def5)) ([cc20327](https://github.com/usememos/memos/commit/cc20327b8a1d595de6fe8915be303eddc8816756)) ([f946974](https://github.com/usememos/memos/commit/f94697496b60f5fe590c2ffa19e3f0c93b749af4)) -* **Internationalization and interface:** Added a searchable locale picker, expanded European locale coverage, completed missing Japanese and Simplified Chinese translations, refreshed the sign-in, sign-up, and About pages, and aligned common controls across the app. ([4183985](https://github.com/usememos/memos/commit/418398587cef90151745ba0dbc51cef4762045ca)) ([a47d049](https://github.com/usememos/memos/commit/a47d04954e75c54491138601c72f1c0cbe140f3c)) ([564da94](https://github.com/usememos/memos/commit/564da949cb87491ca8e493d2f7aedcd2ef9545a1)) -* **Markdown and storage:** Added GFM footnote rendering and navigation, plus an `insecure_skip_tls_verify` option for S3-compatible storage with self-signed certificates. ([1020060](https://github.com/usememos/memos/commit/10200606db24e3d70fb8efefee99c7b0a369ddea)) ([#6039](https://github.com/usememos/memos/issues/6039)) -* **Faster feeds and Explore:** Reduced initial work and bandwidth by caching fingerprinted assets, deferring media and rich renderers until needed, rendering feed content near the viewport, and sharing user and memo lookups across creators, reactions, comments, mentions, and relations. ([88c6ee8](https://github.com/usememos/memos/commit/88c6ee8ebcc341aa1d2e2ae38638a518f4745de1)) ([6c1055f](https://github.com/usememos/memos/commit/6c1055f483c92c2a95193bea07110b6775359651)) ([249b331](https://github.com/usememos/memos/commit/249b331596fd1c9ceceb4e72da8e422499be683f)) -* **Demo experience:** Rebuilt the demo data around representative public and protected memos that showcase nested tags, references, comments, mentions, reactions, locations, attachments, and rich Markdown. ([469c995](https://github.com/usememos/memos/commit/469c995cc04b5e7de259156d28c58b948e85d111)) - -### Fixes and polish - -* **Authentication and SSO:** Stabilized SSO option loading, added OAuth client-auth auto-detection, distinguished fresh instances from populated instances without an admin, and made first-time SSO provisioning atomic across SQLite, MySQL, and PostgreSQL. Valid, non-reserved SSO identifiers are used as local usernames with UUID fallback, and concurrent first sign-ins no longer leave orphaned users. ([6c17e87](https://github.com/usememos/memos/commit/6c17e87cf61cd9c62ea4ef4e25d4adb5603ffc88)) ([96cb653](https://github.com/usememos/memos/commit/96cb65320b714ef8d7993ddb7c9182350ee9da4c)) ([019f4f9](https://github.com/usememos/memos/commit/019f4f9adcfcfca73fc9e2a966d0569fac888a2c)) -* **API compatibility and errors:** Aligned new resource IDs and annotations with AIP conventions while preserving legacy UUID-based identifiers, corrected canonical user-stat resource names, removed internal RPC prefixes from user-facing errors, and consistently enforced private-instance access policy across Connect, REST Gateway, files, and RSS. ([84776cc](https://github.com/usememos/memos/commit/84776cc106745278371e5a8c8d43abca6d38e8b5)) ([b7d5d09](https://github.com/usememos/memos/commit/b7d5d09f8a7445076811d6f53b98d3445ce3afac)) ([0bfeb91](https://github.com/usememos/memos/commit/0bfeb91d50fdd4bafd15c13bb02b3e2810d4b2e4)) ([415a3ec](https://github.com/usememos/memos/commit/415a3ec73d7abee4496eab39b4d135a89387cdc6)) -* **MCP reliability:** Fixed round-tripping canonical resource names, nested resource routing, success-schema validation for tool errors, partial-update request schemas, path-bound request bodies, destructive-operation annotations, and oversized request handling. ([03e34bd](https://github.com/usememos/memos/commit/03e34bd0da2f225addbd00d6a7bb5a472c83aed8)) ([390126f](https://github.com/usememos/memos/commit/390126f1cd5f6aca55a17faf031655da4354b60b)) -* **Editor:** Improved formatting toggles and keyboard shortcuts, file paste and drop handling, focus-mode layout, caret behavior in empty space, and CodeMirror spacing. ([c349c15](https://github.com/usememos/memos/commit/c349c1549e49950e3171b7de28faba5d89249cfa)) ([#6076](https://github.com/usememos/memos/issues/6076)) ([#6093](https://github.com/usememos/memos/issues/6093)) -* **Memos and comments:** Preserved expanded task-list state, added pagination so every comment page can be loaded, included the parent memo relation in comment webhook payloads, and limited share tokens to the selected memo rather than its conversation and relation graph. ([ecbe2ab](https://github.com/usememos/memos/commit/ecbe2ab7977fcd3521aeae1226e816a9dc2a6a40)) ([#6083](https://github.com/usememos/memos/issues/6083)) ([415a3ec](https://github.com/usememos/memos/commit/415a3ec73d7abee4496eab39b4d135a89387cdc6)) -* **Tags:** Tags inside links are no longer parsed as memo tags, literal tags can be escaped with a backslash, and tag names support Unicode combining marks. ([a50ce09](https://github.com/usememos/memos/commit/a50ce09e8159836aed1a97fa717488283378200f)) ([#6051](https://github.com/usememos/memos/issues/6051)) -* **API and security:** Cross-origin API requests now work with bearer tokens while cookie authentication remains same-origin, and `ListUsers` returns consistent paginated results. ([385fa22](https://github.com/usememos/memos/commit/385fa22056c51a42a0eb99fd08a8876009c2c52d)) ([4bc3928](https://github.com/usememos/memos/commit/4bc39280290b0f2612ff52285689854b6cf1344b)) -* **Interface:** Replaced mismatched memo skeletons with a delayed spinner, improved mobile control spacing, truncated long location labels without hiding the full address, corrected radio-group indicator alignment, and positioned tooltip arrows outside their content panels. ([#6047](https://github.com/usememos/memos/issues/6047)) ([3b601b8](https://github.com/usememos/memos/commit/3b601b841670ece4a2832341a99ccc74124a745e)) ([#6097](https://github.com/usememos/memos/issues/6097)) ([2d01420](https://github.com/usememos/memos/commit/2d01420c23372d5708904ec78e03485edb44d49b)) ([#6095](https://github.com/usememos/memos/issues/6095)) ([773e56e](https://github.com/usememos/memos/commit/773e56e537657508af4e357f9c8845af4d4f15e8)) -* **Container:** Prevented the entrypoint from restarting indefinitely when `MEMOS_UID=0`. ([#6061](https://github.com/usememos/memos/issues/6061)) - -## [0.30.0-rc.2](https://github.com/usememos/memos/compare/v0.30.0-rc.1...v0.30.0-rc.2) (2026-07-20) - - -### Highlights - -* **Memo detail and navigation:** Redesigned the memo detail sidebar as a property rail with quick actions, editable visibility, memo metadata, attachments, relations, and a scroll-aware outline. Feed scroll position is now restored when navigating back from another page. ([d4b5a16](https://github.com/usememos/memos/commit/d4b5a1695b9acf4da3ef72f600789a4a0f90e4d5)) ([e497895](https://github.com/usememos/memos/commit/e497895bf3b72cdae92e5bab6cd5b691c8eedc15)) -* **Settings and access tokens:** Refreshed settings navigation and expanded the access-token page with practical guidance, a copyable API example, safety notes, and last-used timestamps. The About page and project documentation now surface the Memos Web Clipper. ([715306e](https://github.com/usememos/memos/commit/715306ea66306a91765d3f7c3ede8bc815d2def5)) ([06ecef3](https://github.com/usememos/memos/commit/06ecef33bc7e6bafc263b2dee71ffd290ab3dc42)) ([f946974](https://github.com/usememos/memos/commit/f94697496b60f5fe590c2ffa19e3f0c93b749af4)) -* **Faster feeds and Explore:** Reduced initial work and bandwidth by caching fingerprinted assets, deferring media and rich renderers until needed, rendering feed content near the viewport, and sharing user and memo lookups across creators, reactions, comments, mentions, and relations. ([88c6ee8](https://github.com/usememos/memos/commit/88c6ee8ebcc341aa1d2e2ae38638a518f4745de1)) ([6c1055f](https://github.com/usememos/memos/commit/6c1055f483c92c2a95193bea07110b6775359651)) ([249b331](https://github.com/usememos/memos/commit/249b331596fd1c9ceceb4e72da8e422499be683f)) -* **Demo experience:** Rebuilt the demo data around representative public and protected memos that showcase nested tags, references, comments, mentions, reactions, locations, attachments, and rich Markdown. ([469c995](https://github.com/usememos/memos/commit/469c995cc04b5e7de259156d28c58b948e85d111)) - -### Fixes and polish - -* **API compatibility and errors:** Aligned new resource IDs and annotations with AIP conventions while preserving legacy UUID-based identifiers, corrected canonical user-stat resource names, and removed internal RPC prefixes from user-facing error messages. ([84776cc](https://github.com/usememos/memos/commit/84776cc106745278371e5a8c8d43abca6d38e8b5)) ([b7d5d09](https://github.com/usememos/memos/commit/b7d5d09f8a7445076811d6f53b98d3445ce3afac)) ([0bfeb91](https://github.com/usememos/memos/commit/0bfeb91d50fdd4bafd15c13bb02b3e2810d4b2e4)) -* **Interface:** Corrected radio-group indicator alignment and positioned tooltip arrows outside their content panels. ([#6097](https://github.com/usememos/memos/issues/6097)) ([2d01420](https://github.com/usememos/memos/commit/2d01420c23372d5708904ec78e03485edb44d49b)) ([#6095](https://github.com/usememos/memos/issues/6095)) ([773e56e](https://github.com/usememos/memos/commit/773e56e537657508af4e357f9c8845af4d4f15e8)) - -## [0.30.0-rc.1](https://github.com/usememos/memos/compare/v0.29.1...v0.30.0-rc.1) (2026-07-14) - - -### ⚠ BREAKING CHANGES - -* **Access control:** Instances without `--instance-url` (or `MEMOS_INSTANCE_URL`) now run in private mode. Anonymous visitors are sent to sign-in and anonymous API access is limited to setup, authentication, and shared-memo routes. Set the instance URL to retain the previous public behavior. ([d1cef7a](https://github.com/usememos/memos/commit/d1cef7a9ab23e8c93f76b2f32661c720c733536d)) -* **Filters:** `now()` has been replaced by the `now` timestamp variable, and time fields now use CEL timestamps. Update saved shortcuts to use expressions such as `created_ts >= now - duration("24h")` or `timestamp()` instead of comparing time fields with bare epoch values. ([26f4b73](https://github.com/usememos/memos/commit/26f4b73cb9a996f9232daad2b5daa34360742697)) -* **MCP:** The MCP server is now a stateless, tools-only endpoint generated from the OpenAPI schema. The previous prompts, resources, tool-filtering headers and route aliases, and unprefixed tool names have been removed. Clients that used them must switch to `/mcp` and the new service-prefixed tool names. ([#6026](https://github.com/usememos/memos/issues/6026)) - -### Highlights - -* **Markdown editor:** Rebuilt the editor as a single CodeMirror 6 decorated-source editor. Markdown is preserved verbatim while headings, formatting, tags, and mentions are styled in place. The editor also adds tag completion, list indentation, and a toggleable formatting toolbar with headings, lists, task lists, code blocks, bold, italic, strikethrough, and inline code. ([5a73d7d](https://github.com/usememos/memos/commit/5a73d7d3e56f853a965207ac709e8f5e84918959)) ([e3c231f](https://github.com/usememos/memos/commit/e3c231fcac5691f9590a5d685bdebec23b73be35)) -* **MCP:** Replaced the hand-written MCP implementation with a curated OpenAPI-driven tool surface that reuses the public API's authentication and authorization. The final toolset includes memo, comment, relation, reaction, shortcut, identity, and attachment operations, including attachment uploads. ([777d227](https://github.com/usememos/memos/commit/777d227eb992c4feccd5d78c781cf8e9094e38de)) ([0e1d821](https://github.com/usememos/memos/commit/0e1d821fb84310feff40b90d899403d45bced596)) -* **Deployment configuration:** Identity providers and supported instance settings can be supplied as validated JSON files under `/etc/secrets`. File-backed settings act as runtime overrides and cannot be changed through the UI or API until the files are removed. ([0038295](https://github.com/usememos/memos/commit/0038295bbc772b38425b6c7f9ca814e4d1e44260)) -* **Memo feeds:** Added persisted controls for one, two, three, or automatically fitted columns; compact mode; and link previews. Multi-column feeds stay balanced as cards resize, while newly created memos remain easy to find above pinned content. ([177d65a](https://github.com/usememos/memos/commit/177d65a90e321fa975a7cf19bd3c075143af5c10)) ([e3e4ae1](https://github.com/usememos/memos/commit/e3e4ae10512f514f71729779b5096d0d591c8cf4)) -* **Webhooks:** Added Standard Webhooks HMAC-SHA256 signing secrets, webhook editing, and a signing-status indicator. Secrets are generated server-side, shown after creation, and can be revealed later from the edit dialog; malformed secrets now fail validation. ([#6013](https://github.com/usememos/memos/issues/6013)) ([#6027](https://github.com/usememos/memos/issues/6027)) -* **Filters:** Expanded CEL shortcuts with string matching, regular expressions, collection predicates, timestamp accessors, set operations, and an untagged-memos example. ([f0e4a56](https://github.com/usememos/memos/commit/f0e4a5624f4371e08fb0c41510891c9f8cce6ba0)) ([b787bfa](https://github.com/usememos/memos/commit/b787bfa75f74d8ee5ec271bd308c2e5a0389ed35)) -* **Tag settings:** Tag colors and content-blur rules are now per-user. Existing instance tag settings are copied to current users during migration. ([#6017](https://github.com/usememos/memos/issues/6017)) -* **Internationalization:** Added a searchable locale picker, expanded European locale coverage, and completed missing Japanese and Simplified Chinese translations. ([4183985](https://github.com/usememos/memos/commit/418398587cef90151745ba0dbc51cef4762045ca)) ([a47d049](https://github.com/usememos/memos/commit/a47d04954e75c54491138601c72f1c0cbe140f3c)) -* **Interface:** Refreshed the sign-in, sign-up, and About pages and aligned common controls across the app. Compact rendering is now opt-in in single-column feeds, so full memo content is shown by default. ([564da94](https://github.com/usememos/memos/commit/564da949cb87491ca8e493d2f7aedcd2ef9545a1)) ([cafa56f](https://github.com/usememos/memos/commit/cafa56f1a8c9091062a4b220284e8ca697b050e8)) -* **Markdown and storage:** Added GFM footnote rendering and navigation, plus an `insecure_skip_tls_verify` option for S3-compatible storage with self-signed certificates. ([1020060](https://github.com/usememos/memos/commit/10200606db24e3d70fb8efefee99c7b0a369ddea)) ([#6039](https://github.com/usememos/memos/issues/6039)) - -### Fixes and polish - -* **Authentication and setup:** Stabilized SSO option loading, added OAuth client-auth auto-detection, and distinguished fresh instances from populated instances that no longer have an admin. ([6c17e87](https://github.com/usememos/memos/commit/6c17e87cf61cd9c62ea4ef4e25d4adb5603ffc88)) ([96cb653](https://github.com/usememos/memos/commit/96cb65320b714ef8d7993ddb7c9182350ee9da4c)) -* **Editor:** Improved formatting toggles and keyboard shortcuts, file paste and drop handling, focus-mode layout, caret behavior in empty space, and CodeMirror spacing. ([c349c15](https://github.com/usememos/memos/commit/c349c1549e49950e3171b7de28faba5d89249cfa)) ([#6076](https://github.com/usememos/memos/issues/6076)) ([#6093](https://github.com/usememos/memos/issues/6093)) -* **Memos and comments:** Preserved expanded task-list state, added pagination so every comment page can be loaded, and included the parent memo relation in comment webhook payloads. ([ecbe2ab](https://github.com/usememos/memos/commit/ecbe2ab7977fcd3521aeae1226e816a9dc2a6a40)) ([#6083](https://github.com/usememos/memos/issues/6083)) -* **Tags:** Tags inside links are no longer parsed as memo tags, literal tags can be escaped with a backslash, and tag names support Unicode combining marks. ([a50ce09](https://github.com/usememos/memos/commit/a50ce09e8159836aed1a97fa717488283378200f)) ([#6051](https://github.com/usememos/memos/issues/6051)) -* **API and security:** Cross-origin API requests now work with bearer tokens while cookie authentication remains same-origin, and `ListUsers` now returns consistent paginated results. ([385fa22](https://github.com/usememos/memos/commit/385fa22056c51a42a0eb99fd08a8876009c2c52d)) ([4bc3928](https://github.com/usememos/memos/commit/4bc39280290b0f2612ff52285689854b6cf1344b)) -* **Interface:** Replaced mismatched memo skeletons with a delayed spinner, improved mobile control spacing, and truncated long location labels without hiding the full address. ([#6047](https://github.com/usememos/memos/issues/6047)) ([3b601b8](https://github.com/usememos/memos/commit/3b601b841670ece4a2832341a99ccc74124a745e)) -* **Container:** Prevented the entrypoint from restarting indefinitely when `MEMOS_UID=0`. ([#6061](https://github.com/usememos/memos/issues/6061)) - -## [0.29.1](https://github.com/usememos/memos/compare/v0.29.0...v0.29.1) (2026-06-04) - - -### Bug Fixes - -* **markdown:** keep task item content in one grid column ([7c3bff4](https://github.com/usememos/memos/commit/7c3bff4e98223fb99a5d49f093e3cd57dd140ba4)) -* support <meta name=description> in link previews ([#6000](https://github.com/usememos/memos/issues/6000)) ([e8d32e8](https://github.com/usememos/memos/commit/e8d32e87d1d6e4927250ad5794ba5965e0260153)) -* **web:** render video attachment posters on mobile ([0e2a9a9](https://github.com/usememos/memos/commit/0e2a9a9c0ce0e2da63535210c553b3ae2f79b239)) - -## [0.29.0](https://github.com/usememos/memos/compare/v0.28.0...v0.29.0) (2026-05-27) - - -### Features - -* **about:** add about page with bird sprites ([411ba7b](https://github.com/usememos/memos/commit/411ba7b34c0c23ad217a7897835097887a28a036)) -* **activity-calendar:** aggregate by ViewContext.timeBasis ([8daef1d](https://github.com/usememos/memos/commit/8daef1dc89544512fff78fd64d8216b2babc2e42)) -* add <Placeholder> component with ASCII bird states ([#5949](https://github.com/usememos/memos/issues/5949)) ([8c16ffa](https://github.com/usememos/memos/commit/8c16ffa1f1410f9413cb57ebe251b4b604f9aeff)) -* add configurable `--log-level` flag ([#5934](https://github.com/usememos/memos/issues/5934)) ([f1e2a06](https://github.com/usememos/memos/commit/f1e2a06b46c7f45ba6562c308d2703fdfb4067b0)) -* add dedicated shortcuts page ([#5942](https://github.com/usememos/memos/issues/5942)) ([1df6479](https://github.com/usememos/memos/commit/1df6479443c334732b862d60a0f76e61f00ebb89)) -* add link metadata endpoints ([9c5c604](https://github.com/usememos/memos/commit/9c5c604944428d3f682f35c9d05a87c1d4c3152f)) -* **frontend:** add pixel bird tilemaps ([cf55f11](https://github.com/usememos/memos/commit/cf55f1107273c928e7c2d6bc26df5f3efea26458)) -* **memo:** add task list quick actions ([#5983](https://github.com/usememos/memos/issues/5983)) ([648b3bd](https://github.com/usememos/memos/commit/648b3bd812e5bf2b1abb9f8b3529efefe4734e7c)) -* **memo:** create memos on the selected calendar date ([#5925](https://github.com/usememos/memos/issues/5925)) ([ef55013](https://github.com/usememos/memos/commit/ef55013418d68e2d6a24a6d02a0365c1ffff03d7)) -* **notification:** add smtp email settings ([cd4f28a](https://github.com/usememos/memos/commit/cd4f28ae1058a125e245ea0a6eae16aea71b8f9d)) -* **placeholder:** add woodpecker tilemap ([638e4f3](https://github.com/usememos/memos/commit/638e4f398e90c556f70af150a79538312c8fc760)) -* render link metadata cards ([0bc5669](https://github.com/usememos/memos/commit/0bc56694b0ca347ab1eb083f62997a22007b763d)) -* **stats:** admin instance resource statistics ([ea0625d](https://github.com/usememos/memos/commit/ea0625da45a419e08158ab4102051f3fe5e59b87)) -* **stats:** support filtered all-user stats ([88ac3ec](https://github.com/usememos/memos/commit/88ac3ec31ee3e808db82663c04a31cf730d1221e)) -* **transcription:** explicit STT settings with provider, model, prompt ([#5926](https://github.com/usememos/memos/issues/5926)) ([238f27d](https://github.com/usememos/memos/commit/238f27dea149492a78a8994470b0aac55fece78d)) - - -### Bug Fixes - -* avoid update event on memo create attachments ([#5961](https://github.com/usememos/memos/issues/5961)) ([3c3382a](https://github.com/usememos/memos/commit/3c3382a3c652bed3b58058931ff3cbf1d875b9a8)) -* delete user cleanup ([#5981](https://github.com/usememos/memos/issues/5981)) ([e53b7d9](https://github.com/usememos/memos/commit/e53b7d96e70965529ba3b04ea720ea6966f77b60)) -* **editor:** wrap selected text when pasting URL ([e0bb3a2](https://github.com/usememos/memos/commit/e0bb3a2e684e932309df2f9fb0ff774ce8e6b692)) -* **fileserver:** preserve HDR image metadata in thumbnails ([c724232](https://github.com/usememos/memos/commit/c7242324a18962e453e7f2a0309a7c07b358bdbe)) -* **frontend:** correct static cache headers ([084f40b](https://github.com/usememos/memos/commit/084f40bc9e5922ff2d41c08dce837b96696437aa)) -* **frontend:** use correct url path for memos in sitemap.xml ([#5921](https://github.com/usememos/memos/issues/5921)) ([603781f](https://github.com/usememos/memos/commit/603781f792b2603fbda93146988a64a93c92d760)) -* **httpgetter:** prevent DNS rebinding in link metadata fetch ([078488c](https://github.com/usememos/memos/commit/078488ca818626fbcab69bdfb4b93b58dca6b6eb)) -* **markdown:** align list items with checkboxes ([e008b1a](https://github.com/usememos/memos/commit/e008b1a23c77945eff87707eb15578d4d6d74e4c)) -* **memo:** enforce parent visibility for comments ([4a1e401](https://github.com/usememos/memos/commit/4a1e401bd99c7850ac48e9693b25c9ebeecfb042)) -* **s3presign:** preserve motion media payload ([7f1f53f](https://github.com/usememos/memos/commit/7f1f53ffc417962f6930d1e6e3783eacd911003d)) -* **security:** enforce attachment ownership on memo updates ([35bf761](https://github.com/usememos/memos/commit/35bf761b8c2c3f155bdc06e9b373b6076116a725)) -* **sse:** stream initial response and refresh tokens ([21303e8](https://github.com/usememos/memos/commit/21303e879d2c7a857306206d2cbdae83f61983e6)) -* **user:** omit internal settings from list responses ([#5917](https://github.com/usememos/memos/issues/5917)) ([1df3fe7](https://github.com/usememos/memos/commit/1df3fe79559ccf94b6c71e9ffb58e870ed43820d)) -* **web:** sync avatar changes immediately after profile update ([#5903](https://github.com/usememos/memos/issues/5903)) ([328396a](https://github.com/usememos/memos/commit/328396a97f2219592032e8418c383e0ab7edaca6)) - - -### Performance Improvements - -* lazy load heavy first-screen dependencies ([#5947](https://github.com/usememos/memos/issues/5947)) ([a6024ee](https://github.com/usememos/memos/commit/a6024eebf129c4b8fb65ee0cba09c6657274bfde)) - -## [0.28.0](https://github.com/usememos/memos/compare/v0.27.1...v0.28.0) (2026-04-27) - - -### Features - -* **auth:** add SSO user identity linkage ([#5883](https://github.com/usememos/memos/issues/5883)) ([d688914](https://github.com/usememos/memos/commit/d688914b2864791eeadbf21c882608632875f17c)) -* **memos:** choose created or updated time for memos ([#5894](https://github.com/usememos/memos/issues/5894)) ([c268551](https://github.com/usememos/memos/commit/c268551a16929a2cbea6891951feff91926bba59)) -* redesign account and SSO management ([#5886](https://github.com/usememos/memos/issues/5886)) ([ee17998](https://github.com/usememos/memos/commit/ee1799851e88674a6920c7a56d93428fcf95e662)) - - -### Bug Fixes - -* **auth:** harden authorization and username validation ([#5890](https://github.com/usememos/memos/issues/5890)) ([0fb83a7](https://github.com/usememos/memos/commit/0fb83a745dd5057ade45a3caad2c444af2239113)) -* disable modal prop on DropdownMenu to prevent scroll disappearing ([#5861](https://github.com/usememos/memos/issues/5861)) ([d98f665](https://github.com/usememos/memos/commit/d98f6659190b8d1a8252e64549d9120d85e05d33)) -* fix legacy username auth flows ([#5885](https://github.com/usememos/memos/issues/5885)) ([30c0611](https://github.com/usememos/memos/commit/30c0611a82f9254952a74650095105254f2940e4)) -* **markdown:** split mixed task and bullet lists ([e2c6084](https://github.com/usememos/memos/commit/e2c60845eaff9a78b8d8eb3ccc9a067ef5690976)) -* reduce list memo query overhead ([#5880](https://github.com/usememos/memos/issues/5880)) ([5063804](https://github.com/usememos/memos/commit/50638040f618b02b0c6d010e1d41554c75067517)) -* **web:** preserve task checkbox state ([#5867](https://github.com/usememos/memos/issues/5867)) ([b5863d7](https://github.com/usememos/memos/commit/b5863d76be3cfbf3e0f8237d8e762122b5a0a679)) - -## [0.27.1](https://github.com/usememos/memos/compare/v0.27.0...v0.27.1) (2026-04-19) - - -### Bug Fixes - -* mixed-case user resource names ([#5853](https://github.com/usememos/memos/issues/5853)) ([01be01f](https://github.com/usememos/memos/commit/01be01f4b7676af41bdd1758b1e9b096aa922546)) -* **release:** inject build version into artifacts ([f8a304b](https://github.com/usememos/memos/commit/f8a304bae33086320b39095d631288156eec4249)) -* user resource names can be uuidv4 from idp sub claim ([#5856](https://github.com/usememos/memos/issues/5856)) ([bbded58](https://github.com/usememos/memos/commit/bbded584ce85a856d863485768e08b53adec7244)) - -## [0.27.0](https://github.com/usememos/memos/compare/v0.26.2...v0.27.0) (2026-04-18) - - -### Features - -* add --allow-private-webhooks flag to bypass SSRF protection ([#5694](https://github.com/usememos/memos/issues/5694)) ([cd5816c](https://github.com/usememos/memos/commit/cd5816c428931f56561f7d48b649a33858812539)) -* add blur_content attribute to tag metadata settings ([#5767](https://github.com/usememos/memos/issues/5767)) ([45b2153](https://github.com/usememos/memos/commit/45b21530d9ebbc730e77bcbcf407f4c295b52e93)) -* add Gemini transcription provider ([#5830](https://github.com/usememos/memos/issues/5830)) ([d87539a](https://github.com/usememos/memos/commit/d87539a1e1261590ab355220e33fa0ae00bd9431)) -* add GitHub release installer and release workflow ([1ed542c](https://github.com/usememos/memos/commit/1ed542c21db421e9aa0cc47417a92c6bd103e257)) -* add live refresh via Server-Sent Events (SSE) with visual indicator ([#5638](https://github.com/usememos/memos/issues/5638)) ([ea0892a](https://github.com/usememos/memos/commit/ea0892a8b26d8806a093e3a942562dfc22794f68)) -* add MCP server with PAT authentication ([47d9414](https://github.com/usememos/memos/commit/47d9414702dc18966af385352b960bfe451511b7)) -* add outline navigation to memo detail sidebar ([#5771](https://github.com/usememos/memos/issues/5771)) ([6b30579](https://github.com/usememos/memos/commit/6b3057990396f9cb6f21706c2e99dddebc35ffd5)) -* **ai:** add BYOK audio transcription ([#5832](https://github.com/usememos/memos/issues/5832)) ([101704c](https://github.com/usememos/memos/commit/101704c8eac17c7f34508d8db6c53bc972061cdb)) -* **ai:** add instance AI providers and transcription ([#5829](https://github.com/usememos/memos/issues/5829)) ([83ed32f](https://github.com/usememos/memos/commit/83ed32f1195841d2d6c057c3e00086a3147879a2)) -* **attachments:** add Live Photo and Motion Photo support ([#5810](https://github.com/usememos/memos/issues/5810)) ([4b4e719](https://github.com/usememos/memos/commit/4b4e719470184e49cd62084b1aa53c9a777a9fec)) -* **cli:** add version subcommand ([#5731](https://github.com/usememos/memos/issues/5731)) ([0ba4c0f](https://github.com/usememos/memos/commit/0ba4c0f397c532a5a314f35ddeb3ce3633e84d42)) -* **editor:** add voice note recording to the memo composer ([#5801](https://github.com/usememos/memos/issues/5801)) ([c0d5854](https://github.com/usememos/memos/commit/c0d5854f678f357cf4054d448e0311f2ee90f8ac)) -* extract title from first H1 heading into memo property ([#5726](https://github.com/usememos/memos/issues/5726)) ([1e688b2](https://github.com/usememos/memos/commit/1e688b2a5d78c2972f4b0078a7b033dae5d1cbf3)) -* **i18n:** update sse connect label in Chinese ([#5732](https://github.com/usememos/memos/issues/5732)) ([89c6902](https://github.com/usememos/memos/commit/89c69028953fa33dbb6e0e257d764636c0fc2d09)) -* **instance:** add canonical tag metadata setting ([#5736](https://github.com/usememos/memos/issues/5736)) ([65d14fb](https://github.com/usememos/memos/commit/65d14fbb63053fc1fbf1f63881c81adbc9d01671)) -* **instance:** add notification transport setting ([#5737](https://github.com/usememos/memos/issues/5737)) ([a249d06](https://github.com/usememos/memos/commit/a249d06e2e0f33e0e3fea34471a891352dacc466)) -* **mcp:** enhance MCP server with full capabilities and new tools ([#5720](https://github.com/usememos/memos/issues/5720)) ([b8e9ee2](https://github.com/usememos/memos/commit/b8e9ee2b26a59e1b19aab6db3ca39656fc18785a)) -* **mcp:** harden tool exposure and side effects ([#5850](https://github.com/usememos/memos/issues/5850)) ([583c3d2](https://github.com/usememos/memos/commit/583c3d24f4d785faa5e034c1b88ed90eda119baa)) -* **mcp:** refactor MCP server to standard protocol structure ([803d488](https://github.com/usememos/memos/commit/803d488a5f8f55477cd3ad4cc4cf0fac98901dd3)) -* **memo-editor:** add compact live waveform recorder panel ([#5817](https://github.com/usememos/memos/issues/5817)) ([e51985a](https://github.com/usememos/memos/commit/e51985a29ffeeecd318b2fb793358ed45bb0eff4)) -* **memo-preview:** support comment metadata in previews ([#5768](https://github.com/usememos/memos/issues/5768)) ([e176b28](https://github.com/usememos/memos/commit/e176b28c801cc3bb3718208a96a7d64c36620d0f)) -* **memo:** add image sharing in detail view ([38fc22b](https://github.com/usememos/memos/commit/38fc22b7541b8a9ddcd848cf77054fcf844eb87f)) -* **memo:** add share links for private memos ([#5742](https://github.com/usememos/memos/issues/5742)) ([3f3133d](https://github.com/usememos/memos/commit/3f3133d6e2f404061e147f9dd2424680dc0303a3)) -* **mentions:** add memo mention parsing, notifications, and rendering ([#5811](https://github.com/usememos/memos/issues/5811)) ([24fc8ab](https://github.com/usememos/memos/commit/24fc8ab8ca68d092e7b12a5d51c48ca9420f72b5)) -* replace auto-increment ID with UID for identity provider resource names ([#5687](https://github.com/usememos/memos/issues/5687)) ([92d937b](https://github.com/usememos/memos/commit/92d937b1aa87365152edc005a3b736e6bf9b9e45)) -* show inline comment preview in list view ([3a5d3c8](https://github.com/usememos/memos/commit/3a5d3c8ff92ae5c24559dc4574300d6475820a87)) -* **store:** change default storage type to local filesystem ([78efa68](https://github.com/usememos/memos/commit/78efa6802e2fd96c981e86c5b658fb4b5c05091f)) -* treat tag setting keys as anchored regex patterns ([#5759](https://github.com/usememos/memos/issues/5759)) ([9e04049](https://github.com/usememos/memos/commit/9e04049632e63f1cf53535773f170c1aa5af7168)) -* **ui:** allow navigating between images with arrows in preview dialog ([#5669](https://github.com/usememos/memos/issues/5669)) ([104d2ec](https://github.com/usememos/memos/commit/104d2ec0a6973e983c46724165fdc0916515ad16)) -* **user:** add per-user tag metadata settings ([#5735](https://github.com/usememos/memos/issues/5735)) ([330291d](https://github.com/usememos/memos/commit/330291d4d9fa95649e940001898929b4f6f0367e)) -* **web:** add demo mode banner ([#5836](https://github.com/usememos/memos/issues/5836)) ([35504cc](https://github.com/usememos/memos/commit/35504cc8bd6f9921291fb565633d549388a3f948)) -* **webhook:** dispatch webhook on memo comment creation ([7c1defb](https://github.com/usememos/memos/commit/7c1defba01fbc91cc81e1a0841cecb6738056db7)) - - -### Bug Fixes - -* access token refresh on web app ([#5681](https://github.com/usememos/memos/issues/5681)) ([3010f10](https://github.com/usememos/memos/commit/3010f10eafb49af5aadd71a94b3ef7a6ec71f617)) -* add unix socket file permission setting (755 -> 660) ([#5849](https://github.com/usememos/memos/issues/5849)) ([0fc1dab](https://github.com/usememos/memos/commit/0fc1dab28b33f7fdbe9a21cd3bd3affe75dd7f19)) -* **api:** appease image size lint ([ff6389a](https://github.com/usememos/memos/commit/ff6389a5ef73772fcb5c132bf1cb169fb4744c00)) -* **api:** improve SSE hub design and fix double-broadcast on comments ([c53677f](https://github.com/usememos/memos/commit/c53677fcba202a8eed35c8ecdfaacea5152b8691)) -* **api:** make credentials write-only and restrict sensitive settings to admins ([9d3a74b](https://github.com/usememos/memos/commit/9d3a74bcccf934aa2fa95ee240b56cc3b3a25776)) -* **api:** reduce memory pressure in backend paths ([c456637](https://github.com/usememos/memos/commit/c45663761d148e94d3e1b30f4810922e7c2571ab)) -* **api:** remove public activity service ([#5734](https://github.com/usememos/memos/issues/5734)) ([04f239a](https://github.com/usememos/memos/commit/04f239a2fc74f7090c779a6a7b8a08238fd31b88)) -* **api:** restrict user email exposure to self and admins ([#5784](https://github.com/usememos/memos/issues/5784)) ([a24d420](https://github.com/usememos/memos/commit/a24d4209222814e4a8bedfc0392e91462bc855ad)) -* **api:** switch user resource names to usernames ([#5779](https://github.com/usememos/memos/issues/5779)) ([acddef1](https://github.com/usememos/memos/commit/acddef1f3dcca44806bcbb85e9dc5cae7daa5285)) -* **api:** tolerate missing related users in memo conversions ([#5809](https://github.com/usememos/memos/issues/5809)) ([25feef3](https://github.com/usememos/memos/commit/25feef3aadd34bfd474d7e3b685815a6509bc4c6)) -* **auth:** recover session via refresh cookie when localStorage is empty ([#5748](https://github.com/usememos/memos/issues/5748)) ([551ee1d](https://github.com/usememos/memos/commit/551ee1d81f398abdcaf73a0c2b782c8379b0e3f2)) -* backend tests action ([065e817](https://github.com/usememos/memos/commit/065e817470b1d3b6b00222525791b85d825c1492)) -* clear content search filter when selecting shortcut ([#5499](https://github.com/usememos/memos/issues/5499)) ([2c3f9e3](https://github.com/usememos/memos/commit/2c3f9e3bfbe09e5d0028d1525c1df83c03f547c9)) -* correct typos in comments, error messages, and identifiers ([#5704](https://github.com/usememos/memos/issues/5704)) ([8f43e80](https://github.com/usememos/memos/commit/8f43e8075b62706f99da4005ab04b165b35215f6)) -* detect legacy installations with empty schema version ([9628d3d](https://github.com/usememos/memos/commit/9628d3de21289e887ffeb6cc4b6710913a0de44e)) -* **editor:** show newly linked memos when editing a memo with attachments ([026ea92](https://github.com/usememos/memos/commit/026ea92f7b4005c30ca84340c22018740659ab51)) -* ensure comment divs span full width in MemoDetail ([ce44164](https://github.com/usememos/memos/commit/ce441644af34ffff156f1793c40011c2b82e8d5f)) -* **fileserver:** render SVG attachment previews ([40fd700](https://github.com/usememos/memos/commit/40fd700fb8be27a8d7a300a2636cf4f366572176)) -* **filter:** enforce CEL syntax semantics ([0e89407](https://github.com/usememos/memos/commit/0e89407ee91deda87e0df7464a89d26d1e9a88b3)) -* **frontend:** restore sitemap and robots routes ([fee7fcd](https://github.com/usememos/memos/commit/fee7fcd6608b9d07da1f146c33c9bb8f898f708f)) -* handle chunk load errors after redeployment with auto-reload ([#5703](https://github.com/usememos/memos/issues/5703)) ([bdd3554](https://github.com/usememos/memos/commit/bdd3554b897246bac5c1e6fd801495c24b6a656e)) -* harden memo content iframe and HTML sanitization ([7e21b72](https://github.com/usememos/memos/commit/7e21b728b346e80023c93e8986130f83e70584f9)) -* hide transcribe button without AI provider ([ab53329](https://github.com/usememos/memos/commit/ab5332901fd6626f0a2ae6b99671af9663f68078)) -* improve image preview dialog and live photo trigger ([aafcc21](https://github.com/usememos/memos/commit/aafcc21ae6f96a313fb372365dd1af8a1a69d1ba)) -* improve installer compatibility and docs ([f90d9a4](https://github.com/usememos/memos/commit/f90d9a49a78d0764a6c5cf8f6720e69ea1164b25)) -* improve KaTeX and Mermaid error handling and overflow ([6b37fcc](https://github.com/usememos/memos/commit/6b37fcc01b5dcded6a2ec254fbaf895f7812d072)) -* include plain URLs and tags in memo snippet generation ([#5688](https://github.com/usememos/memos/issues/5688)) ([3d4f793](https://github.com/usememos/memos/commit/3d4f793f97b567bda823a60b7fe10e09e14499ce)) -* **lint:** correct goimports struct literal alignment after removing write-only credential fields ([#5794](https://github.com/usememos/memos/issues/5794)) ([9610ed8](https://github.com/usememos/memos/commit/9610ed8fc809b3e7aa4b93e4909634957fa94cf7)) -* **map:** align dark mode map styling ([7ac9989](https://github.com/usememos/memos/commit/7ac9989d43f3967b466f340da3841290d86b20f1)) -* **map:** refine Leaflet controls and memo map styling ([894b3eb](https://github.com/usememos/memos/commit/894b3eb045c7d2c2acce847c34a85295c909dcf7)) -* **markdown:** support height/width attributes on img elements ([737acbb](https://github.com/usememos/memos/commit/737acbba2f5e3dd911da3a77d2d5d1cde1bf8ba1)) -* **memo-editor:** scope Cmd+Enter save to the active editor ([#5745](https://github.com/usememos/memos/issues/5745)) ([05810e7](https://github.com/usememos/memos/commit/05810e7882cb03d448d9d8fa84bc6ca54eafbed0)) -* **mysql:** handle CreateMemo custom timestamps with FROM_UNIXTIME ([#5673](https://github.com/usememos/memos/issues/5673)) ([09d73e8](https://github.com/usememos/memos/commit/09d73e8b6e16c43a61767817909a472916c83daa)) -* normalize attachment MIME types before validation ([c3e7e2c](https://github.com/usememos/memos/commit/c3e7e2c316d01bf857931c38303efc87307f2a19)) -* preserve draft content when tab is suspended or editor remounts ([9ca7122](https://github.com/usememos/memos/commit/9ca71229a6c0dfad44b76ed06fced46c5bef49c7)) -* prevent local attachment uploads from overwriting files ([4add9b0](https://github.com/usememos/memos/commit/4add9b04ad5d0b7608c985281f5975dc39f9a572)) -* prevent stale comment drafts from being restored ([e520b63](https://github.com/usememos/memos/commit/e520b637fd8d0f6331674003abe72f9dfbae8231)) -* remove duplicate Japanese locale keys ([efeb28c](https://github.com/usememos/memos/commit/efeb28c872a2bd6edd28fa3b68bd0b15af923d50)) -* render audio attachments as inline players ([#5699](https://github.com/usememos/memos/issues/5699)) ([2ccb98a](https://github.com/usememos/memos/commit/2ccb98a6cbc40544e81eeeca2a2cbbaf8348f45e)) -* restrict archived memo access to creator only ([#5707](https://github.com/usememos/memos/issues/5707)) ([f4154d0](https://github.com/usememos/memos/commit/f4154d090be3896c8e0dd83440f24953bbeb308c)) -* **routing:** redirect unauthenticated users to /explore when public visibility is allowed ([98859eb](https://github.com/usememos/memos/commit/98859eb5e5065a7c12ada983b7c38c5af5035bb6)) -* **server:** close SSE clients during shutdown ([a5ddd5a](https://github.com/usememos/memos/commit/a5ddd5adafef282f00b23e00e145119d4316f24f)) -* sync html lang attribute with active locale ([#5753](https://github.com/usememos/memos/issues/5753)) ([be00abe](https://github.com/usememos/memos/commit/be00abe852479820b7c574e15e276d70961ab7bd)) -* tag parsing truncates emojis with variation selectors ([#5496](https://github.com/usememos/memos/issues/5496)) ([3ea6ea3](https://github.com/usememos/memos/commit/3ea6ea3108f58dc34f39fa6f21d761bd2e97732b)) -* **tags:** allow blur-only tag metadata ([#5800](https://github.com/usememos/memos/issues/5800)) ([1921b57](https://github.com/usememos/memos/commit/1921b57662c2129d179930f71e5c42caf9070a19)) -* toggle focus mode do not reset editor height ([#5504](https://github.com/usememos/memos/issues/5504)) ([0729779](https://github.com/usememos/memos/commit/0729779e0427c68bdbc5b6b711a5683f66ba9bbc)) -* **ui:** show comment editor above the comment list ([#5662](https://github.com/usememos/memos/issues/5662)) ([6b0736b](https://github.com/usememos/memos/commit/6b0736b29325ff7698b7395dc761f2ca41e6521c)) -* **ui:** unify metadata component styles across MemoView and MemoEditor ([664b8c5](https://github.com/usememos/memos/commit/664b8c56290026ba2beb7b75db24c684824b8670)) -* unify live photo previews around LIVE badge playback ([6b0487d](https://github.com/usememos/memos/commit/6b0487dcd857ba72189ca0624cb4985961f08f25)) -* **webhooks:** trigger memo updates for attachment and relation changes ([#5795](https://github.com/usememos/memos/issues/5795)) ([acbc914](https://github.com/usememos/memos/commit/acbc914dea8d4e533028b03929193a4af1ac32b4)) -* **web:** prevent MemoContent prop leaks ([22519b5](https://github.com/usememos/memos/commit/22519b57a0a971ab927a03015c994c63b8c3f1da)) -* **web:** refine attachment media layout ([a0d83e1](https://github.com/usememos/memos/commit/a0d83e1a9e9d0ba50a0103e594adb011728faf8c)) -* **web:** refresh memo detail cache after editor save ([333c9df](https://github.com/usememos/memos/commit/333c9df233240a843a9e62d17c6ff464690636f8)) -* **web:** use BroadcastChannel to sync token refreshes across tabs ([bbdc998](https://github.com/usememos/memos/commit/bbdc998646e8093223a448378a2c29690f0d8612)) - - -### Performance Improvements - -* batch load memo relations when listing memos ([#5692](https://github.com/usememos/memos/issues/5692)) ([1e82714](https://github.com/usememos/memos/commit/1e82714a52c72455a6ba02605cc641d7ad4fbf1a)) diff --git a/README.md b/README.md index e346ba112..5ba209a37 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,12 @@ docker run -d \ Other install options are in the [deployment guide](https://usememos.com/docs/deploy). +Releases use `YY.MM`, with optional point releases such as `26.09.1` and release +candidates such as `26.09-rc.1`. Calendar release tags have no `v` prefix. The Docker `stable` tag follows stable releases; +`canary` follows development builds. If upgrading from a release before v0.31.0, +run [v0.31.0](https://github.com/usememos/memos/releases/tag/v0.31.0) successfully. +See the [upgrade requirements](store/migration/README.md) for earlier versions. + ## Web Clipper Save pages, selections, and images from your browser straight into Memos as source-linked Markdown. Get the [Memos Web Clipper](https://usememos.com/web-clipper) for [Chrome](https://chromewebstore.google.com/detail/memos-web-clipper/nebaoebnljalfegiidibihhkebeiklbl) or [Firefox](https://addons.mozilla.org/en-US/firefox/addon/memos-web-clipper/). diff --git a/docs/design/multi-spaces.md b/docs/design/multi-spaces.md index 3c98d1979..3752d2124 100644 --- a/docs/design/multi-spaces.md +++ b/docs/design/multi-spaces.md @@ -140,6 +140,10 @@ General account erasure remains deferred. As a fail-closed guard, user hard dele ### Persistence and migration +Historical upgrade scripts are now provided by the v0.31.0 release, with the +current binary retaining the fresh-install schemas. See the +[database migration baseline](../../store/migration/README.md). + ```text space(id, uid, title, description) space_member(space_id, user_id, status INVITED | ACTIVE, role ADMIN | USER) @@ -151,7 +155,7 @@ The Space-user pair is unique and represents one current relationship slot. `INV `status` is required and has no default or database `CHECK`; Store logic writes and recognizes `INVITED` and `ACTIVE`, while unknown values fail closed in authorization queries. The existing role constraint remains unchanged. The initial version does not record inviter, invitation, Space, or membership timestamps; they can be added when a concrete attribution, expiration, audit, or ordering requirement exists. A nullable `memo.space_id` directly enforces zero-or-one placement; an association table is unnecessary. Existing `memo_relation` rows remain the source of truth for comments. -The change ships in migration `0.31` for SQLite, MySQL, and PostgreSQL, with equivalent fresh-install schemas. Existing membership rows are backfilled to `ACTIVE`. Existing memos keep their UID, author, visibility, relations, permalink, and become Unassigned. Comment rows and comment visibility are not rewritten. SQLite rebuilds the affected tables where its `ALTER TABLE` support requires it. +The change shipped in v0.31.0, migration `0.31` for SQLite, MySQL, and PostgreSQL, with equivalent fresh-install schemas. Existing membership rows are backfilled to `ACTIVE`. Existing memos keep their UID, author, visibility, relations, permalink, and become Unassigned. Comment rows and comment visibility are not rewritten. SQLite rebuilds the affected tables where its `ALTER TABLE` support requires it. Space creation, invitation transitions, membership changes, placement and audience changes, comment creation, memo deletion, and Space deletion use ordinary transactions where partial application would corrupt directly affected data. On MySQL and PostgreSQL, operations that create or activate a Space relationship serialize with user deletion on the target user row, and invitation creation serializes with Space deletion on the Space row. On SQLite every store transaction begins `IMMEDIATE`, so a transaction that has read a parent row holds the single write lock until it ends and a concurrent delete waits rather than committing underneath it. This prevents a concurrent delete from leaving an orphaned active membership or invitation. Space deletion directly removes assigned memos and their owned rows in the same style as existing user deletion, then uses the existing best-effort attachment storage cleanup after commit. The initial version does not introduce general transaction retries, a cleanup queue, or a global concurrency framework. diff --git a/docs/design/unique-email.md b/docs/design/unique-email.md index 77e710815..615a9a19d 100644 --- a/docs/design/unique-email.md +++ b/docs/design/unique-email.md @@ -75,7 +75,13 @@ Nullable is chosen over a partial unique index because MySQL has no partial inde The Go type `store.User.Email` stays `string`. The driver boundary maps `""` to `NULL` on write and `NULL` to `""` on read. Callers never see `NULL`. `FindUser.Email` trims and lowercases its argument before querying, so a lookup with different casing still hits the index; an empty lookup returns nothing rather than every user without an address. -### Migration +### Migration (historical v0.31.0) + +The following describes the upgrade performed by v0.31.0. Its SQL scripts, +Go preparation step, and legacy replay tests have since been removed from the +current binary. Older installations must run v0.31.0 first; see the +[database migration baseline](../../store/migration/README.md). + The change ships as `0.31/07__unique_email.sql` for each driver, plus matching `LATEST.sql` updates. The unique index is always the last statement, so a failure part-way through never leaves a constraint over unrepaired data. @@ -92,7 +98,7 @@ DDL and ordering per driver: - MySQL switches the column to `utf8mb4_bin` and nullable first, then repairs. Grouping under the server's default collation could treat accent variants as one address and clear one of them needlessly; under the binary collation the repair compares bytes, which is what the application does. - PostgreSQL alters the column, then repairs, all inside the migration transaction. -Then the unique index is created, guarded with `IF NOT EXISTS` on SQLite and PostgreSQL and with a prepared-statement check on MySQL, so the file is a no-op on a database that already carries it. The store test suite rewinds the schema version on fresh installs to exercise individual migrations, and every later migration has to tolerate that. +Then the unique index is created, guarded with `IF NOT EXISTS` on SQLite and PostgreSQL and with a prepared-statement check on MySQL, so the file is a no-op on a database that already carries it. The v0.31.0 store tests rewound the schema version on fresh installs to exercise these migrations. Current upgrade tests instead run released binaries through the fixed v0.31.0 baseline. SQL `LOWER` is not a reliable canonicalizer: SQLite folds ASCII only and PostgreSQL does the same under a C locale, so `Ä@example.com` and `ä@example.com` could both survive deduplication and the index would then permit a canonical collision. The migrator therefore gains one targeted pre-flight, not a general hook system. When the stored schema version is below this migration's version, a Go function reads every non-empty address ordered by id and first rewrites any row whose stored value differs from its Unicode-lowercased, trimmed form, so the SQL that follows sees exactly the canonical values `NormalizeEmail` would produce. It then applies the migration's rules in memory and logs one warning per duplicate group naming the username that keeps the address and the usernames that will be cleared, plus one line listing the users whose value will be cleared as malformed. Addresses themselves are not logged; usernames are enough for the operator to find the accounts. A failure in either step is logged and never blocks the migration. The log is the record. Nothing else stores the cleared values. Cleared accounts can set an address again from the profile page. @@ -127,7 +133,7 @@ The web app changes in one place: the account settings form shows the `AlreadyEx ### Testing - Store tests on all three drivers through the existing testcontainers harness: canonical-form round trip, `NULL` mapping, duplicate insert returns `ErrEmailTaken`, concurrent inserts of the same address yield exactly one success, `FindUser.Email` with mixed case hits. -- A migration test on all three drivers that seeds the pre-0.31 legacy schema fixture with mixed-case and non-ASCII duplicates, surrounding whitespace, `''`, a display-name form, interior whitespace, and a value without `@`, migrates, and asserts the survivor rule, the `NULL` conversion, case-folded lookup, the index, id continuity across the SQLite rebuild, and that re-running the migrator is a no-op. +- Historical v0.31.0 migration coverage on all three drivers seeds the pre-0.31 legacy schema fixture with mixed-case and non-ASCII duplicates, surrounding whitespace, `''`, a display-name form, interior whitespace, and a value without `@`, migrates, and asserts the survivor rule, the `NULL` conversion, case-folded lookup, the index, id continuity across the SQLite rebuild, and that re-running the migrator is a no-op. - API tests: signup, admin create, update, and `validate_only` reject malformed addresses with `InvalidArgument` and duplicates with `AlreadyExists`; SSO first login with a colliding address creates the account with no address and does not link. - Unit tests for the canonical-form function covering display-name forms, whitespace, length, and case. diff --git a/internal/version/version.go b/internal/version/version.go index 519014d1b..16e560689 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -1,12 +1,5 @@ package version -import ( - "fmt" - "strings" - - "golang.org/x/mod/semver" -) - // Version is set by release builds and defaults to a development build marker. var Version = "dev" @@ -16,41 +9,3 @@ var Commit = "unknown" func GetCurrentVersion() string { return Version } - -// GetMinorVersion extracts the minor version (e.g., "0.25") from a full version string (e.g., "0.25.1"). -// Returns the minor version string or empty string if the version format is invalid. -// Version format should be "major.minor.patch" (e.g., "0.25.1"). -func GetMinorVersion(version string) string { - versionList := strings.Split(version, ".") - if len(versionList) < 2 { - return "" - } - // Return major.minor only (first two components) - return versionList[0] + "." + versionList[1] -} - -// IsVersionGreaterOrEqualThan returns true if version is greater than or equal to target. -func IsVersionGreaterOrEqualThan(version, target string) bool { - return semver.Compare(fmt.Sprintf("v%s", version), fmt.Sprintf("v%s", target)) > -1 -} - -// IsVersionGreaterThan returns true if version is greater than target. -func IsVersionGreaterThan(version, target string) bool { - return semver.Compare(fmt.Sprintf("v%s", version), fmt.Sprintf("v%s", target)) > 0 -} - -type SortVersion []string - -func (s SortVersion) Len() int { - return len(s) -} - -func (s SortVersion) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - -func (s SortVersion) Less(i, j int) bool { - v1 := fmt.Sprintf("v%s", s[i]) - v2 := fmt.Sprintf("v%s", s[j]) - return semver.Compare(v1, v2) == -1 -} diff --git a/internal/version/version_test.go b/internal/version/version_test.go deleted file mode 100644 index 0222748d2..000000000 --- a/internal/version/version_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package version - -import ( - "slices" - "testing" - - "github.com/stretchr/testify/assert" - "golang.org/x/mod/semver" -) - -func TestIsVersionGreaterOrEqualThan(t *testing.T) { - tests := []struct { - version string - target string - want bool - }{ - { - version: "0.9.1", - target: "0.9.1", - want: true, - }, - { - version: "0.10.0", - target: "0.9.1", - want: true, - }, - { - version: "0.9.0", - target: "0.9.1", - want: false, - }, - } - for _, test := range tests { - result := IsVersionGreaterOrEqualThan(test.version, test.target) - if result != test.want { - t.Errorf("got result %v, want %v.", result, test.want) - } - } -} - -func TestIsVersionGreaterThan(t *testing.T) { - tests := []struct { - version string - target string - want bool - }{ - { - version: "0.9.1", - target: "0.9.1", - want: false, - }, - { - version: "0.10.0", - target: "0.8.0", - want: true, - }, - { - version: "0.23", - target: "0.22", - want: true, - }, - { - version: "0.8.0", - target: "0.10.0", - want: false, - }, - { - version: "0.9.0", - target: "0.9.1", - want: false, - }, - { - version: "0.22", - target: "0.22", - want: false, - }, - } - for _, test := range tests { - result := IsVersionGreaterThan(test.version, test.target) - if result != test.want { - t.Errorf("got result %v, want %v.", result, test.want) - } - } -} - -func TestSortVersion(t *testing.T) { - tests := []struct { - versionList []string - want []string - }{ - { - versionList: []string{"0.9.1", "0.10.0", "0.8.0"}, - want: []string{"0.8.0", "0.9.1", "0.10.0"}, - }, - { - versionList: []string{"1.9.1", "0.9.1", "0.10.0", "0.8.0"}, - want: []string{"0.8.0", "0.9.1", "0.10.0", "1.9.1"}, - }, - } - for _, test := range tests { - slices.SortFunc(test.versionList, func(a, b string) int { - return semver.Compare("v"+a, "v"+b) - }) - assert.Equal(t, test.versionList, test.want) - } -} diff --git a/release-please-config.json b/release-please-config.json deleted file mode 100644 index d26acd928..000000000 --- a/release-please-config.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", - "include-v-in-tag": true, - "include-component-in-tag": false, - "bump-minor-pre-major": true, - "versioning": "prerelease", - "prerelease": false, - "packages": { - ".": { - "release-type": "go", - "package-name": "memos", - "changelog-path": "CHANGELOG.md", - "changelog-sections": [ - { - "type": "feat", - "section": "Features" - }, - { - "type": "fix", - "section": "Bug Fixes" - }, - { - "type": "perf", - "section": "Performance Improvements" - }, - { - "type": "deps", - "section": "Dependencies" - }, - { - "type": "revert", - "section": "Reverts" - } - ] - } - } -} diff --git a/scripts/install.sh b/scripts/install.sh index 2baa80718..e07361f0e 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -17,7 +17,7 @@ Usage: install.sh [--version ] [--install-dir ] [--repo ] [--skip-checksum] Environment: - MEMOS_VERSION Version to install. Accepts "0.28.1" or "v0.28.1". Defaults to latest release. + MEMOS_VERSION Version to install. Accepts "26.09" or "26.09.1". Defaults to latest release. MEMOS_INSTALL_DIR Directory to install the binary into. MEMOS_SKIP_CHECKSUM Set to 1 to skip checksum verification. MEMOS_INSTALL_QUIET Set to 1 to reduce log output. @@ -25,7 +25,7 @@ Environment: Examples: curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh - curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh -s -- --version 0.28.1 + curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh -s -- --version 26.09 EOF } @@ -254,7 +254,10 @@ main() { VERSION="$(normalize_version "$VERSION")" install_dir="$(resolve_install_dir)" - tag="v${VERSION}" + case "$VERSION" in + 0.*) tag="v${VERSION}" ;; + *) tag="$VERSION" ;; + esac asset_suffix="${arch}" if [ "$arch" = "armv7" ]; then diff --git a/scripts/install_test.go b/scripts/install_test.go new file mode 100644 index 000000000..d1571c19a --- /dev/null +++ b/scripts/install_test.go @@ -0,0 +1,79 @@ +package scripts + +import ( + "crypto/sha256" + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestInstallRelease(t *testing.T) { + for _, tc := range []struct{ input, tag string }{ + {"26.09", "26.09"}, + {"26.09.1", "26.09.1"}, + {"v26.09.1", "26.09.1"}, + {"26.09-rc.1", "26.09-rc.1"}, + {"0.31.0", "v0.31.0"}, + {"v0.31.0", "v0.31.0"}, + {"", "26.09.2"}, + {"", "v0.31.0"}, + } { + input, tag := tc.input, tc.tag + t.Run("version="+input, func(t *testing.T) { + dir := t.TempDir() + mockBin := filepath.Join(dir, "bin") + require.NoError(t, os.Mkdir(mockBin, 0755)) + version := strings.TrimPrefix(tag, "v") + writeExecutable(t, filepath.Join(dir, "memos"), "#!/bin/sh\nprintf '%s\\n' '"+version+"'\n") + archive := filepath.Join(dir, "release.tar.gz") + out, err := exec.Command("tar", "-czf", archive, "-C", dir, "memos").CombinedOutput() + require.NoError(t, err, string(out)) + data, err := os.ReadFile(archive) + require.NoError(t, err) + asset := "memos_" + version + "_linux_amd64.tar.gz" + require.NoError(t, os.WriteFile(filepath.Join(dir, "checksums.txt"), []byte(fmt.Sprintf("%x %s\n", sha256.Sum256(data), asset)), 0644)) + writeExecutable(t, filepath.Join(mockBin, "uname"), "#!/bin/sh\ncase $1 in -s) echo Linux;; -m) echo x86_64;; esac\n") + writeExecutable(t, filepath.Join(mockBin, "curl"), `#!/bin/sh +set -eu +url= dest= +while [ "$#" -gt 0 ]; do + case "$1" in + -o) dest="$2"; shift 2;; + -H) shift 2;; + -*) shift;; + *) url="$1"; shift;; + esac +done +printf '%s\n' "$url" >> "$TEST_DOWNLOAD_LOG" +case "$url" in + */releases/latest) printf '{"tag_name":"%s"}\n' "$TEST_TAG";; + */checksums.txt) cp "$TEST_FIXTURE/checksums.txt" "$dest";; + */memos_*.tar.gz) cp "$TEST_FIXTURE/release.tar.gz" "$dest";; + *) exit 1;; +esac +`) + args := []string{"install.sh", "--install-dir", filepath.Join(dir, "installed")} + if input != "" { + args = append(args, "--version", input) + } + cmd := exec.Command("sh", args...) + logPath := filepath.Join(dir, "downloads.log") + cmd.Env = append(os.Environ(), "PATH="+mockBin+string(os.PathListSeparator)+os.Getenv("PATH"), "TEST_FIXTURE="+dir, + "TEST_TAG="+tag, "TEST_DOWNLOAD_LOG="+logPath, "MEMOS_VERSION=", "MEMOS_SKIP_CHECKSUM=0", "REPO=usememos/memos") + out, err = cmd.CombinedOutput() + require.NoError(t, err, string(out)) + log, err := os.ReadFile(logPath) + require.NoError(t, err) + require.Contains(t, string(log), "https://github.com/usememos/memos/releases/download/"+tag+"/"+asset) + require.Contains(t, string(log), "/"+tag+"/checksums.txt") + out, err = exec.Command(filepath.Join(dir, "installed", "memos")).CombinedOutput() + require.NoError(t, err) + require.Equal(t, version+"\n", string(out)) + }) + } +} diff --git a/scripts/release_smoke_test.sh b/scripts/release_smoke_test.sh index 4d9e3ffec..48ef68ba8 100755 --- a/scripts/release_smoke_test.sh +++ b/scripts/release_smoke_test.sh @@ -24,7 +24,7 @@ Docker image. With no options, the current worktree is built and tested. Options: --candidate-image IMAGE Test an existing image instead of building locally. --previous-image IMAGE Image used to seed the upgrade test. By default, the - latest stable Git tag before HEAD is used. + latest supported stable Git tag before HEAD is used. --keep-resources Keep containers and volumes after the test for debugging. -h, --help Show this help text. @@ -37,7 +37,7 @@ Examples: ./scripts/release_smoke_test.sh ./scripts/release_smoke_test.sh \ --candidate-image memos-smoke:local \ - --previous-image neosmemo/memos:0.29.1 + --previous-image neosmemo/memos:0.31.0 EOF } @@ -142,25 +142,7 @@ cleanup() { trap cleanup EXIT detect_previous_image() { - local head_sha tag tag_sha - head_sha="$(git -C "$REPO_ROOT" rev-parse HEAD)" - - while IFS= read -r tag; do - case "$tag" in - *-rc.*) continue ;; - esac - - tag_sha="$(git -C "$REPO_ROOT" rev-list -n 1 "$tag")" - if [[ "$tag_sha" == "$head_sha" ]]; then - continue - fi - if git -C "$REPO_ROOT" merge-base --is-ancestor "$tag" HEAD; then - printf 'neosmemo/memos:%s\n' "${tag#v}" - return - fi - done < <(git -C "$REPO_ROOT" tag --list 'v[0-9]*' --sort=-version:refname) - - die "could not detect a previous stable release; pass --previous-image" + bash "$SCRIPT_DIR/release_version.sh" previous-image "$REPO_ROOT" } build_local_candidate() { diff --git a/scripts/release_version.sh b/scripts/release_version.sh new file mode 100755 index 000000000..d7bce75b0 --- /dev/null +++ b/scripts/release_version.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Application releases use YY.MM[.N][-rc.N]. Database migration sequences are separate. +parse_release_tag() { + local tag="$1" + if [[ ! "$tag" =~ ^([1-9][0-9]\.(0[1-9]|1[0-2]))(\.([1-9][0-9]*))?(-rc\.([1-9][0-9]*))?$ ]]; then + return 1 + fi + RELEASE_VERSION="$tag" + RELEASE_SERIES="${BASH_REMATCH[1]}" + RELEASE_IS_PRERELEASE=false + if [[ -n "${BASH_REMATCH[5]}" ]]; then + RELEASE_IS_PRERELEASE=true + fi +} + +# previous_release_tag prints the newest stable release tag that is an ancestor +# of HEAD, excluding tags on HEAD itself. Legacy v0.31.x tags count because +# v0.31.0 is the fixed upgrade baseline. +previous_release_tag() { + local repo="$1" head_sha tag tag_sha + head_sha="$(git -C "$repo" rev-parse HEAD)" + # List calendar releases first: the legacy v prefix would otherwise sort ahead. + while IFS= read -r tag; do + if parse_release_tag "$tag"; then + [[ "$RELEASE_IS_PRERELEASE" == false ]] || continue + elif [[ ! "$tag" =~ ^v0\.31\.(0|[1-9][0-9]*)$ ]]; then + continue + fi + tag_sha="$(git -C "$repo" rev-list -n 1 "$tag")" + [[ "$tag_sha" != "$head_sha" ]] || continue + if git -C "$repo" merge-base --is-ancestor "$tag" HEAD; then + printf '%s\n' "$tag" + return + fi + done < <( + git -C "$repo" tag --list '[1-9][0-9].*' --sort=-version:refname + git -C "$repo" tag --list 'v0.31.*' --sort=-version:refname + ) + echo 'No supported previous release found' >&2 + return 1 +} + +previous_release_image() { + local tag + if ! tag="$(previous_release_tag "$1")"; then + echo 'Pass --previous-image' >&2 + return 1 + fi + printf 'neosmemo/memos:%s\n' "${tag#v}" +} + +if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then + case "${1:-}" in + previous-tag) + previous_release_tag "${2:?repository required}" + exit + ;; + previous-image) + previous_release_image "${2:?repository required}" + exit + ;; + esac + tag="${2:?release tag required}" + if ! parse_release_tag "$tag"; then + echo "Unsupported release tag format: $tag" >&2 + exit 1 + fi + case "${1:-}" in + version) + printf 'tag=%s\nversion=%s\nseries=%s\nis_prerelease=%s\n' \ + "$tag" "$RELEASE_VERSION" "$RELEASE_SERIES" "$RELEASE_IS_PRERELEASE" + ;; + image-tags) + printf '%s\n' "$RELEASE_VERSION" + if [[ "$RELEASE_IS_PRERELEASE" == false ]]; then + if [[ "$RELEASE_SERIES" != "$RELEASE_VERSION" ]]; then + printf '%s\n' "$RELEASE_SERIES" + fi + printf 'stable\n' + fi + ;; + *) echo "Unknown release command: ${1:-}" >&2; exit 1 ;; + esac +fi diff --git a/scripts/release_version_test.go b/scripts/release_version_test.go new file mode 100644 index 000000000..cbb2a56a8 --- /dev/null +++ b/scripts/release_version_test.go @@ -0,0 +1,95 @@ +package scripts + +import ( + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestReleaseVersions(t *testing.T) { + for _, tc := range []struct { + tag, series, prerelease, images string + }{ + {"26.09", "26.09", "false", "26.09\nstable\n"}, + {"26.09.1", "26.09", "false", "26.09.1\n26.09\nstable\n"}, + {"26.09.10", "26.09", "false", "26.09.10\n26.09\nstable\n"}, + {"26.10.1", "26.10", "false", "26.10.1\n26.10\nstable\n"}, + {"27.01", "27.01", "false", "27.01\nstable\n"}, + {"26.09-rc.1", "26.09", "true", "26.09-rc.1\n"}, + {"26.09.1-rc.2", "26.09", "true", "26.09.1-rc.2\n"}, + } { + t.Run(tc.tag, func(t *testing.T) { + out, err := exec.Command("bash", "release_version.sh", "version", tc.tag).CombinedOutput() + require.NoError(t, err, string(out)) + require.Equal(t, "tag="+tc.tag+"\nversion="+tc.tag+"\nseries="+tc.series+"\nis_prerelease="+tc.prerelease+"\n", string(out)) + out, err = exec.Command("bash", "release_version.sh", "image-tags", tc.tag).CombinedOutput() + require.NoError(t, err, string(out)) + require.Equal(t, tc.images, string(out)) + }) + } + for _, tag := range []string{"v0.31.0", "v26.09", "v26.09.1", "v26.09-rc.1", "26.9", "26.00", "26.13", "2026.09", "26.09.0", "26.09.01", "26.09-rc.0", "26.09-rc.01", "26.09beta", "26.09.1+build"} { + out, err := exec.Command("bash", "release_version.sh", "version", tag).CombinedOutput() + require.Error(t, err, tag) + require.Contains(t, string(out), "Unsupported release tag") + } +} + +func TestPreviousReleaseImage(t *testing.T) { + repo := t.TempDir() + runGit := func(args ...string) { + t.Helper() + cmd := exec.Command("git", append([]string{"-C", repo, "-c", "user.name=Release Test", "-c", "user.email=test@example.com", "-c", "commit.gpgsign=false"}, args...)...) + out, err := cmd.CombinedOutput() + require.NoError(t, err, string(out)) + } + check := func(want string) { + t.Helper() + out, err := exec.Command("bash", "release_version.sh", "previous-tag", repo).CombinedOutput() + require.NoError(t, err, string(out)) + require.Equal(t, want+"\n", string(out)) + out, err = exec.Command("bash", "release_version.sh", "previous-image", repo).CombinedOutput() + require.NoError(t, err, string(out)) + require.Equal(t, "neosmemo/memos:"+strings.TrimPrefix(want, "v")+"\n", string(out)) + } + runGit("init", "-b", "main") + runGit("commit", "--allow-empty", "-m", "old") + runGit("tag", "v0.30.0") + runGit("commit", "--allow-empty", "-m", "baseline") + runGit("tag", "v0.31.0") + runGit("commit", "--allow-empty", "-m", "first calendar release") + runGit("tag", "26.09") + check("v0.31.0") + runGit("commit", "--allow-empty", "-m", "point release") + runGit("tag", "26.09.2") + check("26.09") + runGit("commit", "--allow-empty", "-m", "tenth point release") + runGit("tag", "26.09.10") + runGit("tag", "99.99") + runGit("commit", "--allow-empty", "-m", "release candidate") + runGit("tag", "26.10-rc.1") + check("26.09.10") + runGit("commit", "--allow-empty", "-m", "after release candidate") + check("26.09.10") + runGit("checkout", "--orphan", "unrelated") + runGit("commit", "--allow-empty", "-m", "unrelated release") + runGit("tag", "29.01") + runGit("checkout", "main") + check("26.09.10") + runGit("tag", "26.10") + runGit("commit", "--allow-empty", "-m", "next year") + runGit("tag", "27.01") + check("26.10") + // The floor excludes pre-baseline tags even if no supported release exists. + repo = t.TempDir() + runGit("init", "-b", "main") + runGit("commit", "--allow-empty", "-m", "old") + runGit("tag", "v0.30.0") + runGit("commit", "--allow-empty", "-m", "candidate") + for _, command := range []string{"previous-tag", "previous-image"} { + out, err := exec.Command("bash", "release_version.sh", command, repo).CombinedOutput() + require.Error(t, err, command) + require.Contains(t, string(out), "No supported previous release found") + } +} diff --git a/store/migration/README.md b/store/migration/README.md new file mode 100644 index 000000000..71e6a4ba7 --- /dev/null +++ b/store/migration/README.md @@ -0,0 +1,29 @@ +# Database migration baseline + +The minimum supported database schema is **0.31.8**, shipped in **v0.31.0**. +This is a fixed baseline, independent of application release numbering. + +- Fresh installations use the driver's `LATEST.sql` and record the current schema version. +- Existing databases below the baseline must first run + [v0.31.0](https://github.com/usememos/memos/releases/tag/v0.31.0) successfully. +- Databases older than v0.22, or with no schema version recorded, must first run + [v0.25.3](https://github.com/usememos/memos/releases/tag/v0.25.3), then v0.31.0. +- Invalid schema versions and databases newer than the binary supports are rejected. + +Historical SemVer migration scripts are retained in Git history and released +binaries. They are no longer embedded in the current binary. Keep each driver's +`LATEST.sql` for fresh installations and add incremental migrations for future +schema changes across SQLite, MySQL, and PostgreSQL. Do not advance the baseline +when adding migrations; databases at 0.31.8 must remain upgradeable. + +New migrations use `YY.MM/NN__description.sql`, where `NN` starts at `00`. +Each schema change ships one file per driver under the same `YY.MM/NN`; a +driver only records versions whose SQL it executed, and the store tests fail +when drivers disagree. Two files with the same `NN` in one month are rejected. +For example, `26.09/00__add_column.sql` records schema `26.9.1`; the next +migration records `26.9.2`. Compare year, month, and sequence numerically. +The sequence is independent of the application's release revision: a release +without schema changes keeps the existing schema version. Calendar schemas +sort after the legacy 0.x baseline. Migration directories keep months zero-padded +(`01` through `12`), while stored schema markers omit the padding. This lets older binaries' SemVer comparisons +recognize a calendar schema as newer and reject a downgrade. diff --git a/store/migration/mysql/0.17/00__inbox.sql b/store/migration/mysql/0.17/00__inbox.sql deleted file mode 100644 index 57635f46a..000000000 --- a/store/migration/mysql/0.17/00__inbox.sql +++ /dev/null @@ -1,9 +0,0 @@ --- inbox -CREATE TABLE `inbox` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `created_ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `sender_id` INT NOT NULL, - `receiver_id` INT NOT NULL, - `status` TEXT NOT NULL, - `message` TEXT NOT NULL -); diff --git a/store/migration/mysql/0.17/01__delete_activity.sql b/store/migration/mysql/0.17/01__delete_activity.sql deleted file mode 100644 index 9ea4e0f12..000000000 --- a/store/migration/mysql/0.17/01__delete_activity.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE FROM `activity`; diff --git a/store/migration/mysql/0.18/00__extend_text.sql b/store/migration/mysql/0.18/00__extend_text.sql deleted file mode 100644 index 21f3bcbdb..000000000 --- a/store/migration/mysql/0.18/00__extend_text.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `system_setting` MODIFY `value` LONGTEXT NOT NULL; -ALTER TABLE `user_setting` MODIFY `value` LONGTEXT NOT NULL; -ALTER TABLE `user` MODIFY `avatar_url` LONGTEXT NOT NULL; diff --git a/store/migration/mysql/0.18/01__webhook.sql b/store/migration/mysql/0.18/01__webhook.sql deleted file mode 100644 index 937f333e0..000000000 --- a/store/migration/mysql/0.18/01__webhook.sql +++ /dev/null @@ -1,10 +0,0 @@ --- webhook -CREATE TABLE `webhook` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `created_ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `row_status` VARCHAR(256) NOT NULL DEFAULT 'NORMAL', - `creator_id` INT NOT NULL, - `name` TEXT NOT NULL, - `url` TEXT NOT NULL -); diff --git a/store/migration/mysql/0.18/02__user_setting.sql b/store/migration/mysql/0.18/02__user_setting.sql deleted file mode 100644 index 99709e43e..000000000 --- a/store/migration/mysql/0.18/02__user_setting.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE `user_setting` SET `key` = 'USER_SETTING_LOCALE', `value` = REPLACE(`value`, '"', '') WHERE `key` = 'locale'; -UPDATE `user_setting` SET `key` = 'USER_SETTING_APPEARANCE', `value` = REPLACE(`value`, '"', '') WHERE `key` = 'appearance'; -UPDATE `user_setting` SET `key` = 'USER_SETTING_MEMO_VISIBILITY', `value` = REPLACE(`value`, '"', '') WHERE `key` = 'memo-visibility'; -UPDATE `user_setting` SET `key` = 'USER_SETTING_TELEGRAM_USER_ID', `value` = REPLACE(`value`, '"', '') WHERE `key` = 'telegram-user-id'; diff --git a/store/migration/mysql/0.19/00__add_resource_name.sql b/store/migration/mysql/0.19/00__add_resource_name.sql deleted file mode 100644 index 462569143..000000000 --- a/store/migration/mysql/0.19/00__add_resource_name.sql +++ /dev/null @@ -1,15 +0,0 @@ -ALTER TABLE `memo` ADD COLUMN `resource_name` VARCHAR(256) AFTER `id`; - -UPDATE `memo` SET `resource_name` = uuid(); - -ALTER TABLE `memo` MODIFY COLUMN `resource_name` VARCHAR(256) NOT NULL; - -CREATE UNIQUE INDEX idx_memo_resource_name ON `memo` (`resource_name`); - -ALTER TABLE `resource` ADD COLUMN `resource_name` VARCHAR(256) AFTER `id`; - -UPDATE `resource` SET `resource_name` = uuid(); - -ALTER TABLE `resource` MODIFY COLUMN `resource_name` VARCHAR(256) NOT NULL; - -CREATE UNIQUE INDEX idx_resource_resource_name ON `resource` (`resource_name`); diff --git a/store/migration/mysql/0.20/00__reaction.sql b/store/migration/mysql/0.20/00__reaction.sql deleted file mode 100644 index a25a1bafd..000000000 --- a/store/migration/mysql/0.20/00__reaction.sql +++ /dev/null @@ -1,9 +0,0 @@ --- reaction -CREATE TABLE `reaction` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `created_ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `creator_id` INT NOT NULL, - `content_id` VARCHAR(256) NOT NULL, - `reaction_type` VARCHAR(256) NOT NULL, - UNIQUE(`creator_id`,`content_id`,`reaction_type`) -); diff --git a/store/migration/mysql/0.21/00__user_description.sql b/store/migration/mysql/0.21/00__user_description.sql deleted file mode 100644 index 44df86873..000000000 --- a/store/migration/mysql/0.21/00__user_description.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `user` ADD COLUMN `description` VARCHAR(256) NOT NULL DEFAULT ''; diff --git a/store/migration/mysql/0.21/01__rename_uid.sql b/store/migration/mysql/0.21/01__rename_uid.sql deleted file mode 100644 index 78ab079d3..000000000 --- a/store/migration/mysql/0.21/01__rename_uid.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `memo` RENAME COLUMN `resource_name` TO `uid`; - -ALTER TABLE `resource` RENAME COLUMN `resource_name` TO `uid`; diff --git a/store/migration/mysql/0.22/00__resource_storage_type.sql b/store/migration/mysql/0.22/00__resource_storage_type.sql deleted file mode 100644 index f598d81c2..000000000 --- a/store/migration/mysql/0.22/00__resource_storage_type.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE `resource` ADD COLUMN `storage_type` VARCHAR(256) NOT NULL DEFAULT ''; -ALTER TABLE `resource` ADD COLUMN `reference` VARCHAR(256) NOT NULL DEFAULT ''; -ALTER TABLE `resource` ADD COLUMN `payload` TEXT NOT NULL; - -UPDATE `resource` SET `payload` = '{}'; - -UPDATE `resource` SET `storage_type` = 'LOCAL', `reference` = `internal_path` WHERE `internal_path` IS NOT NULL AND `internal_path` != ''; -UPDATE `resource` SET `storage_type` = 'EXTERNAL', `reference` = `external_link` WHERE `external_link` IS NOT NULL AND `external_link` != ''; - -ALTER TABLE `resource` DROP COLUMN `internal_path`; -ALTER TABLE `resource` DROP COLUMN `external_link`; diff --git a/store/migration/mysql/0.22/01__memo_tags.sql b/store/migration/mysql/0.22/01__memo_tags.sql deleted file mode 100644 index 6812f76de..000000000 --- a/store/migration/mysql/0.22/01__memo_tags.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `memo` ADD COLUMN `tags_temp` JSON; -UPDATE `memo` SET `tags_temp` = '[]'; -ALTER TABLE `memo` CHANGE COLUMN `tags_temp` `tags` JSON NOT NULL; diff --git a/store/migration/mysql/0.22/02__memo_payload.sql b/store/migration/mysql/0.22/02__memo_payload.sql deleted file mode 100644 index 24e7b84ca..000000000 --- a/store/migration/mysql/0.22/02__memo_payload.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `memo` ADD COLUMN `payload_temp` JSON; -UPDATE `memo` SET `payload_temp` = '{}'; -ALTER TABLE `memo` CHANGE COLUMN `payload_temp` `payload` JSON NOT NULL; diff --git a/store/migration/mysql/0.22/03__drop_tag.sql b/store/migration/mysql/0.22/03__drop_tag.sql deleted file mode 100644 index ba302faa4..000000000 --- a/store/migration/mysql/0.22/03__drop_tag.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS `tag`; diff --git a/store/migration/mysql/0.23/00__reactions.sql b/store/migration/mysql/0.23/00__reactions.sql deleted file mode 100644 index 13979d15c..000000000 --- a/store/migration/mysql/0.23/00__reactions.sql +++ /dev/null @@ -1,12 +0,0 @@ -UPDATE `reaction` SET `reaction_type` = '👍' WHERE `reaction_type` = 'THUMBS_UP'; -UPDATE `reaction` SET `reaction_type` = '👎' WHERE `reaction_type` = 'THUMBS_DOWN'; -UPDATE `reaction` SET `reaction_type` = '💛' WHERE `reaction_type` = 'HEART'; -UPDATE `reaction` SET `reaction_type` = '🔥' WHERE `reaction_type` = 'FIRE'; -UPDATE `reaction` SET `reaction_type` = '👏' WHERE `reaction_type` = 'CLAPPING_HANDS'; -UPDATE `reaction` SET `reaction_type` = '😂' WHERE `reaction_type` = 'LAUGH'; -UPDATE `reaction` SET `reaction_type` = '👌' WHERE `reaction_type` = 'OK_HAND'; -UPDATE `reaction` SET `reaction_type` = '🚀' WHERE `reaction_type` = 'ROCKET'; -UPDATE `reaction` SET `reaction_type` = '👀' WHERE `reaction_type` = 'EYES'; -UPDATE `reaction` SET `reaction_type` = '🤔' WHERE `reaction_type` = 'THINKING_FACE'; -UPDATE `reaction` SET `reaction_type` = '🤡' WHERE `reaction_type` = 'CLOWN_FACE'; -UPDATE `reaction` SET `reaction_type` = '❓' WHERE `reaction_type` = 'QUESTION_MARK'; diff --git a/store/migration/mysql/0.24/00__memo.sql b/store/migration/mysql/0.24/00__memo.sql deleted file mode 100644 index 64ee71f01..000000000 --- a/store/migration/mysql/0.24/00__memo.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Drop deprecated tags column. -ALTER TABLE `memo` DROP COLUMN `tags`; \ No newline at end of file diff --git a/store/migration/mysql/0.24/01__memo_pinned.sql b/store/migration/mysql/0.24/01__memo_pinned.sql deleted file mode 100644 index ee4c0fc78..000000000 --- a/store/migration/mysql/0.24/01__memo_pinned.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Add pinned column. -ALTER TABLE `memo` ADD COLUMN `pinned` BOOLEAN NOT NULL DEFAULT FALSE; - --- Update pinned column from memo_organizer. -UPDATE memo -JOIN memo_organizer ON memo.id = memo_organizer.memo_id -SET memo.pinned = TRUE -WHERE memo_organizer.pinned = 1; diff --git a/store/migration/mysql/0.24/02__s3_reference_length.sql b/store/migration/mysql/0.24/02__s3_reference_length.sql deleted file mode 100644 index f7da77e4a..000000000 --- a/store/migration/mysql/0.24/02__s3_reference_length.sql +++ /dev/null @@ -1,2 +0,0 @@ --- https://github.com/usememos/memos/issues/4322 -ALTER TABLE `resource` MODIFY `reference` TEXT NOT NULL DEFAULT (''); diff --git a/store/migration/mysql/0.25/00__remove_webhook.sql b/store/migration/mysql/0.25/00__remove_webhook.sql deleted file mode 100644 index f60efc073..000000000 --- a/store/migration/mysql/0.25/00__remove_webhook.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS webhook; diff --git a/store/migration/mysql/0.26/00__rename_resource_to_attachment.sql b/store/migration/mysql/0.26/00__rename_resource_to_attachment.sql deleted file mode 100644 index 703234fe3..000000000 --- a/store/migration/mysql/0.26/00__rename_resource_to_attachment.sql +++ /dev/null @@ -1 +0,0 @@ -RENAME TABLE resource TO attachment; diff --git a/store/migration/mysql/0.26/01__drop_memo_organizer.sql b/store/migration/mysql/0.26/01__drop_memo_organizer.sql deleted file mode 100644 index 17c3579f2..000000000 --- a/store/migration/mysql/0.26/01__drop_memo_organizer.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS memo_organizer; diff --git a/store/migration/mysql/0.26/02__migrate_host_to_admin.sql b/store/migration/mysql/0.26/02__migrate_host_to_admin.sql deleted file mode 100644 index 24ec82ac9..000000000 --- a/store/migration/mysql/0.26/02__migrate_host_to_admin.sql +++ /dev/null @@ -1 +0,0 @@ -UPDATE `user` SET `role` = 'ADMIN' WHERE `role` = 'HOST'; diff --git a/store/migration/mysql/0.27/00__migrate_storage_setting.sql b/store/migration/mysql/0.27/00__migrate_storage_setting.sql deleted file mode 100644 index 9a8187713..000000000 --- a/store/migration/mysql/0.27/00__migrate_storage_setting.sql +++ /dev/null @@ -1,6 +0,0 @@ --- Set storage type to DATABASE for existing instances that have no storage setting configured. --- This preserves backward-compatible behavior before the default was changed to LOCAL. -INSERT INTO system_setting (name, value, description) -SELECT 'STORAGE', '{"storageType":"DATABASE"}', '' -FROM DUAL -WHERE NOT EXISTS (SELECT 1 FROM system_setting WHERE name = 'STORAGE'); diff --git a/store/migration/mysql/0.27/01__add_idp_uid.sql b/store/migration/mysql/0.27/01__add_idp_uid.sql deleted file mode 100644 index a3e824731..000000000 --- a/store/migration/mysql/0.27/01__add_idp_uid.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Add uid column to idp table -ALTER TABLE `idp` ADD COLUMN `uid` VARCHAR(256) NOT NULL DEFAULT ''; - --- Populate uid for existing rows using hex of id as a fallback -UPDATE `idp` SET `uid` = LOWER(LPAD(HEX(`id`), 8, '0')) WHERE `uid` = ''; - --- Create unique index on uid -ALTER TABLE `idp` ADD UNIQUE INDEX `idx_idp_uid` (`uid`); diff --git a/store/migration/mysql/0.27/02__migrate_inbox_message_payload.sql b/store/migration/mysql/0.27/02__migrate_inbox_message_payload.sql deleted file mode 100644 index 8800176b6..000000000 --- a/store/migration/mysql/0.27/02__migrate_inbox_message_payload.sql +++ /dev/null @@ -1,14 +0,0 @@ -UPDATE `inbox` AS i -JOIN `activity` AS a - ON a.`id` = CAST(JSON_UNQUOTE(JSON_EXTRACT(i.`message`, '$.activityId')) AS UNSIGNED) -SET i.`message` = JSON_SET( - JSON_REMOVE(i.`message`, '$.activityId'), - '$.memoComment', - JSON_OBJECT( - 'memoId', - JSON_EXTRACT(a.`payload`, '$.memoComment.memoId'), - 'relatedMemoId', - JSON_EXTRACT(a.`payload`, '$.memoComment.relatedMemoId') - ) -) -WHERE JSON_EXTRACT(i.`message`, '$.activityId') IS NOT NULL; diff --git a/store/migration/mysql/0.27/03__drop_activity.sql b/store/migration/mysql/0.27/03__drop_activity.sql deleted file mode 100644 index bfda5a812..000000000 --- a/store/migration/mysql/0.27/03__drop_activity.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE `activity`; diff --git a/store/migration/mysql/0.27/04__memo_share.sql b/store/migration/mysql/0.27/04__memo_share.sql deleted file mode 100644 index d532b8e1a..000000000 --- a/store/migration/mysql/0.27/04__memo_share.sql +++ /dev/null @@ -1,14 +0,0 @@ --- memo_share stores per-memo share grants (one row per share link). --- uid is the opaque bearer token included in the share URL. --- ON DELETE CASCADE ensures grants are cleaned up when the parent memo is deleted. -CREATE TABLE memo_share ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - uid VARCHAR(255) NOT NULL UNIQUE, - memo_id INT NOT NULL, - creator_id INT NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (UNIX_TIMESTAMP()), - expires_ts BIGINT DEFAULT NULL, - FOREIGN KEY (memo_id) REFERENCES memo(id) ON DELETE CASCADE -); - -CREATE INDEX idx_memo_share_memo_id ON memo_share(memo_id); diff --git a/store/migration/mysql/0.28/00__user_identity.sql b/store/migration/mysql/0.28/00__user_identity.sql deleted file mode 100644 index 8479dd2af..000000000 --- a/store/migration/mysql/0.28/00__user_identity.sql +++ /dev/null @@ -1,15 +0,0 @@ --- user_identity stores the linkage between an external identity subject and a local user. --- (provider, extern_uid) is unique across the table; provider stores the idp.uid. --- Each local user can link at most one external account per provider. -CREATE TABLE `user_identity` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `user_id` INT NOT NULL, - `provider` VARCHAR(256) NOT NULL, - `extern_uid` VARCHAR(256) NOT NULL, - `created_ts` BIGINT NOT NULL DEFAULT (UNIX_TIMESTAMP()), - `updated_ts` BIGINT NOT NULL DEFAULT (UNIX_TIMESTAMP()), - UNIQUE (`provider`, `extern_uid`), - UNIQUE (`user_id`, `provider`) -); - -CREATE INDEX `idx_user_identity_user_id` ON `user_identity`(`user_id`); diff --git a/store/migration/mysql/0.30/00__user_tag_setting.sql b/store/migration/mysql/0.30/00__user_tag_setting.sql deleted file mode 100644 index 8d1553e92..000000000 --- a/store/migration/mysql/0.30/00__user_tag_setting.sql +++ /dev/null @@ -1,10 +0,0 @@ -INSERT IGNORE INTO `user_setting` (`user_id`, `key`, `value`) -SELECT - `user`.`id`, - 'TAGS', - `system_setting`.`value` -FROM `user` -JOIN `system_setting` ON `system_setting`.`name` = 'TAGS' -WHERE `system_setting`.`value` IS NOT NULL - AND `system_setting`.`value` != '' - AND `system_setting`.`value` != '{}'; diff --git a/store/migration/mysql/0.31/00__rename_shortcuts_to_memo_views.sql b/store/migration/mysql/0.31/00__rename_shortcuts_to_memo_views.sql deleted file mode 100644 index 936e5251b..000000000 --- a/store/migration/mysql/0.31/00__rename_shortcuts_to_memo_views.sql +++ /dev/null @@ -1,29 +0,0 @@ --- Renames the SHORTCUTS user setting to MEMO_VIEWS, rewriting the stored JSON --- object key from `shortcuts` to `memoViews` to match the renamed proto field. --- --- Rows are skipped rather than failing the migration when either --- * `value` is not valid JSON, which would abort the whole upgrade transaction, or --- * the user already has a MEMO_VIEWS row, which would violate UNIQUE(user_id, key). --- The conflict check goes through a derived table because MySQL cannot read the --- target table of an UPDATE directly in a subquery. -UPDATE user_setting -SET - `key` = 'MEMO_VIEWS', - value = CASE - WHEN JSON_CONTAINS_PATH(value, 'one', '$.shortcuts') THEN JSON_SET( - JSON_REMOVE(value, '$.shortcuts'), - '$.memoViews', - JSON_EXTRACT(value, '$.shortcuts') - ) - ELSE value - END -WHERE `key` = 'SHORTCUTS' - AND CASE - WHEN JSON_VALID(value) THEN JSON_TYPE(value) = 'OBJECT' - ELSE FALSE - END - AND user_id NOT IN ( - SELECT user_id FROM ( - SELECT user_id FROM user_setting WHERE `key` = 'MEMO_VIEWS' - ) AS existing_memo_views - ); diff --git a/store/migration/mysql/0.31/01__migrate_storage_setting.sql b/store/migration/mysql/0.31/01__migrate_storage_setting.sql deleted file mode 100644 index 7e76b0683..000000000 --- a/store/migration/mysql/0.31/01__migrate_storage_setting.sql +++ /dev/null @@ -1,88 +0,0 @@ --- Expands the legacy singleton storage setting into the named storage model. --- Legacy fields remain in place so older clients and rollback versions can --- continue to read the active storage configuration. -UPDATE system_setting -SET value = JSON_SET( - value, - '$.storages', JSON_ARRAY(JSON_OBJECT( - 'id', 'database', - 'name', 'Database', - 'type', 'STORAGE_TYPE_DATABASE' - )), - '$.defaultStorageId', 'database' -) -WHERE name = 'STORAGE' - AND CASE - WHEN JSON_VALID(value) THEN - JSON_TYPE(value) = 'OBJECT' - AND NOT JSON_CONTAINS_PATH(value, 'one', '$.storages') - AND JSON_UNQUOTE(JSON_EXTRACT(value, '$.storageType')) IN ('DATABASE', '1') - ELSE FALSE - END; - -UPDATE system_setting -SET value = JSON_SET( - value, - '$.storages', JSON_ARRAY(JSON_OBJECT( - 'id', 'local', - 'name', 'Local', - 'type', 'STORAGE_TYPE_LOCAL' - )), - '$.defaultStorageId', 'local' -) -WHERE name = 'STORAGE' - AND CASE - WHEN JSON_VALID(value) THEN - JSON_TYPE(value) = 'OBJECT' - AND NOT JSON_CONTAINS_PATH(value, 'one', '$.storages') - AND ( - NOT JSON_CONTAINS_PATH(value, 'one', '$.storageType') - OR JSON_UNQUOTE(JSON_EXTRACT(value, '$.storageType')) IN ('STORAGE_TYPE_UNSPECIFIED', 'LOCAL', '0', '2') - ) - ELSE FALSE - END; - -UPDATE system_setting -SET value = JSON_SET( - value, - '$.storages', JSON_ARRAY(JSON_OBJECT( - 'id', 's3', - 'name', 'S3', - 'type', 'STORAGE_TYPE_S3', - 's3Config', JSON_EXTRACT(value, '$.s3Config') - )), - '$.defaultStorageId', 's3' -) -WHERE name = 'STORAGE' - AND CASE - WHEN JSON_VALID(value) THEN - JSON_TYPE(value) = 'OBJECT' - AND NOT JSON_CONTAINS_PATH(value, 'one', '$.storages') - AND JSON_UNQUOTE(JSON_EXTRACT(value, '$.storageType')) IN ('S3', '3') - AND JSON_TYPE(JSON_EXTRACT(value, '$.s3Config')) = 'OBJECT' - ELSE FALSE - END; - --- Attachments created before S3 configs were embedded only stored the object --- key. Bind them to the namespace captured above before that default changes. -UPDATE attachment -SET payload = JSON_SET(payload, '$.s3Object.storageId', 's3') -WHERE storage_type = 'S3' - AND CASE - WHEN JSON_VALID(payload) THEN - JSON_TYPE(payload) = 'OBJECT' - AND JSON_TYPE(JSON_EXTRACT(payload, '$.s3Object')) = 'OBJECT' - AND NOT JSON_CONTAINS_PATH(payload, 'one', '$.s3Object.storageId') - AND NOT JSON_CONTAINS_PATH(payload, 'one', '$.s3Object.s3Config') - ELSE FALSE - END - AND EXISTS ( - SELECT 1 - FROM system_setting AS storage_setting - WHERE storage_setting.name = 'STORAGE' - AND CASE - WHEN JSON_VALID(storage_setting.value) THEN - JSON_UNQUOTE(JSON_EXTRACT(storage_setting.value, '$.defaultStorageId')) = 's3' - ELSE FALSE - END - ); diff --git a/store/migration/mysql/0.31/02__reaction_memo_id.sql b/store/migration/mysql/0.31/02__reaction_memo_id.sql deleted file mode 100644 index 95a774f69..000000000 --- a/store/migration/mysql/0.31/02__reaction_memo_id.sql +++ /dev/null @@ -1,18 +0,0 @@ --- Replaces the memo resource name stored in reaction.content_id with the --- memo's stable internal ID. Rows that cannot be resolved are intentionally --- deleted before memo_id is made non-nullable. Altering the table in place --- preserves its AUTO_INCREMENT high-water mark. -ALTER TABLE `reaction` - ADD COLUMN `memo_id` INT DEFAULT NULL AFTER `creator_id`; - -UPDATE `reaction` -JOIN `memo` ON `reaction`.`content_id` = CONCAT('memos/', `memo`.`uid`) -SET `reaction`.`memo_id` = `memo`.`id`; - -DELETE FROM `reaction` WHERE `memo_id` IS NULL; - -ALTER TABLE `reaction` - DROP INDEX `creator_id`, - DROP COLUMN `content_id`, - MODIFY COLUMN `memo_id` INT NOT NULL, - ADD UNIQUE (`creator_id`, `memo_id`, `reaction_type`); diff --git a/store/migration/mysql/0.31/03__multi_spaces.sql b/store/migration/mysql/0.31/03__multi_spaces.sql deleted file mode 100644 index 477f98f72..000000000 --- a/store/migration/mysql/0.31/03__multi_spaces.sql +++ /dev/null @@ -1,20 +0,0 @@ -CREATE TABLE `space` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `uid` VARCHAR(256) NOT NULL UNIQUE, - `title` TEXT NOT NULL, - `description` TEXT NOT NULL -); - -CREATE TABLE `space_member` ( - `space_id` INT NOT NULL, - `user_id` INT NOT NULL, - `role` VARCHAR(256) NOT NULL CHECK (`role` IN ('ADMIN', 'USER')), - PRIMARY KEY (`space_id`, `user_id`) -); - -ALTER TABLE `memo` ADD COLUMN `space_id` INT DEFAULT NULL; - -CREATE INDEX `idx_space_member_user_id` ON `space_member`(`user_id`, `space_id`); -CREATE INDEX `idx_memo_space_id` ON `memo`(`space_id`, `row_status`, `created_ts`, `id`); -CREATE INDEX `idx_memo_relation_related_type_memo` - ON `memo_relation`(`related_memo_id`, `type`, `memo_id`); diff --git a/store/migration/mysql/0.31/04__space_member_status.sql b/store/migration/mysql/0.31/04__space_member_status.sql deleted file mode 100644 index 25df40601..000000000 --- a/store/migration/mysql/0.31/04__space_member_status.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE `space_member` - ADD COLUMN `status` VARCHAR(256) NULL AFTER `user_id`; - -UPDATE `space_member` -SET `status` = 'ACTIVE'; - -ALTER TABLE `space_member` - MODIFY COLUMN `status` VARCHAR(256) NOT NULL; diff --git a/store/migration/mysql/0.31/05__case_sensitive_username.sql b/store/migration/mysql/0.31/05__case_sensitive_username.sql deleted file mode 100644 index 51115d94a..000000000 --- a/store/migration/mysql/0.31/05__case_sensitive_username.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `user` - MODIFY `username` VARCHAR(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL; diff --git a/store/migration/mysql/0.31/06__space_payload.sql b/store/migration/mysql/0.31/06__space_payload.sql deleted file mode 100644 index 3241d0686..000000000 --- a/store/migration/mysql/0.31/06__space_payload.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE space ADD COLUMN payload JSON; -UPDATE space SET payload = '{}'; -ALTER TABLE space MODIFY COLUMN payload JSON NOT NULL; diff --git a/store/migration/mysql/0.31/07__unique_email.sql b/store/migration/mysql/0.31/07__unique_email.sql deleted file mode 100644 index eafd047f4..000000000 --- a/store/migration/mysql/0.31/07__unique_email.sql +++ /dev/null @@ -1,42 +0,0 @@ --- Make user.email an optional, canonical, instance-unique attribute. --- The column is switched to a binary collation before the data repair so --- that grouping compares bytes rather than whatever the server default --- collation considers equal. -ALTER TABLE `user` - MODIFY `email` VARCHAR(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL; - --- Canonical form: trimmed and lowercased. -UPDATE `user` SET `email` = LOWER(TRIM(`email`)); - --- Empty values, values without an '@', and values carrying display-name --- syntax or interior whitespace mean no address. -UPDATE `user` SET `email` = NULL -WHERE `email` = '' OR `email` NOT LIKE '%@%' OR `email` LIKE '%<%' OR `email` LIKE '%>%' OR `email` LIKE '% %'; - --- For each address held by more than one account, the oldest account keeps it. --- MySQL cannot read the table being updated in a subquery, so the survivors --- are materialized through a derived table. -UPDATE `user` -SET `email` = NULL -WHERE `email` IS NOT NULL - AND `id` NOT IN ( - SELECT `id` FROM ( - SELECT MIN(`id`) AS `id` FROM `user` WHERE `email` IS NOT NULL GROUP BY `email` - ) AS `keep` - ); - --- MySQL has no CREATE INDEX IF NOT EXISTS; guard through a prepared statement --- so that re-running this file against a database that already carries the --- index (a fresh install whose schema version was rewound) is a no-op. -SET @idx_user_email_exists = ( - SELECT COUNT(*) FROM information_schema.statistics - WHERE table_schema = DATABASE() AND table_name = 'user' AND index_name = 'idx_user_email' -); -SET @idx_user_email_stmt = IF( - @idx_user_email_exists = 0, - 'CREATE UNIQUE INDEX `idx_user_email` ON `user` (`email`)', - 'SELECT 1' -); -PREPARE idx_user_email_prepared FROM @idx_user_email_stmt; -EXECUTE idx_user_email_prepared; -DEALLOCATE PREPARE idx_user_email_prepared; diff --git a/store/migration/postgres/0.19/00__add_resource_name.sql b/store/migration/postgres/0.19/00__add_resource_name.sql deleted file mode 100644 index aa5b560f0..000000000 --- a/store/migration/postgres/0.19/00__add_resource_name.sql +++ /dev/null @@ -1,15 +0,0 @@ -ALTER TABLE memo ADD COLUMN resource_name TEXT; - -UPDATE memo SET resource_name = uuid_in(md5(random()::text || random()::text)::cstring); - -ALTER TABLE memo ALTER COLUMN resource_name SET NOT NULL; - -CREATE UNIQUE INDEX idx_memo_resource_name ON memo (resource_name); - -ALTER TABLE resource ADD COLUMN resource_name TEXT; - -UPDATE resource SET resource_name = uuid_in(md5(random()::text || random()::text)::cstring); - -ALTER TABLE resource ALTER COLUMN resource_name SET NOT NULL; - -CREATE UNIQUE INDEX idx_resource_resource_name ON resource (resource_name); diff --git a/store/migration/postgres/0.20/00__reaction.sql b/store/migration/postgres/0.20/00__reaction.sql deleted file mode 100644 index f9866ee94..000000000 --- a/store/migration/postgres/0.20/00__reaction.sql +++ /dev/null @@ -1,9 +0,0 @@ --- reaction -CREATE TABLE reaction ( - id SERIAL PRIMARY KEY, - created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - creator_id INTEGER NOT NULL, - content_id TEXT NOT NULL, - reaction_type TEXT NOT NULL, - UNIQUE(creator_id, content_id, reaction_type) -); diff --git a/store/migration/postgres/0.21/00__user_description.sql b/store/migration/postgres/0.21/00__user_description.sql deleted file mode 100644 index b8f1aeaf3..000000000 --- a/store/migration/postgres/0.21/00__user_description.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "user" ADD COLUMN description TEXT NOT NULL DEFAULT ''; diff --git a/store/migration/postgres/0.21/01__rename_uid.sql b/store/migration/postgres/0.21/01__rename_uid.sql deleted file mode 100644 index 12a040225..000000000 --- a/store/migration/postgres/0.21/01__rename_uid.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE memo RENAME COLUMN resource_name TO uid; - -ALTER TABLE resource RENAME COLUMN resource_name TO uid; diff --git a/store/migration/postgres/0.22/00__resource_storage_type.sql b/store/migration/postgres/0.22/00__resource_storage_type.sql deleted file mode 100644 index 00cd9b26a..000000000 --- a/store/migration/postgres/0.22/00__resource_storage_type.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE resource ADD COLUMN storage_type TEXT NOT NULL DEFAULT ''; -ALTER TABLE resource ADD COLUMN reference TEXT NOT NULL DEFAULT ''; -ALTER TABLE resource ADD COLUMN payload TEXT NOT NULL DEFAULT '{}'; - -UPDATE resource SET storage_type = 'LOCAL', reference = internal_path WHERE internal_path IS NOT NULL AND internal_path != ''; - -UPDATE resource SET storage_type = 'EXTERNAL', reference = external_link WHERE external_link IS NOT NULL AND external_link != ''; - -ALTER TABLE resource DROP COLUMN internal_path; - -ALTER TABLE resource DROP COLUMN external_link; diff --git a/store/migration/postgres/0.22/01__memo_tags.sql b/store/migration/postgres/0.22/01__memo_tags.sql deleted file mode 100644 index 53012f986..000000000 --- a/store/migration/postgres/0.22/01__memo_tags.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE memo ADD COLUMN tags JSONB NOT NULL DEFAULT '[]'; diff --git a/store/migration/postgres/0.22/02__memo_payload.sql b/store/migration/postgres/0.22/02__memo_payload.sql deleted file mode 100644 index 68dc159c6..000000000 --- a/store/migration/postgres/0.22/02__memo_payload.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE memo ADD COLUMN payload JSONB NOT NULL DEFAULT '{}'; diff --git a/store/migration/postgres/0.22/03__drop_tag.sql b/store/migration/postgres/0.22/03__drop_tag.sql deleted file mode 100644 index 8e3d418e6..000000000 --- a/store/migration/postgres/0.22/03__drop_tag.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS tag; diff --git a/store/migration/postgres/0.23/00__reactions.sql b/store/migration/postgres/0.23/00__reactions.sql deleted file mode 100644 index a01e95a29..000000000 --- a/store/migration/postgres/0.23/00__reactions.sql +++ /dev/null @@ -1,12 +0,0 @@ -UPDATE "reaction" SET "reaction_type" = '👍' WHERE "reaction_type" = 'THUMBS_UP'; -UPDATE "reaction" SET "reaction_type" = '👎' WHERE "reaction_type" = 'THUMBS_DOWN'; -UPDATE "reaction" SET "reaction_type" = '💛' WHERE "reaction_type" = 'HEART'; -UPDATE "reaction" SET "reaction_type" = '🔥' WHERE "reaction_type" = 'FIRE'; -UPDATE "reaction" SET "reaction_type" = '👏' WHERE "reaction_type" = 'CLAPPING_HANDS'; -UPDATE "reaction" SET "reaction_type" = '😂' WHERE "reaction_type" = 'LAUGH'; -UPDATE "reaction" SET "reaction_type" = '👌' WHERE "reaction_type" = 'OK_HAND'; -UPDATE "reaction" SET "reaction_type" = '🚀' WHERE "reaction_type" = 'ROCKET'; -UPDATE "reaction" SET "reaction_type" = '👀' WHERE "reaction_type" = 'EYES'; -UPDATE "reaction" SET "reaction_type" = '🤔' WHERE "reaction_type" = 'THINKING_FACE'; -UPDATE "reaction" SET "reaction_type" = '🤡' WHERE "reaction_type" = 'CLOWN_FACE'; -UPDATE "reaction" SET "reaction_type" = '❓' WHERE "reaction_type" = 'QUESTION_MARK'; diff --git a/store/migration/postgres/0.24/00__memo.sql b/store/migration/postgres/0.24/00__memo.sql deleted file mode 100644 index 0ea2d2221..000000000 --- a/store/migration/postgres/0.24/00__memo.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Drop deprecated tags column. -ALTER TABLE memo DROP COLUMN IF EXISTS tags; \ No newline at end of file diff --git a/store/migration/postgres/0.24/01__memo_pinned.sql b/store/migration/postgres/0.24/01__memo_pinned.sql deleted file mode 100644 index 66adf63c1..000000000 --- a/store/migration/postgres/0.24/01__memo_pinned.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Add pinned column. -ALTER TABLE memo ADD COLUMN pinned BOOLEAN NOT NULL DEFAULT FALSE; - --- Update pinned column from memo_organizer. -UPDATE memo -SET pinned = TRUE -FROM memo_organizer -WHERE memo.id = memo_organizer.memo_id AND memo_organizer.pinned = 1; \ No newline at end of file diff --git a/store/migration/postgres/0.25/00__remove_webhook.sql b/store/migration/postgres/0.25/00__remove_webhook.sql deleted file mode 100644 index f60efc073..000000000 --- a/store/migration/postgres/0.25/00__remove_webhook.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS webhook; diff --git a/store/migration/postgres/0.26/00__rename_resource_to_attachment.sql b/store/migration/postgres/0.26/00__rename_resource_to_attachment.sql deleted file mode 100644 index 9e0e4396e..000000000 --- a/store/migration/postgres/0.26/00__rename_resource_to_attachment.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE resource RENAME TO attachment; diff --git a/store/migration/postgres/0.26/01__drop_memo_organizer.sql b/store/migration/postgres/0.26/01__drop_memo_organizer.sql deleted file mode 100644 index 17c3579f2..000000000 --- a/store/migration/postgres/0.26/01__drop_memo_organizer.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS memo_organizer; diff --git a/store/migration/postgres/0.26/02__migrate_host_to_admin.sql b/store/migration/postgres/0.26/02__migrate_host_to_admin.sql deleted file mode 100644 index bd6db8024..000000000 --- a/store/migration/postgres/0.26/02__migrate_host_to_admin.sql +++ /dev/null @@ -1 +0,0 @@ -UPDATE "user" SET role = 'ADMIN' WHERE role = 'HOST'; diff --git a/store/migration/postgres/0.27/00__migrate_storage_setting.sql b/store/migration/postgres/0.27/00__migrate_storage_setting.sql deleted file mode 100644 index ea40755a9..000000000 --- a/store/migration/postgres/0.27/00__migrate_storage_setting.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Set storage type to DATABASE for existing instances that have no storage setting configured. --- This preserves backward-compatible behavior before the default was changed to LOCAL. -INSERT INTO system_setting (name, value, description) -SELECT 'STORAGE', '{"storageType":"DATABASE"}', '' -WHERE NOT EXISTS (SELECT 1 FROM system_setting WHERE name = 'STORAGE'); diff --git a/store/migration/postgres/0.27/01__add_idp_uid.sql b/store/migration/postgres/0.27/01__add_idp_uid.sql deleted file mode 100644 index d6ac67fea..000000000 --- a/store/migration/postgres/0.27/01__add_idp_uid.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Add uid column to idp table -ALTER TABLE idp ADD COLUMN uid TEXT NOT NULL DEFAULT ''; - --- Populate uid for existing rows using hex of id as a fallback -UPDATE idp SET uid = LPAD(TO_HEX(id), 8, '0') WHERE uid = ''; - --- Create unique index on uid -CREATE UNIQUE INDEX IF NOT EXISTS idx_idp_uid ON idp (uid); diff --git a/store/migration/postgres/0.27/02__migrate_inbox_message_payload.sql b/store/migration/postgres/0.27/02__migrate_inbox_message_payload.sql deleted file mode 100644 index 413915e76..000000000 --- a/store/migration/postgres/0.27/02__migrate_inbox_message_payload.sql +++ /dev/null @@ -1,13 +0,0 @@ -UPDATE inbox AS i -SET message = jsonb_set( - i.message::jsonb - 'activityId', - '{memoComment}', - jsonb_build_object( - 'memoId', - a.payload->'memoComment'->'memoId', - 'relatedMemoId', - a.payload->'memoComment'->'relatedMemoId' - ) -)::text -FROM activity AS a -WHERE (i.message::jsonb->>'activityId')::integer = a.id; diff --git a/store/migration/postgres/0.27/03__drop_activity.sql b/store/migration/postgres/0.27/03__drop_activity.sql deleted file mode 100644 index 6a508d33f..000000000 --- a/store/migration/postgres/0.27/03__drop_activity.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE activity; diff --git a/store/migration/postgres/0.27/04__memo_share.sql b/store/migration/postgres/0.27/04__memo_share.sql deleted file mode 100644 index 1505c3ecc..000000000 --- a/store/migration/postgres/0.27/04__memo_share.sql +++ /dev/null @@ -1,14 +0,0 @@ --- memo_share stores per-memo share grants (one row per share link). --- uid is the opaque bearer token included in the share URL. --- ON DELETE CASCADE ensures grants are cleaned up when the parent memo is deleted. -CREATE TABLE memo_share ( - id SERIAL PRIMARY KEY, - uid TEXT NOT NULL UNIQUE, - memo_id INTEGER NOT NULL, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - expires_ts BIGINT DEFAULT NULL, - FOREIGN KEY (memo_id) REFERENCES memo(id) ON DELETE CASCADE -); - -CREATE INDEX idx_memo_share_memo_id ON memo_share(memo_id); diff --git a/store/migration/postgres/0.28/00__user_identity.sql b/store/migration/postgres/0.28/00__user_identity.sql deleted file mode 100644 index dd786b402..000000000 --- a/store/migration/postgres/0.28/00__user_identity.sql +++ /dev/null @@ -1,15 +0,0 @@ --- user_identity stores the linkage between an external identity subject and a local user. --- (provider, extern_uid) is unique across the table; provider stores the idp.uid. --- Each local user can link at most one external account per provider. -CREATE TABLE user_identity ( - id SERIAL PRIMARY KEY, - user_id INTEGER NOT NULL, - provider TEXT NOT NULL, - extern_uid TEXT NOT NULL, - created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - UNIQUE (provider, extern_uid), - UNIQUE (user_id, provider) -); - -CREATE INDEX idx_user_identity_user_id ON user_identity(user_id); diff --git a/store/migration/postgres/0.30/00__user_tag_setting.sql b/store/migration/postgres/0.30/00__user_tag_setting.sql deleted file mode 100644 index bea163f11..000000000 --- a/store/migration/postgres/0.30/00__user_tag_setting.sql +++ /dev/null @@ -1,11 +0,0 @@ -INSERT INTO user_setting (user_id, key, value) -SELECT - "user".id, - 'TAGS', - system_setting.value -FROM "user" -JOIN system_setting ON system_setting.name = 'TAGS' -WHERE system_setting.value IS NOT NULL - AND system_setting.value != '' - AND system_setting.value != '{}' -ON CONFLICT (user_id, key) DO NOTHING; diff --git a/store/migration/postgres/0.31/00__rename_shortcuts_to_memo_views.sql b/store/migration/postgres/0.31/00__rename_shortcuts_to_memo_views.sql deleted file mode 100644 index ce4ac9c42..000000000 --- a/store/migration/postgres/0.31/00__rename_shortcuts_to_memo_views.sql +++ /dev/null @@ -1,28 +0,0 @@ --- Renames the SHORTCUTS user setting to MEMO_VIEWS, rewriting the stored JSON --- object key from `shortcuts` to `memoViews` to match the renamed proto field. --- --- Invalid or non-object JSON values are skipped rather than aborting the upgrade, --- while the conflict check preserves an existing MEMO_VIEWS setting. -UPDATE user_setting AS legacy -SET - key = 'MEMO_VIEWS', - value = CASE - WHEN legacy.value::jsonb ? 'shortcuts' THEN jsonb_set( - legacy.value::jsonb - 'shortcuts', - '{memoViews}', - legacy.value::jsonb->'shortcuts' - )::text - ELSE legacy.value - END -WHERE legacy.key = 'SHORTCUTS' - AND CASE - WHEN pg_input_is_valid(legacy.value, 'jsonb') - THEN jsonb_typeof(legacy.value::jsonb) = 'object' - ELSE FALSE - END - AND NOT EXISTS ( - SELECT 1 - FROM user_setting AS existing - WHERE existing.user_id = legacy.user_id - AND existing.key = 'MEMO_VIEWS' - ); diff --git a/store/migration/postgres/0.31/01__migrate_storage_setting.sql b/store/migration/postgres/0.31/01__migrate_storage_setting.sql deleted file mode 100644 index 41650d14b..000000000 --- a/store/migration/postgres/0.31/01__migrate_storage_setting.sql +++ /dev/null @@ -1,104 +0,0 @@ --- Expands the legacy singleton storage setting into the named storage model. --- Legacy fields remain in place so older clients and rollback versions can --- continue to read the active storage configuration. -UPDATE system_setting -SET value = jsonb_set( - jsonb_set( - value::jsonb, - '{storages}', - jsonb_build_array(jsonb_build_object( - 'id', 'database', - 'name', 'Database', - 'type', 'STORAGE_TYPE_DATABASE' - )) - ), - '{defaultStorageId}', - to_jsonb('database'::text) -)::text -WHERE name = 'STORAGE' - AND CASE - WHEN pg_input_is_valid(value, 'jsonb') THEN - jsonb_typeof(value::jsonb) = 'object' - AND NOT value::jsonb ? 'storages' - AND value::jsonb->>'storageType' IN ('DATABASE', '1') - ELSE FALSE - END; - -UPDATE system_setting -SET value = jsonb_set( - jsonb_set( - value::jsonb, - '{storages}', - jsonb_build_array(jsonb_build_object( - 'id', 'local', - 'name', 'Local', - 'type', 'STORAGE_TYPE_LOCAL' - )) - ), - '{defaultStorageId}', - to_jsonb('local'::text) -)::text -WHERE name = 'STORAGE' - AND CASE - WHEN pg_input_is_valid(value, 'jsonb') THEN - jsonb_typeof(value::jsonb) = 'object' - AND NOT value::jsonb ? 'storages' - AND ( - NOT value::jsonb ? 'storageType' - OR value::jsonb->>'storageType' IN ('STORAGE_TYPE_UNSPECIFIED', 'LOCAL', '0', '2') - ) - ELSE FALSE - END; - -UPDATE system_setting -SET value = jsonb_set( - jsonb_set( - value::jsonb, - '{storages}', - jsonb_build_array(jsonb_build_object( - 'id', 's3', - 'name', 'S3', - 'type', 'STORAGE_TYPE_S3', - 's3Config', value::jsonb->'s3Config' - )) - ), - '{defaultStorageId}', - to_jsonb('s3'::text) -)::text -WHERE name = 'STORAGE' - AND CASE - WHEN pg_input_is_valid(value, 'jsonb') THEN - jsonb_typeof(value::jsonb) = 'object' - AND NOT value::jsonb ? 'storages' - AND value::jsonb->>'storageType' IN ('S3', '3') - AND jsonb_typeof(value::jsonb->'s3Config') = 'object' - ELSE FALSE - END; - --- Attachments created before S3 configs were embedded only stored the object --- key. Bind them to the namespace captured above before that default changes. -UPDATE attachment -SET payload = jsonb_set( - payload::jsonb, - '{s3Object,storageId}', - to_jsonb('s3'::text) -)::text -WHERE storage_type = 'S3' - AND CASE - WHEN pg_input_is_valid(payload, 'jsonb') THEN - jsonb_typeof(payload::jsonb) = 'object' - AND jsonb_typeof(payload::jsonb->'s3Object') = 'object' - AND NOT payload::jsonb->'s3Object' ? 'storageId' - AND NOT payload::jsonb->'s3Object' ? 's3Config' - ELSE FALSE - END - AND EXISTS ( - SELECT 1 - FROM system_setting AS storage_setting - WHERE storage_setting.name = 'STORAGE' - AND CASE - WHEN pg_input_is_valid(storage_setting.value, 'jsonb') THEN - storage_setting.value::jsonb->>'defaultStorageId' = 's3' - ELSE FALSE - END - ); diff --git a/store/migration/postgres/0.31/02__reaction_memo_id.sql b/store/migration/postgres/0.31/02__reaction_memo_id.sql deleted file mode 100644 index d2b754861..000000000 --- a/store/migration/postgres/0.31/02__reaction_memo_id.sql +++ /dev/null @@ -1,17 +0,0 @@ --- Replaces the memo resource name stored in reaction.content_id with the --- memo's stable internal ID. Rows that cannot be resolved are intentionally --- deleted before memo_id is made non-nullable. -ALTER TABLE reaction ADD COLUMN memo_id INTEGER; - -UPDATE reaction -SET memo_id = memo.id -FROM memo -WHERE reaction.content_id = 'memos/' || memo.uid; - -DELETE FROM reaction WHERE memo_id IS NULL; - -ALTER TABLE reaction - DROP CONSTRAINT reaction_creator_id_content_id_reaction_type_key, - DROP COLUMN content_id, - ALTER COLUMN memo_id SET NOT NULL, - ADD UNIQUE (creator_id, memo_id, reaction_type); diff --git a/store/migration/postgres/0.31/03__multi_spaces.sql b/store/migration/postgres/0.31/03__multi_spaces.sql deleted file mode 100644 index dbbbfb22f..000000000 --- a/store/migration/postgres/0.31/03__multi_spaces.sql +++ /dev/null @@ -1,20 +0,0 @@ -CREATE TABLE space ( - id SERIAL PRIMARY KEY, - uid TEXT NOT NULL UNIQUE, - title TEXT NOT NULL, - description TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE space_member ( - space_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - role TEXT NOT NULL CHECK (role IN ('ADMIN', 'USER')), - PRIMARY KEY (space_id, user_id) -); - -ALTER TABLE memo ADD COLUMN space_id INTEGER DEFAULT NULL; - -CREATE INDEX idx_space_member_user_id ON space_member(user_id, space_id); -CREATE INDEX idx_memo_space_id ON memo(space_id, row_status, created_ts DESC, id DESC); -CREATE INDEX idx_memo_relation_related_type_memo - ON memo_relation(related_memo_id, type, memo_id); diff --git a/store/migration/postgres/0.31/04__space_member_status.sql b/store/migration/postgres/0.31/04__space_member_status.sql deleted file mode 100644 index f82e9ed4e..000000000 --- a/store/migration/postgres/0.31/04__space_member_status.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE space_member - ADD COLUMN status TEXT; - -UPDATE space_member -SET status = 'ACTIVE'; - -ALTER TABLE space_member - ALTER COLUMN status SET NOT NULL; diff --git a/store/migration/postgres/0.31/05__case_sensitive_username.sql b/store/migration/postgres/0.31/05__case_sensitive_username.sql deleted file mode 100644 index c78a8bc64..000000000 --- a/store/migration/postgres/0.31/05__case_sensitive_username.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE "user" - ALTER COLUMN username TYPE TEXT COLLATE "C"; diff --git a/store/migration/postgres/0.31/06__space_payload.sql b/store/migration/postgres/0.31/06__space_payload.sql deleted file mode 100644 index b02c713a7..000000000 --- a/store/migration/postgres/0.31/06__space_payload.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE space ADD COLUMN payload JSONB NOT NULL DEFAULT '{}'; diff --git a/store/migration/postgres/0.31/07__unique_email.sql b/store/migration/postgres/0.31/07__unique_email.sql deleted file mode 100644 index f9c1ddccb..000000000 --- a/store/migration/postgres/0.31/07__unique_email.sql +++ /dev/null @@ -1,21 +0,0 @@ --- Make user.email an optional, canonical, instance-unique attribute. -ALTER TABLE "user" - ALTER COLUMN email DROP NOT NULL, - ALTER COLUMN email DROP DEFAULT, - ALTER COLUMN email TYPE TEXT COLLATE "C"; - --- Canonical form: trimmed and lowercased. -UPDATE "user" SET email = LOWER(TRIM(email)); - --- Empty values, values without an '@', and values carrying display-name --- syntax or interior whitespace mean no address. -UPDATE "user" SET email = NULL -WHERE email = '' OR email NOT LIKE '%@%' OR email LIKE '%<%' OR email LIKE '%>%' OR email LIKE '% %'; - --- For each address held by more than one account, the oldest account keeps it. -UPDATE "user" -SET email = NULL -WHERE email IS NOT NULL - AND id NOT IN (SELECT MIN(id) FROM "user" WHERE email IS NOT NULL GROUP BY email); - -CREATE UNIQUE INDEX IF NOT EXISTS idx_user_email ON "user" (email); diff --git a/store/migration/sqlite/0.10/00__activity.sql b/store/migration/sqlite/0.10/00__activity.sql deleted file mode 100644 index 459468d66..000000000 --- a/store/migration/sqlite/0.10/00__activity.sql +++ /dev/null @@ -1,9 +0,0 @@ --- activity -CREATE TABLE activity ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - type TEXT NOT NULL DEFAULT '', - level TEXT NOT NULL CHECK (level IN ('INFO', 'WARN', 'ERROR')) DEFAULT 'INFO', - payload TEXT NOT NULL DEFAULT '{}' -); \ No newline at end of file diff --git a/store/migration/sqlite/0.11/00__user_avatar.sql b/store/migration/sqlite/0.11/00__user_avatar.sql deleted file mode 100644 index 11c63e950..000000000 --- a/store/migration/sqlite/0.11/00__user_avatar.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE - user -ADD - COLUMN avatar_url TEXT NOT NULL DEFAULT ''; \ No newline at end of file diff --git a/store/migration/sqlite/0.11/01__idp.sql b/store/migration/sqlite/0.11/01__idp.sql deleted file mode 100644 index be5cf49fd..000000000 --- a/store/migration/sqlite/0.11/01__idp.sql +++ /dev/null @@ -1,8 +0,0 @@ --- idp -CREATE TABLE idp ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - type TEXT NOT NULL, - identifier_filter TEXT NOT NULL DEFAULT '', - config TEXT NOT NULL DEFAULT '{}' -); \ No newline at end of file diff --git a/store/migration/sqlite/0.11/02__storage.sql b/store/migration/sqlite/0.11/02__storage.sql deleted file mode 100644 index 8dbf56372..000000000 --- a/store/migration/sqlite/0.11/02__storage.sql +++ /dev/null @@ -1,7 +0,0 @@ --- storage -CREATE TABLE storage ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - type TEXT NOT NULL, - config TEXT NOT NULL DEFAULT '{}' -); \ No newline at end of file diff --git a/store/migration/sqlite/0.12/00__user_setting.sql b/store/migration/sqlite/0.12/00__user_setting.sql deleted file mode 100644 index b9fbbe62e..000000000 --- a/store/migration/sqlite/0.12/00__user_setting.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE - user_setting -SET - key = 'memo-visibility' -WHERE - key = 'memoVisibility'; \ No newline at end of file diff --git a/store/migration/sqlite/0.12/01__system_setting.sql b/store/migration/sqlite/0.12/01__system_setting.sql deleted file mode 100644 index 12fabb77b..000000000 --- a/store/migration/sqlite/0.12/01__system_setting.sql +++ /dev/null @@ -1,69 +0,0 @@ -UPDATE - system_setting -SET - name = 'server-id' -WHERE - name = 'serverId'; - -UPDATE - system_setting -SET - name = 'secret-session' -WHERE - name = 'secretSessionName'; - -UPDATE - system_setting -SET - name = 'allow-signup' -WHERE - name = 'allowSignUp'; - -UPDATE - system_setting -SET - name = 'disable-public-memos' -WHERE - name = 'disablePublicMemos'; - -UPDATE - system_setting -SET - name = 'additional-style' -WHERE - name = 'additionalStyle'; - -UPDATE - system_setting -SET - name = 'additional-script' -WHERE - name = 'additionalScript'; - -UPDATE - system_setting -SET - name = 'customized-profile' -WHERE - name = 'customizedProfile'; - -UPDATE - system_setting -SET - name = 'storage-service-id' -WHERE - name = 'storageServiceId'; - -UPDATE - system_setting -SET - name = 'local-storage-path' -WHERE - name = 'localStoragePath'; - -UPDATE - system_setting -SET - name = 'openai-config' -WHERE - name = 'openAIConfig'; \ No newline at end of file diff --git a/store/migration/sqlite/0.12/03__resource_internal_path.sql b/store/migration/sqlite/0.12/03__resource_internal_path.sql deleted file mode 100644 index 97f37a375..000000000 --- a/store/migration/sqlite/0.12/03__resource_internal_path.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE - resource -ADD - COLUMN internal_path TEXT NOT NULL DEFAULT ''; \ No newline at end of file diff --git a/store/migration/sqlite/0.12/04__resource_public_id.sql b/store/migration/sqlite/0.12/04__resource_public_id.sql deleted file mode 100644 index ef08d02a6..000000000 --- a/store/migration/sqlite/0.12/04__resource_public_id.sql +++ /dev/null @@ -1,18 +0,0 @@ -ALTER TABLE - resource -ADD - COLUMN public_id TEXT NOT NULL DEFAULT ''; - -CREATE UNIQUE INDEX resource_id_public_id_unique_index ON resource (id, public_id); - -UPDATE - resource -SET - public_id = printf ( - '%s-%s-%s-%s-%s', - lower(hex(randomblob(4))), - lower(hex(randomblob(2))), - lower(hex(randomblob(2))), - lower(hex(randomblob(2))), - lower(hex(randomblob(6))) - ); \ No newline at end of file diff --git a/store/migration/sqlite/0.13/00__memo_relation.sql b/store/migration/sqlite/0.13/00__memo_relation.sql deleted file mode 100644 index 821a5984c..000000000 --- a/store/migration/sqlite/0.13/00__memo_relation.sql +++ /dev/null @@ -1,7 +0,0 @@ --- memo_relation -CREATE TABLE memo_relation ( - memo_id INTEGER NOT NULL, - related_memo_id INTEGER NOT NULL, - type TEXT NOT NULL, - UNIQUE(memo_id, related_memo_id, type) -); \ No newline at end of file diff --git a/store/migration/sqlite/0.13/01__remove_memo_organizer_id.sql b/store/migration/sqlite/0.13/01__remove_memo_organizer_id.sql deleted file mode 100644 index 6c4156c45..000000000 --- a/store/migration/sqlite/0.13/01__remove_memo_organizer_id.sql +++ /dev/null @@ -1,22 +0,0 @@ -DROP TABLE IF EXISTS memo_organizer_temp; - -CREATE TABLE memo_organizer_temp ( - memo_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0, - UNIQUE(memo_id, user_id) -); - -INSERT INTO - memo_organizer_temp (memo_id, user_id, pinned) -SELECT - memo_id, - user_id, - pinned -FROM - memo_organizer; - -DROP TABLE memo_organizer; - -ALTER TABLE - memo_organizer_temp RENAME TO memo_organizer; \ No newline at end of file diff --git a/store/migration/sqlite/0.14/00__drop_resource_public_id.sql b/store/migration/sqlite/0.14/00__drop_resource_public_id.sql deleted file mode 100644 index c6e636d04..000000000 --- a/store/migration/sqlite/0.14/00__drop_resource_public_id.sql +++ /dev/null @@ -1,25 +0,0 @@ -DROP TABLE IF EXISTS resource_temp; - -CREATE TABLE resource_temp ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - filename TEXT NOT NULL DEFAULT '', - blob BLOB DEFAULT NULL, - external_link TEXT NOT NULL DEFAULT '', - type TEXT NOT NULL DEFAULT '', - size INTEGER NOT NULL DEFAULT 0, - internal_path TEXT NOT NULL DEFAULT '' -); - -INSERT INTO - resource_temp (id, creator_id, created_ts, updated_ts, filename, blob, external_link, type, size, internal_path) -SELECT - id, creator_id, created_ts, updated_ts, filename, blob, external_link, type, size, internal_path -FROM - resource; - -DROP TABLE resource; - -ALTER TABLE resource_temp RENAME TO resource; diff --git a/store/migration/sqlite/0.14/01__create_indexes.sql b/store/migration/sqlite/0.14/01__create_indexes.sql deleted file mode 100644 index 721c05d85..000000000 --- a/store/migration/sqlite/0.14/01__create_indexes.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE INDEX IF NOT EXISTS idx_user_username ON user (username); -CREATE INDEX IF NOT EXISTS idx_memo_creator_id ON memo (creator_id); -CREATE INDEX IF NOT EXISTS idx_memo_content ON memo (content); -CREATE INDEX IF NOT EXISTS idx_memo_visibility ON memo (visibility); -CREATE INDEX IF NOT EXISTS idx_resource_creator_id ON resource (creator_id); diff --git a/store/migration/sqlite/0.15/00__drop_user_open_id.sql b/store/migration/sqlite/0.15/00__drop_user_open_id.sql deleted file mode 100644 index 711d32a9f..000000000 --- a/store/migration/sqlite/0.15/00__drop_user_open_id.sql +++ /dev/null @@ -1,25 +0,0 @@ -DROP TABLE IF EXISTS user_temp; - -CREATE TABLE user_temp ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - username TEXT NOT NULL UNIQUE, - role TEXT NOT NULL CHECK (role IN ('HOST', 'ADMIN', 'USER')) DEFAULT 'USER', - email TEXT NOT NULL DEFAULT '', - nickname TEXT NOT NULL DEFAULT '', - password_hash TEXT NOT NULL, - avatar_url TEXT NOT NULL DEFAULT '' -); - -INSERT INTO - user_temp (id, created_ts, updated_ts, row_status, username, role, email, nickname, password_hash, avatar_url) -SELECT - id, created_ts, updated_ts, row_status, username, role, email, nickname, password_hash, avatar_url -FROM - user; - -DROP TABLE user; - -ALTER TABLE user_temp RENAME TO user; diff --git a/store/migration/sqlite/0.16/00__add_memo_id_to_resource.sql b/store/migration/sqlite/0.16/00__add_memo_id_to_resource.sql deleted file mode 100644 index 5af8ad632..000000000 --- a/store/migration/sqlite/0.16/00__add_memo_id_to_resource.sql +++ /dev/null @@ -1,13 +0,0 @@ -ALTER TABLE resource ADD COLUMN memo_id INTEGER; - -UPDATE resource -SET memo_id = ( - SELECT memo_id - FROM memo_resource - WHERE resource.id = memo_resource.resource_id - LIMIT 1 -); - -CREATE INDEX idx_resource_memo_id ON resource (memo_id); - -DROP TABLE IF EXISTS memo_resource; diff --git a/store/migration/sqlite/0.16/01__drop_shortcut_table.sql b/store/migration/sqlite/0.16/01__drop_shortcut_table.sql deleted file mode 100644 index d830a5b47..000000000 --- a/store/migration/sqlite/0.16/01__drop_shortcut_table.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS shortcut; diff --git a/store/migration/sqlite/0.17/00__inbox.sql b/store/migration/sqlite/0.17/00__inbox.sql deleted file mode 100644 index ed5f309ec..000000000 --- a/store/migration/sqlite/0.17/00__inbox.sql +++ /dev/null @@ -1,9 +0,0 @@ --- inbox -CREATE TABLE inbox ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - sender_id INTEGER NOT NULL, - receiver_id INTEGER NOT NULL, - status TEXT NOT NULL, - message TEXT NOT NULL DEFAULT '{}' -); diff --git a/store/migration/sqlite/0.17/01__delete_activities.sql b/store/migration/sqlite/0.17/01__delete_activities.sql deleted file mode 100644 index 24593d47c..000000000 --- a/store/migration/sqlite/0.17/01__delete_activities.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE FROM activity; diff --git a/store/migration/sqlite/0.18/00__webhook.sql b/store/migration/sqlite/0.18/00__webhook.sql deleted file mode 100644 index 426ce9c2a..000000000 --- a/store/migration/sqlite/0.18/00__webhook.sql +++ /dev/null @@ -1,12 +0,0 @@ --- webhook -CREATE TABLE webhook ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - creator_id INTEGER NOT NULL, - name TEXT NOT NULL, - url TEXT NOT NULL -); - -CREATE INDEX idx_webhook_creator_id ON webhook (creator_id); diff --git a/store/migration/sqlite/0.18/01__user_setting.sql b/store/migration/sqlite/0.18/01__user_setting.sql deleted file mode 100644 index fe79a8f16..000000000 --- a/store/migration/sqlite/0.18/01__user_setting.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE user_setting SET key = 'USER_SETTING_LOCALE', value = REPLACE(value, '"', '') WHERE key = 'locale'; -UPDATE user_setting SET key = 'USER_SETTING_APPEARANCE', value = REPLACE(value, '"', '') WHERE key = 'appearance'; -UPDATE user_setting SET key = 'USER_SETTING_MEMO_VISIBILITY', value = REPLACE(value, '"', '') WHERE key = 'memo-visibility'; -UPDATE user_setting SET key = 'USER_SETTING_TELEGRAM_USER_ID', value = REPLACE(value, '"', '') WHERE key = 'telegram-user-id'; diff --git a/store/migration/sqlite/0.19/00__add_resource_name.sql b/store/migration/sqlite/0.19/00__add_resource_name.sql deleted file mode 100644 index 33add15ec..000000000 --- a/store/migration/sqlite/0.19/00__add_resource_name.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE memo ADD COLUMN resource_name TEXT NOT NULL DEFAULT ""; - -UPDATE memo SET resource_name = lower(hex(randomblob(8))); - -CREATE UNIQUE INDEX idx_memo_resource_name ON memo (resource_name); - -ALTER TABLE resource ADD COLUMN resource_name TEXT NOT NULL DEFAULT ""; - -UPDATE resource SET resource_name = lower(hex(randomblob(8))); - -CREATE UNIQUE INDEX idx_resource_resource_name ON resource (resource_name); diff --git a/store/migration/sqlite/0.2/00__user_role.sql b/store/migration/sqlite/0.2/00__user_role.sql deleted file mode 100644 index e6a312e9b..000000000 --- a/store/migration/sqlite/0.2/00__user_role.sql +++ /dev/null @@ -1,60 +0,0 @@ --- change user role field from "OWNER"/"USER" to "HOST"/"USER". -PRAGMA foreign_keys = off; - -DROP TABLE IF EXISTS _user_old; - -ALTER TABLE - user RENAME TO _user_old; - -CREATE TABLE user ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - email TEXT NOT NULL UNIQUE, - role TEXT NOT NULL CHECK (role IN ('HOST', 'USER')) DEFAULT 'USER', - name TEXT NOT NULL, - password_hash TEXT NOT NULL, - open_id TEXT NOT NULL UNIQUE -); - -INSERT INTO - user ( - id, - created_ts, - updated_ts, - row_status, - email, - name, - password_hash, - open_id - ) -SELECT - id, - created_ts, - updated_ts, - row_status, - email, - name, - password_hash, - open_id -FROM - _user_old; - -UPDATE - user -SET - role = 'HOST' -WHERE - id IN ( - SELECT - id - FROM - _user_old - WHERE - role = 'OWNER' - ); - -DROP TABLE IF EXISTS _user_old; - -PRAGMA foreign_keys = on; \ No newline at end of file diff --git a/store/migration/sqlite/0.2/01__memo_visibility.sql b/store/migration/sqlite/0.2/01__memo_visibility.sql deleted file mode 100644 index 84a00daee..000000000 --- a/store/migration/sqlite/0.2/01__memo_visibility.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE - memo -ADD - COLUMN visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PRIVATE')) DEFAULT 'PRIVATE'; \ No newline at end of file diff --git a/store/migration/sqlite/0.20/00__reaction.sql b/store/migration/sqlite/0.20/00__reaction.sql deleted file mode 100644 index b4e8bd62c..000000000 --- a/store/migration/sqlite/0.20/00__reaction.sql +++ /dev/null @@ -1,9 +0,0 @@ --- reaction -CREATE TABLE reaction ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - creator_id INTEGER NOT NULL, - content_id TEXT NOT NULL, - reaction_type TEXT NOT NULL, - UNIQUE(creator_id, content_id, reaction_type) -); diff --git a/store/migration/sqlite/0.21/00__user_description.sql b/store/migration/sqlite/0.21/00__user_description.sql deleted file mode 100644 index 53408fe0d..000000000 --- a/store/migration/sqlite/0.21/00__user_description.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE user ADD COLUMN description TEXT NOT NULL DEFAULT ""; diff --git a/store/migration/sqlite/0.21/01__rename_uid.sql b/store/migration/sqlite/0.21/01__rename_uid.sql deleted file mode 100644 index 12a040225..000000000 --- a/store/migration/sqlite/0.21/01__rename_uid.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE memo RENAME COLUMN resource_name TO uid; - -ALTER TABLE resource RENAME COLUMN resource_name TO uid; diff --git a/store/migration/sqlite/0.22/00__resource_storage_type.sql b/store/migration/sqlite/0.22/00__resource_storage_type.sql deleted file mode 100644 index daa46de20..000000000 --- a/store/migration/sqlite/0.22/00__resource_storage_type.sql +++ /dev/null @@ -1,17 +0,0 @@ -ALTER TABLE resource ADD COLUMN storage_type TEXT NOT NULL DEFAULT ''; - -ALTER TABLE resource ADD COLUMN reference TEXT NOT NULL DEFAULT ''; - -ALTER TABLE resource ADD COLUMN payload TEXT NOT NULL DEFAULT '{}'; - -UPDATE resource -SET storage_type = 'LOCAL', reference = internal_path -WHERE internal_path IS NOT NULL AND internal_path != ''; - -UPDATE resource -SET storage_type = 'EXTERNAL', reference = external_link -WHERE external_link IS NOT NULL AND external_link != ''; - -ALTER TABLE resource DROP COLUMN internal_path; - -ALTER TABLE resource DROP COLUMN external_link; diff --git a/store/migration/sqlite/0.22/01__memo_tags.sql b/store/migration/sqlite/0.22/01__memo_tags.sql deleted file mode 100644 index 5816269b1..000000000 --- a/store/migration/sqlite/0.22/01__memo_tags.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE memo ADD COLUMN tags TEXT NOT NULL DEFAULT '[]'; - -CREATE INDEX idx_memo_tags ON memo (tags); diff --git a/store/migration/sqlite/0.22/02__memo_payload.sql b/store/migration/sqlite/0.22/02__memo_payload.sql deleted file mode 100644 index 267a7497c..000000000 --- a/store/migration/sqlite/0.22/02__memo_payload.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE memo ADD COLUMN payload TEXT NOT NULL DEFAULT '{}'; diff --git a/store/migration/sqlite/0.22/03__drop_tag.sql b/store/migration/sqlite/0.22/03__drop_tag.sql deleted file mode 100644 index 6411efb7a..000000000 --- a/store/migration/sqlite/0.22/03__drop_tag.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE tag; \ No newline at end of file diff --git a/store/migration/sqlite/0.23/00__reactions.sql b/store/migration/sqlite/0.23/00__reactions.sql deleted file mode 100644 index 13979d15c..000000000 --- a/store/migration/sqlite/0.23/00__reactions.sql +++ /dev/null @@ -1,12 +0,0 @@ -UPDATE `reaction` SET `reaction_type` = '👍' WHERE `reaction_type` = 'THUMBS_UP'; -UPDATE `reaction` SET `reaction_type` = '👎' WHERE `reaction_type` = 'THUMBS_DOWN'; -UPDATE `reaction` SET `reaction_type` = '💛' WHERE `reaction_type` = 'HEART'; -UPDATE `reaction` SET `reaction_type` = '🔥' WHERE `reaction_type` = 'FIRE'; -UPDATE `reaction` SET `reaction_type` = '👏' WHERE `reaction_type` = 'CLAPPING_HANDS'; -UPDATE `reaction` SET `reaction_type` = '😂' WHERE `reaction_type` = 'LAUGH'; -UPDATE `reaction` SET `reaction_type` = '👌' WHERE `reaction_type` = 'OK_HAND'; -UPDATE `reaction` SET `reaction_type` = '🚀' WHERE `reaction_type` = 'ROCKET'; -UPDATE `reaction` SET `reaction_type` = '👀' WHERE `reaction_type` = 'EYES'; -UPDATE `reaction` SET `reaction_type` = '🤔' WHERE `reaction_type` = 'THINKING_FACE'; -UPDATE `reaction` SET `reaction_type` = '🤡' WHERE `reaction_type` = 'CLOWN_FACE'; -UPDATE `reaction` SET `reaction_type` = '❓' WHERE `reaction_type` = 'QUESTION_MARK'; diff --git a/store/migration/sqlite/0.24/00__memo.sql b/store/migration/sqlite/0.24/00__memo.sql deleted file mode 100644 index 262085118..000000000 --- a/store/migration/sqlite/0.24/00__memo.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Remove deprecated indexes. -DROP INDEX IF EXISTS idx_memo_tags; -DROP INDEX IF EXISTS idx_memo_content; -DROP INDEX IF EXISTS idx_memo_visibility; - --- Drop deprecated tags column. -ALTER TABLE memo DROP COLUMN tags; \ No newline at end of file diff --git a/store/migration/sqlite/0.24/01__memo_pinned.sql b/store/migration/sqlite/0.24/01__memo_pinned.sql deleted file mode 100644 index 8fa12e6f7..000000000 --- a/store/migration/sqlite/0.24/01__memo_pinned.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Add pinned column. -ALTER TABLE memo ADD COLUMN pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0; - --- Update pinned column from memo_organizer. -UPDATE memo -SET pinned = 1 -WHERE EXISTS ( - SELECT 1 - FROM memo_organizer - WHERE memo.id = memo_organizer.memo_id AND memo_organizer.pinned = 1 -); diff --git a/store/migration/sqlite/0.25/00__remove_webhook.sql b/store/migration/sqlite/0.25/00__remove_webhook.sql deleted file mode 100644 index f60efc073..000000000 --- a/store/migration/sqlite/0.25/00__remove_webhook.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS webhook; diff --git a/store/migration/sqlite/0.26/00__rename_resource_to_attachment.sql b/store/migration/sqlite/0.26/00__rename_resource_to_attachment.sql deleted file mode 100644 index 151cd6d3a..000000000 --- a/store/migration/sqlite/0.26/00__rename_resource_to_attachment.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `resource` RENAME TO `attachment`; -DROP INDEX IF EXISTS `idx_resource_creator_id`; -CREATE INDEX `idx_attachment_creator_id` ON `attachment` (`creator_id`); -DROP INDEX IF EXISTS `idx_resource_memo_id`; -CREATE INDEX `idx_attachment_memo_id` ON `attachment` (`memo_id`); diff --git a/store/migration/sqlite/0.26/01__drop_memo_organizer.sql b/store/migration/sqlite/0.26/01__drop_memo_organizer.sql deleted file mode 100644 index 17c3579f2..000000000 --- a/store/migration/sqlite/0.26/01__drop_memo_organizer.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS memo_organizer; diff --git a/store/migration/sqlite/0.26/02__drop_indexes.sql b/store/migration/sqlite/0.26/02__drop_indexes.sql deleted file mode 100644 index 2923ba4fa..000000000 --- a/store/migration/sqlite/0.26/02__drop_indexes.sql +++ /dev/null @@ -1,4 +0,0 @@ -DROP INDEX IF EXISTS idx_user_username; -DROP INDEX IF EXISTS idx_memo_creator_id; -DROP INDEX IF EXISTS idx_attachment_creator_id; -DROP INDEX IF EXISTS idx_attachment_memo_id; diff --git a/store/migration/sqlite/0.26/03__alter_user_role.sql b/store/migration/sqlite/0.26/03__alter_user_role.sql deleted file mode 100644 index 863097541..000000000 --- a/store/migration/sqlite/0.26/03__alter_user_role.sql +++ /dev/null @@ -1,24 +0,0 @@ -ALTER TABLE user RENAME TO user_old; - -CREATE TABLE user ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - username TEXT NOT NULL UNIQUE, - role TEXT NOT NULL DEFAULT 'USER', - email TEXT NOT NULL DEFAULT '', - nickname TEXT NOT NULL DEFAULT '', - password_hash TEXT NOT NULL, - avatar_url TEXT NOT NULL DEFAULT '', - description TEXT NOT NULL DEFAULT '' -); - -INSERT INTO user ( - id, created_ts, updated_ts, row_status, username, role, email, nickname, password_hash, avatar_url, description -) -SELECT - id, created_ts, updated_ts, row_status, username, role, email, nickname, password_hash, avatar_url, description -FROM user_old; - -DROP TABLE user_old; diff --git a/store/migration/sqlite/0.26/04__migrate_host_to_admin.sql b/store/migration/sqlite/0.26/04__migrate_host_to_admin.sql deleted file mode 100644 index 3e3f850ed..000000000 --- a/store/migration/sqlite/0.26/04__migrate_host_to_admin.sql +++ /dev/null @@ -1 +0,0 @@ -UPDATE user SET role = 'ADMIN' WHERE role = 'HOST'; diff --git a/store/migration/sqlite/0.27/00__migrate_storage_setting.sql b/store/migration/sqlite/0.27/00__migrate_storage_setting.sql deleted file mode 100644 index ea40755a9..000000000 --- a/store/migration/sqlite/0.27/00__migrate_storage_setting.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Set storage type to DATABASE for existing instances that have no storage setting configured. --- This preserves backward-compatible behavior before the default was changed to LOCAL. -INSERT INTO system_setting (name, value, description) -SELECT 'STORAGE', '{"storageType":"DATABASE"}', '' -WHERE NOT EXISTS (SELECT 1 FROM system_setting WHERE name = 'STORAGE'); diff --git a/store/migration/sqlite/0.27/01__add_idp_uid.sql b/store/migration/sqlite/0.27/01__add_idp_uid.sql deleted file mode 100644 index 4a6d95233..000000000 --- a/store/migration/sqlite/0.27/01__add_idp_uid.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Add uid column to idp table -ALTER TABLE idp ADD COLUMN uid TEXT NOT NULL DEFAULT ''; - --- Populate uid for existing rows using hex of id as a fallback -UPDATE idp SET uid = printf('%08x', id) WHERE uid = ''; - --- Create unique index on uid -CREATE UNIQUE INDEX IF NOT EXISTS idx_idp_uid ON idp (uid); diff --git a/store/migration/sqlite/0.27/02__migrate_inbox_message_payload.sql b/store/migration/sqlite/0.27/02__migrate_inbox_message_payload.sql deleted file mode 100644 index 0a6714f8d..000000000 --- a/store/migration/sqlite/0.27/02__migrate_inbox_message_payload.sql +++ /dev/null @@ -1,25 +0,0 @@ -UPDATE inbox -SET message = json_set( - json_remove(message, '$.activityId'), - '$.memoComment', - json_object( - 'memoId', - ( - SELECT json_extract(activity.payload, '$.memoComment.memoId') - FROM activity - WHERE activity.id = json_extract(inbox.message, '$.activityId') - ), - 'relatedMemoId', - ( - SELECT json_extract(activity.payload, '$.memoComment.relatedMemoId') - FROM activity - WHERE activity.id = json_extract(inbox.message, '$.activityId') - ) - ) -) -WHERE json_extract(message, '$.activityId') IS NOT NULL - AND EXISTS ( - SELECT 1 - FROM activity - WHERE activity.id = json_extract(inbox.message, '$.activityId') - ); diff --git a/store/migration/sqlite/0.27/03__drop_activity.sql b/store/migration/sqlite/0.27/03__drop_activity.sql deleted file mode 100644 index 6a508d33f..000000000 --- a/store/migration/sqlite/0.27/03__drop_activity.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE activity; diff --git a/store/migration/sqlite/0.27/04__memo_share.sql b/store/migration/sqlite/0.27/04__memo_share.sql deleted file mode 100644 index 46673daab..000000000 --- a/store/migration/sqlite/0.27/04__memo_share.sql +++ /dev/null @@ -1,14 +0,0 @@ --- memo_share stores per-memo share grants (one row per share link). --- uid is the opaque bearer token included in the share URL. --- ON DELETE CASCADE ensures grants are cleaned up when the parent memo is deleted. -CREATE TABLE memo_share ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - uid TEXT NOT NULL UNIQUE, - memo_id INTEGER NOT NULL, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - expires_ts BIGINT DEFAULT NULL, - FOREIGN KEY (memo_id) REFERENCES memo(id) ON DELETE CASCADE -); - -CREATE INDEX idx_memo_share_memo_id ON memo_share(memo_id); diff --git a/store/migration/sqlite/0.28/00__user_identity.sql b/store/migration/sqlite/0.28/00__user_identity.sql deleted file mode 100644 index 204ee1c4f..000000000 --- a/store/migration/sqlite/0.28/00__user_identity.sql +++ /dev/null @@ -1,15 +0,0 @@ --- user_identity stores the linkage between an external identity subject and a local user. --- (provider, extern_uid) is unique across the table; provider stores the idp.uid. --- Each local user can link at most one external account per provider. -CREATE TABLE user_identity ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - user_id INTEGER NOT NULL, - provider TEXT NOT NULL, - extern_uid TEXT NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - UNIQUE (provider, extern_uid), - UNIQUE (user_id, provider) -); - -CREATE INDEX idx_user_identity_user_id ON user_identity(user_id); diff --git a/store/migration/sqlite/0.3/00__memo_visibility_protected.sql b/store/migration/sqlite/0.3/00__memo_visibility_protected.sql deleted file mode 100644 index b960f4a61..000000000 --- a/store/migration/sqlite/0.3/00__memo_visibility_protected.sql +++ /dev/null @@ -1,43 +0,0 @@ --- change memo visibility field from "PRIVATE"/"PUBLIC" to "PRIVATE"/"PROTECTED"/"PUBLIC". -PRAGMA foreign_keys = off; - -DROP TABLE IF EXISTS _memo_old; - -ALTER TABLE - memo RENAME TO _memo_old; - -CREATE TABLE memo ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - content TEXT NOT NULL DEFAULT '', - visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE', - FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE -); - -INSERT INTO - memo ( - id, - creator_id, - created_ts, - updated_ts, - row_status, - content, - visibility - ) -SELECT - id, - creator_id, - created_ts, - updated_ts, - row_status, - content, - visibility -FROM - _memo_old; - -DROP TABLE IF EXISTS _memo_old; - -PRAGMA foreign_keys = on; \ No newline at end of file diff --git a/store/migration/sqlite/0.30/00__user_tag_setting.sql b/store/migration/sqlite/0.30/00__user_tag_setting.sql deleted file mode 100644 index 01c32aa6e..000000000 --- a/store/migration/sqlite/0.30/00__user_tag_setting.sql +++ /dev/null @@ -1,10 +0,0 @@ -INSERT OR IGNORE INTO user_setting (user_id, key, value) -SELECT - user.id, - 'TAGS', - system_setting.value -FROM user -JOIN system_setting ON system_setting.name = 'TAGS' -WHERE system_setting.value IS NOT NULL - AND system_setting.value != '' - AND system_setting.value != '{}'; diff --git a/store/migration/sqlite/0.31/00__rename_shortcuts_to_memo_views.sql b/store/migration/sqlite/0.31/00__rename_shortcuts_to_memo_views.sql deleted file mode 100644 index c2dde83f3..000000000 --- a/store/migration/sqlite/0.31/00__rename_shortcuts_to_memo_views.sql +++ /dev/null @@ -1,25 +0,0 @@ --- Renames the SHORTCUTS user setting to MEMO_VIEWS, rewriting the stored JSON --- object key from `shortcuts` to `memoViews` to match the renamed proto field. --- --- Rows are skipped rather than failing the migration when either --- * `value` is not valid JSON, which would abort the whole upgrade transaction, or --- * the user already has a MEMO_VIEWS row, which would violate UNIQUE(user_id, key). -UPDATE user_setting -SET - key = 'MEMO_VIEWS', - value = CASE - WHEN json_type(value, '$.shortcuts') IS NOT NULL THEN json_set( - json_remove(value, '$.shortcuts'), - '$.memoViews', - json_extract(value, '$.shortcuts') - ) - ELSE value - END -WHERE key = 'SHORTCUTS' - AND CASE - WHEN json_valid(value) THEN json_type(value) = 'object' - ELSE 0 - END - AND user_id NOT IN ( - SELECT user_id FROM user_setting WHERE key = 'MEMO_VIEWS' - ); diff --git a/store/migration/sqlite/0.31/01__migrate_storage_setting.sql b/store/migration/sqlite/0.31/01__migrate_storage_setting.sql deleted file mode 100644 index f1a4e2430..000000000 --- a/store/migration/sqlite/0.31/01__migrate_storage_setting.sql +++ /dev/null @@ -1,88 +0,0 @@ --- Expands the legacy singleton storage setting into the named storage model. --- Legacy fields remain in place so older clients and rollback versions can --- continue to read the active storage configuration. -UPDATE system_setting -SET value = json_set( - value, - '$.storages', json_array(json_object( - 'id', 'database', - 'name', 'Database', - 'type', 'STORAGE_TYPE_DATABASE' - )), - '$.defaultStorageId', 'database' -) -WHERE name = 'STORAGE' - AND CASE - WHEN json_valid(value) THEN - json_type(value) = 'object' - AND json_type(value, '$.storages') IS NULL - AND json_extract(value, '$.storageType') IN ('DATABASE', 1) - ELSE FALSE - END; - -UPDATE system_setting -SET value = json_set( - value, - '$.storages', json_array(json_object( - 'id', 'local', - 'name', 'Local', - 'type', 'STORAGE_TYPE_LOCAL' - )), - '$.defaultStorageId', 'local' -) -WHERE name = 'STORAGE' - AND CASE - WHEN json_valid(value) THEN - json_type(value) = 'object' - AND json_type(value, '$.storages') IS NULL - AND ( - json_type(value, '$.storageType') IS NULL - OR json_extract(value, '$.storageType') IN ('STORAGE_TYPE_UNSPECIFIED', 'LOCAL', 0, 2) - ) - ELSE FALSE - END; - -UPDATE system_setting -SET value = json_set( - value, - '$.storages', json_array(json_object( - 'id', 's3', - 'name', 'S3', - 'type', 'STORAGE_TYPE_S3', - 's3Config', json_extract(value, '$.s3Config') - )), - '$.defaultStorageId', 's3' -) -WHERE name = 'STORAGE' - AND CASE - WHEN json_valid(value) THEN - json_type(value) = 'object' - AND json_type(value, '$.storages') IS NULL - AND json_extract(value, '$.storageType') IN ('S3', 3) - AND json_type(value, '$.s3Config') = 'object' - ELSE FALSE - END; - --- Attachments created before S3 configs were embedded only stored the object --- key. Bind them to the namespace captured above before that default changes. -UPDATE attachment -SET payload = json_set(payload, '$.s3Object.storageId', 's3') -WHERE storage_type = 'S3' - AND CASE - WHEN json_valid(payload) THEN - json_type(payload) = 'object' - AND json_type(payload, '$.s3Object') = 'object' - AND json_type(payload, '$.s3Object.storageId') IS NULL - AND json_type(payload, '$.s3Object.s3Config') IS NULL - ELSE FALSE - END - AND EXISTS ( - SELECT 1 - FROM system_setting AS storage_setting - WHERE storage_setting.name = 'STORAGE' - AND CASE - WHEN json_valid(storage_setting.value) THEN - json_extract(storage_setting.value, '$.defaultStorageId') = 's3' - ELSE FALSE - END - ); diff --git a/store/migration/sqlite/0.31/02__reaction_memo_id.sql b/store/migration/sqlite/0.31/02__reaction_memo_id.sql deleted file mode 100644 index 2ecfc9018..000000000 --- a/store/migration/sqlite/0.31/02__reaction_memo_id.sql +++ /dev/null @@ -1,35 +0,0 @@ --- Replaces the memo resource name stored in reaction.content_id with the --- memo's stable internal ID. The inner join intentionally drops orphaned --- reactions whose resource name no longer resolves to an existing memo. -CREATE TABLE reaction_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - creator_id INTEGER NOT NULL, - memo_id INTEGER NOT NULL, - reaction_type TEXT NOT NULL, - UNIQUE(creator_id, memo_id, reaction_type) -); - -INSERT INTO reaction_new (id, created_ts, creator_id, memo_id, reaction_type) -SELECT - reaction.id, - reaction.created_ts, - reaction.creator_id, - memo.id, - reaction.reaction_type -FROM reaction -JOIN memo ON reaction.content_id = 'memos/' || memo.uid; - --- Keep IDs issued for deleted or orphaned reactions from being reused. -INSERT INTO sqlite_sequence (name, seq) -SELECT 'reaction_new', seq -FROM sqlite_sequence -WHERE name = 'reaction' - AND NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = 'reaction_new'); - -UPDATE sqlite_sequence -SET seq = MAX(seq, (SELECT seq FROM sqlite_sequence WHERE name = 'reaction')) -WHERE name = 'reaction_new'; - -DROP TABLE reaction; -ALTER TABLE reaction_new RENAME TO reaction; diff --git a/store/migration/sqlite/0.31/03__multi_spaces.sql b/store/migration/sqlite/0.31/03__multi_spaces.sql deleted file mode 100644 index 95f6d4bb3..000000000 --- a/store/migration/sqlite/0.31/03__multi_spaces.sql +++ /dev/null @@ -1,60 +0,0 @@ -CREATE TABLE space ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - uid TEXT NOT NULL UNIQUE, - title TEXT NOT NULL, - description TEXT NOT NULL DEFAULT '' -); - -CREATE TABLE space_member ( - space_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - role TEXT NOT NULL CHECK (role IN ('ADMIN', 'USER')), - PRIMARY KEY (space_id, user_id) -); - --- SQLite requires a table rebuild to extend the visibility CHECK constraint. --- Copy every existing memo value verbatim; placement starts Unassigned. -CREATE TABLE memo_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - uid TEXT NOT NULL UNIQUE, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - content TEXT NOT NULL DEFAULT '', - visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE', 'SPACE')) DEFAULT 'PRIVATE', - pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0, - payload TEXT NOT NULL DEFAULT '{}', - space_id INTEGER DEFAULT NULL -); - -INSERT INTO memo_new ( - id, uid, creator_id, created_ts, updated_ts, row_status, content, - visibility, pinned, payload, space_id -) -SELECT - id, uid, creator_id, created_ts, updated_ts, row_status, content, - visibility, pinned, payload, NULL -FROM memo; - --- Preserve the largest ID ever issued, including IDs belonging to deleted --- memos that were not copied into the rebuilt table. -INSERT INTO sqlite_sequence (name, seq) -SELECT 'memo_new', seq -FROM sqlite_sequence -WHERE name = 'memo' - AND NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = 'memo_new'); - -UPDATE sqlite_sequence -SET seq = MAX(seq, (SELECT seq FROM sqlite_sequence WHERE name = 'memo')) -WHERE name = 'memo_new'; - -DROP TABLE memo; -ALTER TABLE memo_new RENAME TO memo; - --- Recreate the pre-existing index dropped with the rebuilt memo table. -CREATE INDEX idx_memo_creator_id ON memo(creator_id); -CREATE INDEX idx_space_member_user_id ON space_member(user_id, space_id); -CREATE INDEX idx_memo_space_id ON memo(space_id, row_status, created_ts DESC, id DESC); -CREATE INDEX idx_memo_relation_related_type_memo - ON memo_relation(related_memo_id, type, memo_id); diff --git a/store/migration/sqlite/0.31/04__space_member_status.sql b/store/migration/sqlite/0.31/04__space_member_status.sql deleted file mode 100644 index f81d30224..000000000 --- a/store/migration/sqlite/0.31/04__space_member_status.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE space_member_new ( - space_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - status TEXT NOT NULL, - role TEXT NOT NULL CHECK (role IN ('ADMIN', 'USER')), - PRIMARY KEY (space_id, user_id) -); - -INSERT INTO space_member_new (space_id, user_id, status, role) -SELECT space_id, user_id, 'ACTIVE', role -FROM space_member; - -DROP TABLE space_member; -ALTER TABLE space_member_new RENAME TO space_member; - -CREATE INDEX idx_space_member_user_id ON space_member(user_id, space_id); diff --git a/store/migration/sqlite/0.31/06__space_payload.sql b/store/migration/sqlite/0.31/06__space_payload.sql deleted file mode 100644 index 825efe828..000000000 --- a/store/migration/sqlite/0.31/06__space_payload.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE space ADD COLUMN payload TEXT NOT NULL DEFAULT '{}'; diff --git a/store/migration/sqlite/0.31/07__unique_email.sql b/store/migration/sqlite/0.31/07__unique_email.sql deleted file mode 100644 index 566d1a16d..000000000 --- a/store/migration/sqlite/0.31/07__unique_email.sql +++ /dev/null @@ -1,59 +0,0 @@ --- Make user.email an optional, canonical, instance-unique attribute. --- Data repair runs against the old table first, then the table is rebuilt --- because SQLite cannot change a column's nullability in place. - --- Canonical form: trimmed and lowercased. SQLite's LOWER folds ASCII only; --- the migrator canonicalizes with Unicode rules before this file runs, so --- this statement is a safety net for the ASCII case. -UPDATE user SET email = LOWER(TRIM(email)); - --- Values without an '@', or carrying display-name syntax or interior --- whitespace, are not addresses the API would accept. -UPDATE user SET email = '' -WHERE email NOT LIKE '%@%' OR email LIKE '%<%' OR email LIKE '%>%' OR email LIKE '% %'; - --- For each address held by more than one account, the oldest account keeps it. -UPDATE user -SET email = '' -WHERE email <> '' - AND id NOT IN (SELECT MIN(id) FROM user WHERE email <> '' GROUP BY email); - -CREATE TABLE user_new ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - username TEXT COLLATE BINARY NOT NULL UNIQUE, - role TEXT NOT NULL DEFAULT 'USER', - email TEXT COLLATE BINARY DEFAULT NULL, - nickname TEXT NOT NULL DEFAULT '', - password_hash TEXT NOT NULL, - avatar_url TEXT NOT NULL DEFAULT '', - description TEXT NOT NULL DEFAULT '' -); - -INSERT INTO user_new ( - id, created_ts, updated_ts, row_status, username, role, email, - nickname, password_hash, avatar_url, description -) -SELECT - id, created_ts, updated_ts, row_status, username, role, NULLIF(email, ''), - nickname, password_hash, avatar_url, description -FROM user; - --- Preserve the largest ID ever issued, including IDs belonging to deleted --- users that were not copied into the rebuilt table. -INSERT INTO sqlite_sequence (name, seq) -SELECT 'user_new', seq -FROM sqlite_sequence -WHERE name = 'user' - AND NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = 'user_new'); - -UPDATE sqlite_sequence -SET seq = MAX(seq, (SELECT seq FROM sqlite_sequence WHERE name = 'user')) -WHERE name = 'user_new'; - -DROP TABLE user; -ALTER TABLE user_new RENAME TO user; - -CREATE UNIQUE INDEX IF NOT EXISTS idx_user_email ON user(email); diff --git a/store/migration/sqlite/0.4/00__user_setting.sql b/store/migration/sqlite/0.4/00__user_setting.sql deleted file mode 100644 index 1f9e54c25..000000000 --- a/store/migration/sqlite/0.4/00__user_setting.sql +++ /dev/null @@ -1,9 +0,0 @@ --- user_setting -CREATE TABLE user_setting ( - user_id INTEGER NOT NULL, - key TEXT NOT NULL, - value TEXT NOT NULL, - FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE -); - -CREATE UNIQUE INDEX user_setting_key_user_id_index ON user_setting(key, user_id); \ No newline at end of file diff --git a/store/migration/sqlite/0.5/00__regenerate_foreign_keys.sql b/store/migration/sqlite/0.5/00__regenerate_foreign_keys.sql deleted file mode 100644 index 00ed430a0..000000000 --- a/store/migration/sqlite/0.5/00__regenerate_foreign_keys.sql +++ /dev/null @@ -1,217 +0,0 @@ -PRAGMA foreign_keys = off; - -DROP TABLE IF EXISTS _user_old; - -ALTER TABLE - user RENAME TO _user_old; - --- user -CREATE TABLE user ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - email TEXT NOT NULL UNIQUE, - role TEXT NOT NULL CHECK (role IN ('HOST', 'USER')) DEFAULT 'USER', - name TEXT NOT NULL, - password_hash TEXT NOT NULL, - open_id TEXT NOT NULL UNIQUE -); - -INSERT INTO - user -SELECT - * -FROM - _user_old; - -DROP TABLE IF EXISTS _user_old; - -DROP TRIGGER IF EXISTS `trigger_update_user_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_user_modification_time` -AFTER -UPDATE - ON `user` FOR EACH ROW BEGIN -UPDATE - `user` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; - -DROP TABLE IF EXISTS _memo_old; - -ALTER TABLE - memo RENAME TO _memo_old; - --- memo -CREATE TABLE memo ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - content TEXT NOT NULL DEFAULT '', - visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE', - FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE -); - -INSERT INTO - memo -SELECT - * -FROM - _memo_old; - -DROP TABLE IF EXISTS _memo_old; - -DROP TRIGGER IF EXISTS `trigger_update_memo_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_memo_modification_time` -AFTER -UPDATE - ON `memo` FOR EACH ROW BEGIN -UPDATE - `memo` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; - -DROP TABLE IF EXISTS _memo_organizer_old; - -ALTER TABLE - memo_organizer RENAME TO _memo_organizer_old; - --- memo_organizer -CREATE TABLE memo_organizer ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - memo_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0, - FOREIGN KEY(memo_id) REFERENCES memo(id) ON DELETE CASCADE, - FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE, - UNIQUE(memo_id, user_id) -); - -INSERT INTO - memo_organizer -SELECT - * -FROM - _memo_organizer_old; - -DROP TABLE IF EXISTS _memo_organizer_old; - -DROP TABLE IF EXISTS _shortcut_old; - -ALTER TABLE - shortcut RENAME TO _shortcut_old; - --- shortcut -CREATE TABLE shortcut ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - title TEXT NOT NULL DEFAULT '', - payload TEXT NOT NULL DEFAULT '{}', - FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE -); - -INSERT INTO - shortcut -SELECT - * -FROM - _shortcut_old; - -DROP TABLE IF EXISTS _shortcut_old; - -DROP TRIGGER IF EXISTS `trigger_update_shortcut_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_shortcut_modification_time` -AFTER -UPDATE - ON `shortcut` FOR EACH ROW BEGIN -UPDATE - `shortcut` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; - -DROP TABLE IF EXISTS _resource_old; - -ALTER TABLE - resource RENAME TO _resource_old; - --- resource -CREATE TABLE resource ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - filename TEXT NOT NULL DEFAULT '', - blob BLOB DEFAULT NULL, - type TEXT NOT NULL DEFAULT '', - size INTEGER NOT NULL DEFAULT 0, - FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE -); - -INSERT INTO - resource -SELECT - * -FROM - _resource_old; - -DROP TABLE IF EXISTS _resource_old; - -DROP TRIGGER IF EXISTS `trigger_update_resource_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_resource_modification_time` -AFTER -UPDATE - ON `resource` FOR EACH ROW BEGIN -UPDATE - `resource` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; - -DROP TABLE IF EXISTS _user_setting_old; - -ALTER TABLE - user_setting RENAME TO _user_setting_old; - --- user_setting -CREATE TABLE user_setting ( - user_id INTEGER NOT NULL, - key TEXT NOT NULL, - value TEXT NOT NULL, - FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE, - UNIQUE(user_id, key) -); - -INSERT INTO - user_setting -SELECT - * -FROM - _user_setting_old; - -DROP TABLE IF EXISTS _user_setting_old; - -PRAGMA foreign_keys = on; \ No newline at end of file diff --git a/store/migration/sqlite/0.5/01__memo_resource.sql b/store/migration/sqlite/0.5/01__memo_resource.sql deleted file mode 100644 index 0a798ae8c..000000000 --- a/store/migration/sqlite/0.5/01__memo_resource.sql +++ /dev/null @@ -1,10 +0,0 @@ --- memo_resource -CREATE TABLE memo_resource ( - memo_id INTEGER NOT NULL, - resource_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - FOREIGN KEY(memo_id) REFERENCES memo(id) ON DELETE CASCADE, - FOREIGN KEY(resource_id) REFERENCES resource(id) ON DELETE CASCADE, - UNIQUE(memo_id, resource_id) -); \ No newline at end of file diff --git a/store/migration/sqlite/0.5/02__system_setting.sql b/store/migration/sqlite/0.5/02__system_setting.sql deleted file mode 100644 index 90879098e..000000000 --- a/store/migration/sqlite/0.5/02__system_setting.sql +++ /dev/null @@ -1,7 +0,0 @@ --- system_setting -CREATE TABLE system_setting ( - name TEXT NOT NULL, - value TEXT NOT NULL, - description TEXT NOT NULL DEFAULT '', - UNIQUE(name) -); \ No newline at end of file diff --git a/store/migration/sqlite/0.5/03__resource_extermal_link.sql b/store/migration/sqlite/0.5/03__resource_extermal_link.sql deleted file mode 100644 index b346bdac8..000000000 --- a/store/migration/sqlite/0.5/03__resource_extermal_link.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE - resource -ADD - COLUMN external_link TEXT NOT NULL DEFAULT ''; \ No newline at end of file diff --git a/store/migration/sqlite/0.6/00__recreate_triggers.sql b/store/migration/sqlite/0.6/00__recreate_triggers.sql deleted file mode 100644 index 4f1f1dcf1..000000000 --- a/store/migration/sqlite/0.6/00__recreate_triggers.sql +++ /dev/null @@ -1,59 +0,0 @@ -DROP TRIGGER IF EXISTS `trigger_update_user_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_user_modification_time` -AFTER -UPDATE - ON `user` FOR EACH ROW BEGIN -UPDATE - `user` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; - -DROP TRIGGER IF EXISTS `trigger_update_memo_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_memo_modification_time` -AFTER -UPDATE - ON `memo` FOR EACH ROW BEGIN -UPDATE - `memo` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; - -DROP TRIGGER IF EXISTS `trigger_update_shortcut_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_shortcut_modification_time` -AFTER -UPDATE - ON `shortcut` FOR EACH ROW BEGIN -UPDATE - `shortcut` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; - -DROP TRIGGER IF EXISTS `trigger_update_resource_modification_time`; - -CREATE TRIGGER IF NOT EXISTS `trigger_update_resource_modification_time` -AFTER -UPDATE - ON `resource` FOR EACH ROW BEGIN -UPDATE - `resource` -SET - updated_ts = (strftime('%s', 'now')) -WHERE - rowid = old.rowid; - -END; \ No newline at end of file diff --git a/store/migration/sqlite/0.7/00__remove_fk.sql b/store/migration/sqlite/0.7/00__remove_fk.sql deleted file mode 100644 index 84d4112a0..000000000 --- a/store/migration/sqlite/0.7/00__remove_fk.sql +++ /dev/null @@ -1,191 +0,0 @@ -PRAGMA foreign_keys = off; - -DROP TABLE IF EXISTS _user_old; - -ALTER TABLE - user RENAME TO _user_old; - --- user -CREATE TABLE user ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - email TEXT NOT NULL UNIQUE, - role TEXT NOT NULL CHECK (role IN ('HOST', 'USER')) DEFAULT 'USER', - name TEXT NOT NULL, - password_hash TEXT NOT NULL, - open_id TEXT NOT NULL UNIQUE -); - -INSERT INTO - user -SELECT - * -FROM - _user_old; - -DROP TABLE IF EXISTS _user_old; - -DROP TABLE IF EXISTS _memo_old; - -ALTER TABLE - memo RENAME TO _memo_old; - --- memo -CREATE TABLE memo ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - content TEXT NOT NULL DEFAULT '', - visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE' -); - -INSERT INTO - memo -SELECT - * -FROM - _memo_old; - -DROP TABLE IF EXISTS _memo_old; - -DROP TABLE IF EXISTS _memo_organizer_old; - -ALTER TABLE - memo_organizer RENAME TO _memo_organizer_old; - --- memo_organizer -CREATE TABLE memo_organizer ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - memo_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0, - UNIQUE(memo_id, user_id) -); - -INSERT INTO - memo_organizer -SELECT - * -FROM - _memo_organizer_old; - -DROP TABLE IF EXISTS _memo_organizer_old; - -DROP TABLE IF EXISTS _shortcut_old; - -ALTER TABLE - shortcut RENAME TO _shortcut_old; - --- shortcut -CREATE TABLE shortcut ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - title TEXT NOT NULL DEFAULT '', - payload TEXT NOT NULL DEFAULT '{}' -); - -INSERT INTO - shortcut -SELECT - * -FROM - _shortcut_old; - -DROP TABLE IF EXISTS _shortcut_old; - -DROP TABLE IF EXISTS _resource_old; - -ALTER TABLE - resource RENAME TO _resource_old; - --- resource -CREATE TABLE resource ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - filename TEXT NOT NULL DEFAULT '', - blob BLOB DEFAULT NULL, - external_link TEXT NOT NULL DEFAULT '', - type TEXT NOT NULL DEFAULT '', - size INTEGER NOT NULL DEFAULT 0 -); - -INSERT INTO - resource ( - id, - creator_id, - created_ts, - updated_ts, - filename, - blob, - external_link, - type, - size - ) -SELECT - id, - creator_id, - created_ts, - updated_ts, - filename, - blob, - external_link, - type, - size -FROM - _resource_old; - -DROP TABLE IF EXISTS _resource_old; - -DROP TABLE IF EXISTS _user_setting_old; - -ALTER TABLE - user_setting RENAME TO _user_setting_old; - --- user_setting -CREATE TABLE user_setting ( - user_id INTEGER NOT NULL, - key TEXT NOT NULL, - value TEXT NOT NULL, - UNIQUE(user_id, key) -); - -INSERT INTO - user_setting -SELECT - * -FROM - _user_setting_old; - -DROP TABLE IF EXISTS _user_setting_old; - -DROP TABLE IF EXISTS _memo_resource_old; - -ALTER TABLE - memo_resource RENAME TO _memo_resource_old; - --- memo_resource -CREATE TABLE memo_resource ( - memo_id INTEGER NOT NULL, - resource_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - UNIQUE(memo_id, resource_id) -); - -INSERT INTO - memo_resource -SELECT - * -FROM - _memo_resource_old; - -DROP TABLE IF EXISTS _memo_resource_old; \ No newline at end of file diff --git a/store/migration/sqlite/0.7/01__remove_triggers.sql b/store/migration/sqlite/0.7/01__remove_triggers.sql deleted file mode 100644 index 7f04c82ef..000000000 --- a/store/migration/sqlite/0.7/01__remove_triggers.sql +++ /dev/null @@ -1,7 +0,0 @@ -DROP TRIGGER IF EXISTS `trigger_update_user_modification_time`; - -DROP TRIGGER IF EXISTS `trigger_update_memo_modification_time`; - -DROP TRIGGER IF EXISTS `trigger_update_shortcut_modification_time`; - -DROP TRIGGER IF EXISTS `trigger_update_resource_modification_time`; \ No newline at end of file diff --git a/store/migration/sqlite/0.8/00__migration_history.sql b/store/migration/sqlite/0.8/00__migration_history.sql deleted file mode 100644 index 961234465..000000000 --- a/store/migration/sqlite/0.8/00__migration_history.sql +++ /dev/null @@ -1,5 +0,0 @@ --- migration_history -CREATE TABLE IF NOT EXISTS migration_history ( - version TEXT NOT NULL PRIMARY KEY, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')) -); \ No newline at end of file diff --git a/store/migration/sqlite/0.8/01__user_username.sql b/store/migration/sqlite/0.8/01__user_username.sql deleted file mode 100644 index 273ffe6b4..000000000 --- a/store/migration/sqlite/0.8/01__user_username.sql +++ /dev/null @@ -1,50 +0,0 @@ --- add column username TEXT NOT NULL UNIQUE --- rename column name to nickname --- add role `ADMIN` -DROP TABLE IF EXISTS _user_old; - -ALTER TABLE - user RENAME TO _user_old; - --- user -CREATE TABLE user ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - username TEXT NOT NULL UNIQUE, - role TEXT NOT NULL CHECK (role IN ('HOST', 'ADMIN', 'USER')) DEFAULT 'USER', - email TEXT NOT NULL DEFAULT '', - nickname TEXT NOT NULL DEFAULT '', - password_hash TEXT NOT NULL, - open_id TEXT NOT NULL UNIQUE -); - -INSERT INTO - user ( - id, - created_ts, - updated_ts, - row_status, - username, - role, - email, - nickname, - password_hash, - open_id - ) -SELECT - id, - created_ts, - updated_ts, - row_status, - email, - role, - email, - name, - password_hash, - open_id -FROM - _user_old; - -DROP TABLE IF EXISTS _user_old; \ No newline at end of file diff --git a/store/migration/sqlite/0.9/00__tag.sql b/store/migration/sqlite/0.9/00__tag.sql deleted file mode 100644 index 89802d46a..000000000 --- a/store/migration/sqlite/0.9/00__tag.sql +++ /dev/null @@ -1,6 +0,0 @@ --- tag -CREATE TABLE tag ( - name TEXT NOT NULL, - creator_id INTEGER NOT NULL, - UNIQUE(name, creator_id) -); \ No newline at end of file diff --git a/store/migrator.go b/store/migrator.go index 9cb3b7141..1cc643159 100644 --- a/store/migrator.go +++ b/store/migrator.go @@ -7,7 +7,6 @@ import ( "fmt" "io/fs" "log/slog" - "path/filepath" "slices" "strconv" "strings" @@ -15,7 +14,6 @@ import ( "github.com/pkg/errors" "google.golang.org/protobuf/encoding/protojson" - "github.com/usememos/memos/internal/version" storepb "github.com/usememos/memos/proto/gen/store" ) @@ -26,20 +24,22 @@ import ( // // Migration Flow: // 1. preMigrate: Check if DB is initialized. If not, apply LATEST.sql -// 2. checkMinimumUpgradeVersion: Verify installation can be upgraded (reject pre-0.22 installations) +// 2. checkMinimumUpgradeVersion: Verify the database meets the fixed v0.31.0 baseline // 3. Migrate (prod mode): Apply incremental migrations from current to target version // 4. Migrate (demo mode): Seed database with demo data // Deployment configuration is loaded separately after migration completes. // // Version Tracking: // - New installations: Schema version set in system_setting immediately -// - Existing v0.22+ installations: Schema version tracked in system_setting -// - Pre-v0.22 installations: Must upgrade to v0.25.x first (migration_history → system_setting migration) +// - Existing installations: Must have schema 0.31.8 or newer +// - Older installations: Must upgrade through v0.31.0 before running this binary // // Migration Files: // - Location: store/migration/{driver}/{version}/NN__description.sql -// - Naming: NN is zero-padded patch number, description is human-readable -// - Ordering: Files sorted lexicographically and applied in order +// - Naming: NN is a zero-based migration sequence, description is human-readable +// - Ordering: Calendar year, month, and migration sequence are compared numerically +// - Every driver ships the same set of migration versions; a schema change is +// one file per driver under the same YY.MM/NN // - LATEST.sql: Full schema for new installations (faster than incremental migrations) //go:embed migration @@ -49,8 +49,8 @@ var migrationFS embed.FS var seedFS embed.FS const ( - // MigrateFileNameSplit is the split character between the patch version and the description in the migration file name. - // For example, "1__create_table.sql". + // MigrateFileNameSplit separates the migration sequence from the description in the migration file name. + // For example, "00__create_table.sql". MigrateFileNameSplit = "__" // LatestSchemaFileName is the name of the latest schema file. // This file is used to initialize fresh installations with the current schema. @@ -59,39 +59,36 @@ const ( // defaultSchemaVersion is used when schema version is empty or not set. // This handles edge cases for old installations without version tracking. defaultSchemaVersion = "0.0.0" + + // baselineSchemaVersion is the schema shipped by v0.31.0. Historical migrations + // were removed at this boundary; this minimum must not advance with releases. + baselineSchemaVersion = "0.31.8" ) -// getSchemaVersionOrDefault returns the schema version or default if empty. -// This ensures safe version comparisons and handles old installations. -func getSchemaVersionOrDefault(schemaVersion string) string { - if schemaVersion == "" { - return defaultSchemaVersion - } - return schemaVersion +// migrationFile is one embedded migration script with its schema version parsed once. +type migrationFile struct { + path string + version string + parsed [3]int } -// isVersionEmpty checks if the schema version is empty or the default value. +// isVersionEmpty identifies legacy databases without schema tracking. func isVersionEmpty(schemaVersion string) bool { return schemaVersion == "" || schemaVersion == defaultSchemaVersion } -// shouldApplyMigration determines if a migration file should be applied. -// It checks if the file's version is between the current DB version and target version. -func shouldApplyMigration(fileVersion, currentDBVersion, targetVersion string) bool { - currentDBVersionSafe := getSchemaVersionOrDefault(currentDBVersion) - return version.IsVersionGreaterThan(fileVersion, currentDBVersionSafe) && - version.IsVersionGreaterOrEqualThan(targetVersion, fileVersion) +// shouldApplyMigration reports whether a file version lies after the current +// database version and at or before the target version. +func shouldApplyMigration(fileVersion, currentDBVersion, targetVersion [3]int) bool { + return compareParsedSchemaVersions(fileVersion, currentDBVersion) > 0 && + compareParsedSchemaVersions(fileVersion, targetVersion) <= 0 } // validateMigrationFileName checks if a migration file follows the expected naming convention. // Expected format: "NN__description.sql" where NN is a zero-padded number. func validateMigrationFileName(filename string) error { - parts := strings.SplitN(filename, MigrateFileNameSplit, 2) - if len(parts) < 2 { - return errors.Errorf("invalid migration filename format (missing %s): %s", MigrateFileNameSplit, filename) - } - if _, err := strconv.Atoi(parts[0]); err != nil { - return errors.Errorf("migration filename must start with a number: %s", filename) + if !migrationFilePattern.MatchString(filename) { + return errors.Errorf("invalid migration filename %q; expected NN__description.sql", filename) } return nil } @@ -112,8 +109,11 @@ func (s *Store) Migrate(ctx context.Context) error { if err != nil { return errors.Wrap(err, "failed to get current schema version") } - // Check for downgrade (but skip if schema version is empty - that means fresh/old installation) - if !isVersionEmpty(instanceBasicSetting.SchemaVersion) && version.IsVersionGreaterThan(instanceBasicSetting.SchemaVersion, currentSchemaVersion) { + order, err := compareSchemaVersions(instanceBasicSetting.SchemaVersion, currentSchemaVersion) + if err != nil { + return err + } + if order > 0 { slog.Error("cannot downgrade schema version", slog.String("databaseVersion", instanceBasicSetting.SchemaVersion), slog.String("currentVersion", currentSchemaVersion), @@ -121,8 +121,7 @@ func (s *Store) Migrate(ctx context.Context) error { return errors.Errorf("cannot downgrade schema version from %s to %s", instanceBasicSetting.SchemaVersion, currentSchemaVersion) } // Apply migrations if needed. - if isVersionEmpty(instanceBasicSetting.SchemaVersion) || version.IsVersionGreaterThan(currentSchemaVersion, instanceBasicSetting.SchemaVersion) { - s.prepareUniqueEmailMigration(ctx, instanceBasicSetting.SchemaVersion, currentSchemaVersion) + if order < 0 { if err := s.applyMigrations(ctx, instanceBasicSetting.SchemaVersion, currentSchemaVersion); err != nil { return errors.Wrap(err, "failed to apply migrations") } @@ -165,11 +164,18 @@ func (s *Store) initializeInstanceAccessSetting(ctx context.Context) error { // applyMigrations applies all necessary migration files between current and target schema versions. // It runs all migrations in a single transaction for atomicity. func (s *Store) applyMigrations(ctx context.Context, currentSchemaVersion, targetSchemaVersion string) error { - filePaths, err := fs.Glob(migrationFS, fmt.Sprintf("%s*/*.sql", s.getMigrationBasePath())) + current, err := parseSchemaVersion(currentSchemaVersion) if err != nil { - return errors.Wrap(err, "failed to read migration files") + return err + } + target, err := parseSchemaVersion(targetSchemaVersion) + if err != nil { + return err + } + files, err := s.listMigrationFiles() + if err != nil { + return err } - slices.Sort(filePaths) // Start a transaction to apply migrations atomically tx, err := s.driver.GetDB().Begin() @@ -178,46 +184,29 @@ func (s *Store) applyMigrations(ctx context.Context, currentSchemaVersion, targe } defer tx.Rollback() - // Use safe version for comparison (handles empty version case) - schemaVersionForComparison := getSchemaVersionOrDefault(currentSchemaVersion) - if isVersionEmpty(currentSchemaVersion) { - slog.Warn("schema version is empty, treating as default for migration comparison", - slog.String("defaultVersion", defaultSchemaVersion)) - } - slog.Info("start migration", - slog.String("currentSchemaVersion", schemaVersionForComparison), + slog.String("currentSchemaVersion", currentSchemaVersion), slog.String("targetSchemaVersion", targetSchemaVersion)) migrationsApplied := 0 - for _, filePath := range filePaths { - fileSchemaVersion, err := s.getSchemaVersionOfMigrateScript(filePath) + for _, file := range files { + if !shouldApplyMigration(file.parsed, current, target) { + continue + } + slog.Info("applying migration", + slog.String("file", file.path), + slog.String("version", file.version)) + + bytes, err := migrationFS.ReadFile(file.path) if err != nil { - return errors.Wrap(err, "failed to get schema version of migrate script") + return errors.Wrapf(err, "failed to read migration file: %s", file.path) } - if shouldApplyMigration(fileSchemaVersion, currentSchemaVersion, targetSchemaVersion) { - // Validate migration filename before applying - filename := filepath.Base(filePath) - if err := validateMigrationFileName(filename); err != nil { - slog.Warn("migration file has invalid name but will be applied", slog.String("file", filePath), slog.String("error", err.Error())) - } - - slog.Info("applying migration", - slog.String("file", filePath), - slog.String("version", fileSchemaVersion)) - - bytes, err := migrationFS.ReadFile(filePath) - if err != nil { - return errors.Wrapf(err, "failed to read migration file: %s", filePath) - } - - stmt := string(bytes) - if err := s.execute(ctx, tx, stmt); err != nil { - return errors.Wrapf(err, "failed to execute migration %s: %s", filePath, err) - } - migrationsApplied++ + stmt := string(bytes) + if err := s.execute(ctx, tx, stmt); err != nil { + return errors.Wrapf(err, "failed to execute migration %s: %s", file.path, err) } + migrationsApplied++ } if err := tx.Commit(); err != nil { @@ -323,60 +312,88 @@ func (s *Store) seed(ctx context.Context) error { } // GetCurrentSchemaVersion returns the latest schema version available for the configured database driver. +// With no incremental migrations, it returns the fixed v0.31.0 baseline. // -// A driver introduced after the last schema change ships only LATEST.sql and -// no versioned migration files. LATEST.sql describes the same schema on every -// driver, so such a driver reports the highest version any driver's migration -// directory defines and picks up future migrations from there. +// Only this driver's migration files count. Every driver must ship the same +// migration versions (TestMigrationVersionsMatchAcrossDrivers enforces this), +// so a driver never records a version whose SQL it has not executed. func (s *Store) GetCurrentSchemaVersion() (string, error) { - filePaths, err := fs.Glob(migrationFS, fmt.Sprintf("%s*/*.sql", s.getMigrationBasePath())) + files, err := s.listMigrationFiles() if err != nil { - return "", errors.Wrap(err, "failed to read migration files") + return "", err } - if len(filePaths) == 0 { - filePaths, err = fs.Glob(migrationFS, "migration/*/*/*.sql") - if err != nil { - return "", errors.Wrap(err, "failed to read migration files") - } + if len(files) == 0 { + return baselineSchemaVersion, nil } - if len(filePaths) == 0 { - return defaultSchemaVersion, nil + latest := files[len(files)-1] + if compareParsedSchemaVersions(latest.parsed, mustParseSchemaVersion(baselineSchemaVersion)) < 0 { + return baselineSchemaVersion, nil } + return latest.version, nil +} - currentSchemaVersion := defaultSchemaVersion - for _, filePath := range filePaths { - fileSchemaVersion, err := s.getSchemaVersionOfMigrateScript(filePath) - if err != nil { - return "", errors.Wrap(err, "failed to get schema version of migrate script") - } - if version.IsVersionGreaterThan(fileSchemaVersion, currentSchemaVersion) { - currentSchemaVersion = fileSchemaVersion - } +// listMigrationFiles returns this driver's migration scripts in application +// order. Every filename is validated and every version parsed before any SQL +// runs, sequences are ordered numerically (including months with more than +// 100 migrations), and two files that resolve to the same version are rejected +// because their relative order would be undefined. +func (s *Store) listMigrationFiles() ([]migrationFile, error) { + return listMigrationFilesFrom(migrationFS, s.getMigrationBasePath()) +} + +func listMigrationFilesFrom(fsys fs.FS, basePath string) ([]migrationFile, error) { + paths, err := fs.Glob(fsys, basePath+"*/*.sql") + if err != nil { + return nil, errors.Wrap(err, "failed to read migration files") } - return currentSchemaVersion, nil + files := make([]migrationFile, 0, len(paths)) + seen := make(map[string]string, len(paths)) + for _, path := range paths { + version, err := getSchemaVersionOfMigrateScript(path) + if err != nil { + return nil, errors.Wrap(err, "failed to get schema version of migrate script") + } + if previous, exists := seen[version]; exists { + return nil, errors.Errorf("migration files %s and %s both resolve to schema version %s", previous, path, version) + } + seen[version] = path + files = append(files, migrationFile{path: path, version: version, parsed: mustParseSchemaVersion(version)}) + } + slices.SortFunc(files, func(a, b migrationFile) int { + return compareParsedSchemaVersions(a.parsed, b.parsed) + }) + return files, nil } // getSchemaVersionOfMigrateScript extracts the schema version from the migration script file path. -// It returns the schema version in the format "major.minor.patch". -// If the file is the latest schema file, it returns the current schema version. -func (s *Store) getSchemaVersionOfMigrateScript(filePath string) (string, error) { - // If the file is the latest schema file, return the current schema version. - if strings.HasSuffix(filePath, LatestSchemaFileName) { - return s.GetCurrentSchemaVersion() - } - - normalizedPath := filepath.ToSlash(filePath) - elements := strings.Split(normalizedPath, "/") +// Calendar directory YY.MM and file NN__description.sql produce YY.M.(NN+1). +func getSchemaVersionOfMigrateScript(filePath string) (string, error) { + elements := strings.Split(filePath, "/") if len(elements) < 2 { return "", errors.Errorf("invalid file path: %s", filePath) } - minorVersion := elements[len(elements)-2] - rawPatchVersion := strings.Split(elements[len(elements)-1], MigrateFileNameSplit)[0] - patchVersion, err := strconv.Atoi(rawPatchVersion) - if err != nil { - return "", errors.Wrapf(err, "failed to convert patch version to int: %s", rawPatchVersion) + if err := validateMigrationFileName(elements[len(elements)-1]); err != nil { + return "", err } - return fmt.Sprintf("%s.%d", minorVersion, patchVersion+1), nil + series := elements[len(elements)-2] + rawSequence := strings.Split(elements[len(elements)-1], MigrateFileNameSplit)[0] + sequence, err := strconv.Atoi(rawSequence) + if err != nil { + return "", errors.Wrapf(err, "failed to convert migration sequence to int: %s", rawSequence) + } + if !calendarMigrationSeriesPattern.MatchString(series) { + return "", errors.Errorf("invalid migration series %q; expected YY.MM", series) + } + yearMonth := strings.Split(series, ".") + month, err := strconv.Atoi(yearMonth[1]) + if err != nil { + return "", errors.Wrap(err, "invalid migration month") + } + schema := fmt.Sprintf("%s.%d.%d", yearMonth[0], month, sequence+1) + if _, err := parseSchemaVersion(schema); err != nil { + return "", err + } + return schema, nil } // execute executes a SQL statement within a transaction context. @@ -405,47 +422,39 @@ func (s *Store) updateCurrentSchemaVersion(ctx context.Context, schemaVersion st return nil } -// checkMinimumUpgradeVersion verifies the installation meets minimum version requirements for upgrade. -// For very old installations (< v0.22.0), users must upgrade to v0.25.x first before upgrading to current version. -// This is necessary because schema version tracking was moved from migration_history to system_setting in v0.22.0. +// checkMinimumUpgradeVersion rejects databases whose migration history is no longer shipped. +// Fresh installations already have their schema version set by preMigrate. func (s *Store) checkMinimumUpgradeVersion(ctx context.Context) error { instanceBasicSetting, err := s.GetInstanceBasicSetting(ctx) if err != nil { - return errors.Wrap(err, "failed to get instance basic setting") + return errors.Wrap(err, "failed to read database schema version") } schemaVersion := instanceBasicSetting.SchemaVersion - - // Modern installation: nothing to check. - if !isVersionEmpty(schemaVersion) && version.IsVersionGreaterOrEqualThan(schemaVersion, "0.22.0") { - return nil - } - - // Schema version is empty for fresh installs too, but preMigrate sets it before we get here. - // So empty schema version on an initialized DB means a pre-v0.22 legacy installation. - if isVersionEmpty(schemaVersion) { - initialized, err := s.driver.IsInitialized(ctx) + if !isVersionEmpty(schemaVersion) { + order, err := compareSchemaVersions(schemaVersion, baselineSchemaVersion) if err != nil { - return errors.Wrap(err, "failed to check if database is initialized") + return err } - if !initialized { + if order >= 0 { return nil } } - // schemaVersion is either set but < 0.22.0, or empty on an initialized (legacy) DB. - currentVersion, _ := s.GetCurrentSchemaVersion() + upgradePath := "First upgrade to v0.31.0: https://github.com/usememos/memos/releases/tag/v0.31.0" + legacyOrder := -1 + if !isVersionEmpty(schemaVersion) { + legacyOrder, err = compareSchemaVersions(schemaVersion, "0.22.0") + if err != nil { + return err + } + } + if legacyOrder < 0 { + upgradePath = "First upgrade to v0.25.3: https://github.com/usememos/memos/releases/tag/v0.25.3\n" + + "Start the server and verify it works, then upgrade to v0.31.0: https://github.com/usememos/memos/releases/tag/v0.31.0" + } return errors.Errorf( - "Your Memos installation is too old to upgrade directly.\n\n"+ - "Your current version: %s\n"+ - "Target version: %s\n"+ - "Minimum required: v0.22.0 (May 2024)\n\n"+ - "Upgrade path:\n"+ - "1. First upgrade to v0.25.3: https://github.com/usememos/memos/releases/tag/v0.25.3\n"+ - "2. Start the server and verify it works\n"+ - "3. Then upgrade to the latest version\n\n"+ - "This is required because schema version tracking was moved from migration_history\n"+ - "to system_setting in v0.22.0. The intermediate upgrade handles this migration safely.", - schemaVersion, - currentVersion, + "database schema %q is too old to upgrade directly; minimum supported schema is %s.\n"+ + "%s\nStart v0.31.0 and verify it works before upgrading to this version.", + schemaVersion, baselineSchemaVersion, upgradePath, ) } diff --git a/store/migrator_email.go b/store/migrator_email.go deleted file mode 100644 index be6c939b7..000000000 --- a/store/migrator_email.go +++ /dev/null @@ -1,169 +0,0 @@ -package store - -import ( - "context" - "log/slog" - "strings" -) - -// uniqueEmailSchemaVersion is the schema version introduced by -// migration/{driver}/0.31/07__unique_email.sql; the migrator numbers a file -// as its patch number plus one. -const uniqueEmailSchemaVersion = "0.31.8" - -// prepareUniqueEmailMigration runs before the unique-email migration and does -// two things the SQL file cannot do on its own. -// -// First, it rewrites every stored address into the canonical form used by -// store.NormalizeEmail: trimmed and lowercased with Unicode rules. SQLite's -// LOWER folds ASCII only, and PostgreSQL does the same under a C locale, so -// without this pass "Ä@example.com" and "ä@example.com" could both survive -// the migration's deduplication and the unique index would then permit a -// canonical collision. The rewrite is idempotent and touches only rows whose -// stored value differs from its canonical form. -// -// Second, it logs which accounts the migration will change. The migration -// itself is plain SQL and cannot log, and an operator whose second account -// silently loses its address would otherwise have no way to find out. The -// rules mirror the migration exactly: values that do not look like an address -// are cleared, and within a duplicate group the lowest id keeps the address. -// Addresses themselves are not logged; usernames are enough for the operator -// to find the affected accounts. -// -// Neither step blocks the migration; a failure is logged and ignored. -func (s *Store) prepareUniqueEmailMigration(ctx context.Context, currentSchemaVersion, targetSchemaVersion string) { - if !shouldApplyMigration(uniqueEmailSchemaVersion, currentSchemaVersion, targetSchemaVersion) { - return - } - - accounts, err := s.loadLegacyEmailAccounts(ctx) - if err != nil { - slog.Warn("unable to inspect user emails before the unique-email migration", slog.String("error", err.Error())) - return - } - - // Pass 1: Unicode-aware canonicalization. - canonicalized := 0 - tx, err := s.driver.GetDB().BeginTx(ctx, nil) - if err != nil { - slog.Warn("unable to canonicalize user emails before the unique-email migration", slog.String("error", err.Error())) - } else { - updateQuery := s.uniqueEmailUpdateQuery() - for _, current := range accounts { - canonical := strings.ToLower(strings.TrimSpace(current.email)) - if canonical == current.email { - continue - } - if _, err := tx.ExecContext(ctx, updateQuery, canonical, current.id); err != nil { - _ = tx.Rollback() - slog.Warn("unable to canonicalize user emails before the unique-email migration", slog.String("error", err.Error())) - canonicalized = -1 - break - } - canonicalized++ - } - if canonicalized >= 0 { - if err := tx.Commit(); err != nil { - slog.Warn("unable to canonicalize user emails before the unique-email migration", slog.String("error", err.Error())) - } else if canonicalized > 0 { - slog.Info("canonicalized user emails before the unique-email migration", slog.Int("count", canonicalized)) - } - } - } - - // Pass 2: report. Rows arrive ordered by id, so the first account seen for - // an address is the one the migration keeps. - keeper := map[string]string{} - cleared := map[string][]string{} - malformed := []string{} - for _, current := range accounts { - canonical := strings.ToLower(strings.TrimSpace(current.email)) - if canonical == "" { - continue - } - if !legacyEmailLooksLikeAddress(canonical) { - malformed = append(malformed, current.username) - continue - } - if _, exists := keeper[canonical]; !exists { - keeper[canonical] = current.username - continue - } - cleared[canonical] = append(cleared[canonical], current.username) - } - for canonical, losers := range cleared { - slog.Warn("unique-email migration will clear a duplicate address", - slog.String("keptBy", keeper[canonical]), - slog.Any("clearedFrom", losers), - ) - } - if len(malformed) > 0 { - slog.Warn("unique-email migration will clear malformed addresses", - slog.Int("count", len(malformed)), - slog.Any("users", malformed), - ) - } -} - -// legacyEmailAccount is one pre-migration user row with a non-empty address. -type legacyEmailAccount struct { - id int32 - username string - email string -} - -// loadLegacyEmailAccounts reads every user with a non-empty address, oldest -// first. The result set is fully consumed and closed before the caller -// writes, which matters on SQLite where an open cursor blocks a writer. -func (s *Store) loadLegacyEmailAccounts(ctx context.Context) ([]legacyEmailAccount, error) { - rows, err := s.driver.GetDB().QueryContext(ctx, s.uniqueEmailSelectQuery()) - if err != nil { - return nil, err - } - defer rows.Close() - - accounts := []legacyEmailAccount{} - for rows.Next() { - var current legacyEmailAccount - if err := rows.Scan(¤t.id, ¤t.username, ¤t.email); err != nil { - return nil, err - } - accounts = append(accounts, current) - } - if err := rows.Err(); err != nil { - return nil, err - } - return accounts, nil -} - -// legacyEmailLooksLikeAddress mirrors the migration's SQL rule for values that -// are kept: it must contain an '@' and none of the characters that only appear -// in display-name forms or other junk the API would refuse. -func legacyEmailLooksLikeAddress(email string) bool { - return strings.Contains(email, "@") && !strings.ContainsAny(email, "<> ") -} - -// uniqueEmailSelectQuery selects every user that currently has a non-empty -// address, oldest first, using the pre-migration column shape. -func (s *Store) uniqueEmailSelectQuery() string { - switch s.profile.Driver { - case "mysql": - return "SELECT `id`, `username`, `email` FROM `user` WHERE `email` <> '' ORDER BY `id`" - case "postgres": - return `SELECT id, username, email FROM "user" WHERE email <> '' ORDER BY id` - default: - return "SELECT id, username, email FROM user WHERE email <> '' ORDER BY id" - } -} - -// uniqueEmailUpdateQuery rewrites one user's address by id. -func (s *Store) uniqueEmailUpdateQuery() string { - switch s.profile.Driver { - case "mysql": - return "UPDATE `user` SET `email` = ? WHERE `id` = ?" - case "postgres": - return `UPDATE "user" SET email = $1 WHERE id = $2` - default: - return "UPDATE user SET email = ? WHERE id = ?" - } -} diff --git a/store/schema_version.go b/store/schema_version.go new file mode 100644 index 000000000..065e06581 --- /dev/null +++ b/store/schema_version.go @@ -0,0 +1,64 @@ +package store + +import ( + "cmp" + "regexp" + "strconv" + "strings" + + "github.com/pkg/errors" +) + +// Schema versions are legacy 0.MINOR.SEQUENCE or calendar YY.M.SEQUENCE. +// The sequence tracks database migrations, independently of release revisions. +// Calendar markers omit month padding so old binaries can reject downgrades +// using their SemVer comparator. Release tags and migration directories retain it. +var calendarMigrationSeriesPattern = regexp.MustCompile(`^[1-9][0-9]\.(0[1-9]|1[0-2])$`) +var migrationFilePattern = regexp.MustCompile(`^[0-9]+__[^/]+\.sql$`) +var schemaVersionPattern = regexp.MustCompile(`^(0\.(0|[1-9][0-9]*)|[1-9][0-9]\.([1-9]|1[0-2]))\.(0|[1-9][0-9]*)$`) + +func parseSchemaVersion(value string) ([3]int, error) { + var result [3]int + if !schemaVersionPattern.MatchString(value) { + return result, errors.Errorf("invalid database schema version %q", value) + } + for i, part := range strings.Split(value, ".") { + number, err := strconv.Atoi(part) + if err != nil { + return result, errors.Wrapf(err, "invalid database schema version %q", value) + } + result[i] = number + } + return result, nil +} + +// mustParseSchemaVersion is for versions the migrator itself produced or +// declared as constants; those are valid by construction. +func mustParseSchemaVersion(value string) [3]int { + parsed, err := parseSchemaVersion(value) + if err != nil { + panic(err) + } + return parsed +} + +func compareParsedSchemaVersions(a, b [3]int) int { + for i := range a { + if order := cmp.Compare(a[i], b[i]); order != 0 { + return order + } + } + return 0 +} + +func compareSchemaVersions(a, b string) (int, error) { + left, err := parseSchemaVersion(a) + if err != nil { + return 0, err + } + right, err := parseSchemaVersion(b) + if err != nil { + return 0, err + } + return compareParsedSchemaVersions(left, right), nil +} diff --git a/store/schema_version_test.go b/store/schema_version_test.go new file mode 100644 index 000000000..d77443e8f --- /dev/null +++ b/store/schema_version_test.go @@ -0,0 +1,159 @@ +package store + +import ( + "io/fs" + "maps" + "slices" + "testing" + "testing/fstest" + + "github.com/pkg/errors" + "github.com/stretchr/testify/require" + "golang.org/x/mod/semver" +) + +func TestCompareSchemaVersions(t *testing.T) { + for _, tc := range []struct { + a, b string + want int + }{ + {"0.31.7", "0.31.8", -1}, + {"0.31.8", "0.31.8", 0}, + {"26.9.1", "0.31.8", 1}, + {"26.9.10", "26.9.2", 1}, + {"26.10.1", "26.9.99", 1}, + {"27.1.1", "26.12.99", 1}, + } { + order, err := compareSchemaVersions(tc.a, tc.b) + require.NoError(t, err) + require.Equal(t, tc.want, order) + } + for _, invalid := range []string{"", "dev", "26.09.1", "26.9", "26.0.1", "26.13.1", "26.9.01", "26.9.1-rc.1", "26.9.1+build", "0.031.8", "26.9.999999999999999999999999"} { + _, err := compareSchemaVersions(invalid, baselineSchemaVersion) + require.Error(t, err, invalid) + _, err = compareSchemaVersions(baselineSchemaVersion, invalid) + require.Error(t, err, invalid) + } +} + +func migrationFixture(paths ...string) fstest.MapFS { + fsys := fstest.MapFS{} + for _, path := range paths { + fsys[path] = &fstest.MapFile{Data: []byte("SELECT 1;")} + } + return fsys +} + +func TestCalendarMigrationOrdering(t *testing.T) { + files, err := listMigrationFilesFrom(migrationFixture( + "migration/sqlite/LATEST.sql", + "migration/sqlite/27.01/00__next_year.sql", + "migration/sqlite/26.09/100__many_changes.sql", + "migration/sqlite/26.10/00__next_month.sql", + "migration/sqlite/26.09/09__tenth.sql", + "migration/sqlite/26.09/00__first.sql", + ), "migration/sqlite/") + require.NoError(t, err) + var versions []string + for _, file := range files { + versions = append(versions, file.version) + require.Equal(t, mustParseSchemaVersion(file.version), file.parsed) + // v0.31.0 uses this comparator for its downgrade guard. + require.True(t, semver.IsValid("v"+file.version)) + require.Positive(t, semver.Compare("v"+file.version, "v"+baselineSchemaVersion)) + } + require.Equal(t, []string{"26.9.1", "26.9.10", "26.9.101", "26.10.1", "27.1.1"}, versions) + v, err := getSchemaVersionOfMigrateScript("migration/sqlite/26.09/00__LATEST.sql") + require.NoError(t, err) + require.Equal(t, "26.9.1", v) + for _, path := range []string{ + "migration/sqlite/26.13/00__bad_month.sql", + "migration/sqlite/26.9/00__unpadded.sql", + "migration/sqlite/26.09/-1__negative.sql", + "migration/sqlite/26.09/00.sql", + "migration/sqlite/26.09/00__.sql", + "migration/sqlite/26.09/LATEST.sql", + } { + _, err := listMigrationFilesFrom(migrationFixture(path), "migration/sqlite/") + require.Error(t, err, path) + } +} + +func TestDuplicateMigrationSequenceIsRejected(t *testing.T) { + _, err := listMigrationFilesFrom(migrationFixture( + "migration/sqlite/26.09/00__first.sql", + "migration/sqlite/26.09/01__add_index.sql", + "migration/sqlite/26.09/01__rename_column.sql", + ), "migration/sqlite/") + require.ErrorContains(t, err, "both resolve to schema version 26.9.2") +} + +func TestCalendarMigrationSelection(t *testing.T) { + for _, tc := range []struct { + file, current, target string + want bool + }{ + {"26.9.1", "0.31.8", "26.10.1", true}, + {"26.9.1", "26.9.1", "26.10.1", false}, + {"26.9.2", "26.9.1", "26.9.2", true}, + {"26.9.3", "26.9.1", "26.9.2", false}, + {"27.1.1", "26.12.1", "27.1.1", true}, + } { + apply := shouldApplyMigration(mustParseSchemaVersion(tc.file), mustParseSchemaVersion(tc.current), mustParseSchemaVersion(tc.target)) + require.Equal(t, tc.want, apply, "%+v", tc) + } +} + +// migrationVersionsByDriver lists each driver's migration versions in order. +func migrationVersionsByDriver(t *testing.T, fsys fs.FS) map[string][]string { + t.Helper() + entries, err := fs.ReadDir(fsys, "migration") + require.NoError(t, err) + versions := map[string][]string{} + for _, entry := range entries { + if !entry.IsDir() { + continue + } + files, err := listMigrationFilesFrom(fsys, "migration/"+entry.Name()+"/") + require.NoError(t, err, entry.Name()) + driverVersions := []string{} + for _, file := range files { + driverVersions = append(driverVersions, file.version) + } + versions[entry.Name()] = driverVersions + } + return versions +} + +// migrationVersionMismatch names the first driver whose migration versions +// differ from another driver's, or returns nil when every driver agrees. +func migrationVersionMismatch(versions map[string][]string) error { + drivers := slices.Sorted(maps.Keys(versions)) + for _, driver := range drivers[1:] { + if !slices.Equal(versions[drivers[0]], versions[driver]) { + return errors.Errorf("driver %s ships migration versions %v but %s ships %v", + driver, versions[driver], drivers[0], versions[drivers[0]]) + } + } + return nil +} + +// TestMigrationVersionsMatchAcrossDrivers guards the schema marker: a driver +// only records versions whose SQL it executed, so a migration must exist for +// every driver before any driver can advance past it. +func TestMigrationVersionsMatchAcrossDrivers(t *testing.T) { + versions := migrationVersionsByDriver(t, migrationFS) + require.Len(t, versions, 3) + require.NoError(t, migrationVersionMismatch(versions)) + + // The check itself catches a migration that lands for one driver only. + partial := migrationVersionsByDriver(t, migrationFixture( + "migration/mysql/LATEST.sql", + "migration/postgres/LATEST.sql", + "migration/sqlite/LATEST.sql", + "migration/sqlite/26.09/00__sqlite_only.sql", + )) + require.Equal(t, []string{"26.9.1"}, partial["sqlite"]) + require.Empty(t, partial["mysql"]) + require.ErrorContains(t, migrationVersionMismatch(partial), "driver sqlite ships migration versions [26.9.1] but mysql ships []") +} diff --git a/store/test/containers.go b/store/test/containers.go index 639121a17..db26223d4 100644 --- a/store/test/containers.go +++ b/store/test/containers.go @@ -32,12 +32,9 @@ const ( // Memos container settings for migration testing. MemosDockerImage = "neosmemo/memos" - // StableMemosVersion is the previous stable release upgrades are tested from. - // Pinned rather than tracking the floating "stable" tag so a Docker Hub retag - // cannot change what CI verifies. Bump this when a new stable ships. - // scripts/release_smoke_test.sh detects the previous release from Git tags - // instead, so the black-box tier still follows "stable" automatically. - StableMemosVersion = "0.30.0" + // PreBaselineMemosVersion exercises the mandatory v0.31.0 intermediate upgrade. + // Keep this pinned: the current binary no longer ships its migration history. + PreBaselineMemosVersion = "0.30.0" mysqlNetworkAlias = "memos-mysql" postgresNetworkAlias = "memos-postgres" diff --git a/store/test/migrator_guardrail_test.go b/store/test/migrator_guardrail_test.go index 44494cb64..dea067393 100644 --- a/store/test/migrator_guardrail_test.go +++ b/store/test/migrator_guardrail_test.go @@ -30,67 +30,58 @@ func setSchemaVersion(ctx context.Context, t *testing.T, ts *store.Store, schema require.Equal(t, schemaVersion, stored.SchemaVersion, "schema version should be persisted") } -// TestMigrationRejectsDowngrade verifies a database written by a newer Memos is -// refused rather than silently re-migrated. Starting an old binary against a -// newer database is the most common way a rollback corrupts data. -func TestMigrationRejectsDowngrade(t *testing.T) { - t.Parallel() +// TestMigrationRejectsUnsupportedSchema verifies rejected startup leaves data +// and settings unchanged, including an ACCESS setting that would otherwise be created. +func TestMigrationRejectsUnsupportedSchema(t *testing.T) { + for _, tc := range []struct { + name, schema, message string + missingBasic bool + }{ + {name: "pre-v0.22", schema: "0.21.0", message: "First upgrade to v0.25.3"}, + {name: "v0.22", schema: "0.22.0", message: "First upgrade to v0.31.0"}, + {name: "v0.30", schema: "0.30.1", message: "First upgrade to v0.31.0"}, + {name: "before-baseline", schema: "0.31.7", message: "First upgrade to v0.31.0"}, + {name: "empty", schema: "", message: "First upgrade to v0.25.3"}, + {name: "zero", schema: "0.0.0", message: "First upgrade to v0.25.3"}, + {name: "missing-basic", missingBasic: true, message: "First upgrade to v0.25.3"}, + {name: "invalid-month", schema: "26.13.1", message: "invalid database schema version"}, + {name: "calver-newer", schema: "26.9.1", message: "cannot downgrade schema version"}, + {name: "invalid", schema: "unknown", message: "invalid database schema version"}, + {name: "incomplete", schema: "0.31", message: "invalid database schema version"}, + {name: "prerelease", schema: "0.31.8-rc.1", message: "invalid database schema version"}, + {name: "build-metadata", schema: "0.31.8+build", message: "invalid database schema version"}, + {name: "newer", schema: "99.1.1", message: "cannot downgrade schema version"}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + ctx := context.Background() + ts := NewTestingStore(ctx, t) + defer ts.Close() + user, err := createTestingHostUser(ctx, ts) + require.NoError(t, err) + memo, err := ts.CreateMemo(ctx, &store.Memo{ + UID: "preserved-memo", CreatorID: user.ID, Content: "preserve on rejected startup", Visibility: store.Private, + }) + require.NoError(t, err) + memo, err = ts.GetMemo(ctx, &store.FindMemo{UID: &memo.UID}) + require.NoError(t, err) + if tc.missingBasic { + require.NoError(t, ts.DeleteInstanceSetting(ctx, &store.DeleteInstanceSetting{Name: "BASIC"})) + } else { + setSchemaVersion(ctx, t, ts, tc.schema) + } + require.NoError(t, ts.DeleteInstanceSetting(ctx, &store.DeleteInstanceSetting{Name: "ACCESS"})) + before, err := ts.GetDriver().ListInstanceSettings(ctx, &store.FindInstanceSetting{}) + require.NoError(t, err) - ctx := context.Background() - ts := NewTestingStore(ctx, t) + require.ErrorContains(t, ts.Migrate(ctx), tc.message) - currentVersion, err := ts.GetCurrentSchemaVersion() - require.NoError(t, err) - - // Pretend the database was written by a much newer release. - setSchemaVersion(ctx, t, ts, "99.0.0") - - err = ts.Migrate(ctx) - require.Error(t, err, "migrating a newer database should fail") - require.Contains(t, err.Error(), "cannot downgrade schema version", - "error should explain the downgrade was refused") - require.Contains(t, err.Error(), currentVersion, - "error should name the version the binary supports") -} - -// TestMigrationRejectsPreV022Installation verifies installations older than the -// supported floor are refused with actionable upgrade instructions instead of -// failing partway through a migration. -func TestMigrationRejectsPreV022Installation(t *testing.T) { - t.Parallel() - - ctx := context.Background() - ts := NewTestingStore(ctx, t) - - // 0.21.x predates moving schema tracking from migration_history to system_setting. - setSchemaVersion(ctx, t, ts, "0.21.0") - - err := ts.Migrate(ctx) - require.Error(t, err, "migrating a pre-0.22 installation should fail") - require.Contains(t, err.Error(), "too old to upgrade directly") - require.Contains(t, err.Error(), "0.25.3", - "error should name the intermediate version to upgrade through") -} - -// TestMigrationAcceptsMinimumSupportedVersion pins the other side of the -// supported-version boundary: 0.22.0 must clear the floor check that rejects -// 0.21.x. -// -// This asserts only that the floor check passes, not that the whole migration -// succeeds. The store here has a current schema relabelled as 0.22.0, so -// replaying the 0.22-onward migrations against it legitimately fails on tables -// that were since renamed. Verifying a real 0.22 replay needs a genuine 0.22 -// database, which is the container tier's job. -func TestMigrationAcceptsMinimumSupportedVersion(t *testing.T) { - t.Parallel() - - ctx := context.Background() - ts := NewTestingStore(ctx, t) - - setSchemaVersion(ctx, t, ts, "0.22.0") - - if err := ts.Migrate(ctx); err != nil { - require.NotContains(t, err.Error(), "too old to upgrade directly", - "0.22.0 is the supported floor and must clear the minimum-version check") + after, err := ts.GetDriver().ListInstanceSettings(ctx, &store.FindInstanceSetting{}) + require.NoError(t, err) + require.ElementsMatch(t, before, after, "rejected startup must not write settings") + preserved, err := ts.GetMemo(ctx, &store.FindMemo{UID: &memo.UID}) + require.NoError(t, err) + require.Equal(t, memo, preserved) + }) } } diff --git a/store/test/migrator_stable_upgrade_test.go b/store/test/migrator_stable_upgrade_test.go index d0eb8ed3d..13d85fe9d 100644 --- a/store/test/migrator_stable_upgrade_test.go +++ b/store/test/migrator_stable_upgrade_test.go @@ -12,17 +12,9 @@ import ( "github.com/usememos/memos/store" ) -// TestUpgradeFromPreviousStableRenamesShortcutsToMemoViews covers the upgrade -// path users actually take: previous stable release to the current build, with -// data already in the database. -// -// The 0.31 SHORTCUTS rename is hand-written per driver with dialect-specific -// JSON rewriting (MySQL JSON_* functions and backtick quoting, SQLite json_*, -// Postgres jsonb operators) and per-driver validity guards. The existing -// fixture test drives a hand-maintained legacy schema; this test drives the -// schema the real previous-stable binary created on whichever driver DRIVER -// selects. -func TestUpgradeFromPreviousStableRenamesShortcutsToMemoViews(t *testing.T) { +// TestUpgradeThroughBaselineRelease verifies the required intermediate upgrade +// using released binaries, including data transformations owned by v0.31.0. +func TestUpgradeThroughBaselineRelease(t *testing.T) { if testing.Short() { t.Skip("skipping container-based upgrade test in short mode") } @@ -31,10 +23,10 @@ func TestUpgradeFromPreviousStableRenamesShortcutsToMemoViews(t *testing.T) { ctx := context.Background() driver := getDriverFromEnv() - cfg, hostDSN := prepareUpgradeFixture(t, driver, StableMemosVersion) + cfg, hostDSN := prepareUpgradeFixture(t, driver, PreBaselineMemosVersion) t.Logf("Starting Memos %s container for %s schema bootstrap...", cfg.Version, driver) container, err := StartMemosContainer(ctx, cfg) - require.NoError(t, err, "failed to start memos %s container", StableMemosVersion) + require.NoError(t, err, "failed to start memos %s container", PreBaselineMemosVersion) t.Cleanup(func() { if container != nil { _ = container.Terminate(ctx) @@ -49,10 +41,11 @@ func TestUpgradeFromPreviousStableRenamesShortcutsToMemoViews(t *testing.T) { settingBeforeUpgrade, err := legacyStore.GetInstanceBasicSetting(ctx) require.NoError(t, err) - t.Logf("Schema version written by %s: %s", StableMemosVersion, settingBeforeUpgrade.SchemaVersion) + t.Logf("Schema version written by %s: %s", PreBaselineMemosVersion, settingBeforeUpgrade.SchemaVersion) - require.NoError(t, container.Terminate(ctx), "failed to stop memos %s container", StableMemosVersion) + require.NoError(t, container.Terminate(ctx), "failed to stop memos %s container", PreBaselineMemosVersion) container = nil + require.NoError(t, legacyStore.Close()) // Seed through the store API where the schema is shared by v0.30.0 and the // current build. The legacy SHORTCUTS rows predate the current proto, so @@ -76,6 +69,12 @@ func TestUpgradeFromPreviousStableRenamesShortcutsToMemoViews(t *testing.T) { insertSetting = fmt.Sprintf("INSERT INTO user_setting (user_id, %[1]s, value) VALUES ($1, $2, $3)", settingKeyColumn) } db := seedStore.GetDriver().GetDB() + insertMemo := "INSERT INTO memo (uid, creator_id, content, payload) VALUES (?, ?, ?, '{}')" + if driver == "postgres" { + insertMemo = "INSERT INTO memo (uid, creator_id, content, payload) VALUES ($1, $2, $3, '{}')" + } + _, err = db.ExecContext(ctx, insertMemo, "before-baseline", renamedUser.ID, "memo from v0.30.0") + require.NoError(t, err) _, err = db.ExecContext(ctx, insertSetting, renamedUser.ID, "SHORTCUTS", `{"shortcuts":[{"id":"legacy","title":"legacy shortcut","filter":"tag in [\"legacy\"]"}]}`) require.NoError(t, err, "should seed a legacy SHORTCUTS setting") @@ -105,15 +104,44 @@ func TestUpgradeFromPreviousStableRenamesShortcutsToMemoViews(t *testing.T) { require.NoError(t, err) require.Nil(t, preExisting, "the seeded user should not have a MEMO_VIEWS setting before the upgrade") + // The current binary must refuse the old schema before modifying settings. + before, err := seedStore.GetDriver().ListInstanceSettings(ctx, &store.FindInstanceSetting{}) + require.NoError(t, err) + require.ErrorContains(t, seedStore.Migrate(ctx), "First upgrade to v0.31.0") + after, err := seedStore.GetDriver().ListInstanceSettings(ctx, &store.FindInstanceSetting{}) + require.NoError(t, err) + require.ElementsMatch(t, before, after) + var preservedContent string + require.NoError(t, db.QueryRowContext(ctx, "SELECT content FROM memo WHERE uid = 'before-baseline'").Scan(&preservedContent)) + require.Equal(t, "memo from v0.30.0", preservedContent) + require.NoError(t, seedStore.Close()) + + // Only the released intermediate binary carries the historical migrations. + cfg.Version = "0.31.0" + container, err = StartMemosContainer(ctx, cfg) + require.NoError(t, err, "failed to start the required intermediate release") + require.NoError(t, container.Terminate(ctx)) + container = nil + // Upgrade with current code. ts := NewTestingStoreWithDSN(ctx, t, driver, hostDSN) - require.NoError(t, ts.Migrate(ctx), "upgrade from %s should succeed for %s", StableMemosVersion, driver) + defer ts.Close() + baseline, err := ts.GetInstanceBasicSetting(ctx) + require.NoError(t, err) + require.Equal(t, "0.31.8", baseline.SchemaVersion, "v0.31.0 must establish the fixed baseline") + require.NoError(t, ts.Migrate(ctx), "upgrade from v0.31.0 should succeed for %s", driver) currentVersion, err := ts.GetCurrentSchemaVersion() require.NoError(t, err) upgradedSetting, err := ts.GetInstanceBasicSetting(ctx) require.NoError(t, err) require.Equal(t, currentVersion, upgradedSetting.SchemaVersion, "schema version should advance") + memoUID := "before-baseline" + preservedMemo, err := ts.GetMemo(ctx, &store.FindMemo{UID: &memoUID}) + require.NoError(t, err) + require.NotNil(t, preservedMemo) + require.Equal(t, "memo from v0.30.0", preservedMemo.Content) + require.Equal(t, renamedUser.ID, preservedMemo.CreatorID) // The legacy SHORTCUTS setting is now readable as MEMO_VIEWS. renamed, err := ts.GetUserSetting(ctx, &store.FindUserSetting{ diff --git a/store/test/migrator_test.go b/store/test/migrator_test.go index 15c185d47..44a677fcc 100644 --- a/store/test/migrator_test.go +++ b/store/test/migrator_test.go @@ -3,15 +3,10 @@ package test import ( "context" "database/sql" - "fmt" "testing" - "time" "github.com/stretchr/testify/require" - colorpb "google.golang.org/genproto/googleapis/type/color" - "google.golang.org/protobuf/encoding/protojson" - "github.com/usememos/memos/internal/testutil/fakes3" storepb "github.com/usememos/memos/proto/gen/store" "github.com/usememos/memos/store" storedb "github.com/usememos/memos/store/db" @@ -52,7 +47,7 @@ func TestFreshInstall(t *testing.T) { // Verify migration completed successfully currentSchemaVersion, err := ts.GetCurrentSchemaVersion() require.NoError(t, err) - require.NotEmpty(t, currentSchemaVersion, "schema version should be set after fresh install") + require.Equal(t, "0.31.8", currentSchemaVersion, "fresh install should start at the retained baseline") // Verify we can read instance settings (basic sanity check) instanceSetting, err := ts.GetInstanceBasicSetting(ctx) @@ -150,188 +145,6 @@ func TestMigrationWithData(t *testing.T) { require.Equal(t, "Data before migration re-run", memo.Content, "memo content should be preserved") } -func TestMigrationMultiSpacesPreservesMemosAndRelations(t *testing.T) { - ctx := context.Background() - driver := getDriverFromEnv() - skipWithoutLegacySchema(t, driver) - dsn := getTestingProfileForDriver(t, driver).DSN - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - _, err = db.ExecContext(ctx, legacySchemaFixture(driver)) - require.NoError(t, err) - - basicSetting, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.31.3"}) - require.NoError(t, err) - insertSetting := "INSERT INTO system_setting (name, value, description) VALUES (?, ?, '')" - insertMemo := "INSERT INTO memo (id, uid, content, visibility, row_status, pinned, payload) VALUES (?, ?, ?, ?, ?, ?, ?)" - insertRelation := "INSERT INTO memo_relation (memo_id, related_memo_id, type) VALUES (?, ?, ?)" - if driver == "postgres" { - insertSetting = "INSERT INTO system_setting (name, value, description) VALUES ($1, $2, '')" - insertMemo = "INSERT INTO memo (id, uid, content, visibility, row_status, pinned, payload) VALUES ($1, $2, $3, $4, $5, $6, $7)" - insertRelation = "INSERT INTO memo_relation (memo_id, related_memo_id, type) VALUES ($1, $2, $3)" - } - _, err = db.ExecContext(ctx, insertSetting, "BASIC", string(basicSetting)) - require.NoError(t, err) - for _, memo := range []struct { - id int32 - uid string - visibility store.Visibility - rowStatus store.RowStatus - pinned bool - payload string - }{ - {id: 1, uid: "legacy-root", visibility: store.Public, rowStatus: store.Normal, pinned: true, payload: `{"property":{"hasLink":true}}`}, - {id: 2, uid: "legacy-direct-comment", visibility: store.Public, rowStatus: store.Normal, payload: `{}`}, - {id: 3, uid: "legacy-nested-comment", visibility: store.Protected, rowStatus: store.Archived, payload: `{"property":{"hasTaskList":true}}`}, - {id: 4, uid: "legacy-reference-target", visibility: store.Private, rowStatus: store.Normal, payload: `{}`}, - } { - _, err = db.ExecContext(ctx, insertMemo, memo.id, memo.uid, memo.uid, memo.visibility, memo.rowStatus, memo.pinned, memo.payload) - require.NoError(t, err) - } - _, err = db.ExecContext(ctx, insertMemo, 100, "deleted-high-memo", "deleted", store.Private, store.Normal, false, `{}`) - require.NoError(t, err) - _, err = db.ExecContext(ctx, "DELETE FROM memo WHERE id = 100") - require.NoError(t, err) - if driver == "postgres" { - _, err = db.ExecContext(ctx, "SELECT setval(pg_get_serial_sequence('memo', 'id'), 100, true)") - require.NoError(t, err) - } - for _, relation := range []struct { - memoID, relatedMemoID int32 - typeName store.MemoRelationType - }{ - {memoID: 2, relatedMemoID: 1, typeName: store.MemoRelationComment}, - {memoID: 3, relatedMemoID: 2, typeName: store.MemoRelationComment}, - {memoID: 1, relatedMemoID: 4, typeName: store.MemoRelationReference}, - } { - _, err = db.ExecContext(ctx, insertRelation, relation.memoID, relation.relatedMemoID, relation.typeName) - require.NoError(t, err) - } - if driver == "sqlite" { - _, err = db.ExecContext(ctx, "CREATE INDEX idx_memo_creator_id ON memo(creator_id)") - require.NoError(t, err) - } - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, driver, dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - - assertMemo := func(id int32, uid string, visibility store.Visibility, rowStatus store.RowStatus, pinned bool, payload string) { - t.Helper() - var gotUID, content string - var gotVisibility store.Visibility - var gotRowStatus store.RowStatus - var gotPinned bool - var gotPayload []byte - var spaceID sql.NullInt64 - query := "SELECT uid, content, visibility, row_status, pinned, payload, space_id FROM memo WHERE id = ?" - if driver == "postgres" { - query = "SELECT uid, content, visibility, row_status, pinned, payload, space_id FROM memo WHERE id = $1" - } - require.NoError(t, ts.GetDriver().GetDB().QueryRowContext(ctx, query, id).Scan( - &gotUID, &content, &gotVisibility, &gotRowStatus, &gotPinned, &gotPayload, &spaceID, - )) - require.Equal(t, uid, gotUID) - require.Equal(t, uid, content) - require.Equal(t, visibility, gotVisibility) - require.Equal(t, rowStatus, gotRowStatus) - require.Equal(t, pinned, gotPinned) - require.JSONEq(t, payload, string(gotPayload)) - require.False(t, spaceID.Valid) - } - assertMemo(1, "legacy-root", store.Public, store.Normal, true, `{"property":{"hasLink":true}}`) - assertMemo(2, "legacy-direct-comment", store.Public, store.Normal, false, `{}`) - assertMemo(3, "legacy-nested-comment", store.Protected, store.Archived, false, `{"property":{"hasTaskList":true}}`) - assertMemo(4, "legacy-reference-target", store.Private, store.Normal, false, `{}`) - - type relationRow struct { - memoID, relatedMemoID int32 - typeName store.MemoRelationType - } - rows, err := ts.GetDriver().GetDB().QueryContext(ctx, "SELECT memo_id, related_memo_id, type FROM memo_relation ORDER BY memo_id, related_memo_id, type") - require.NoError(t, err) - defer rows.Close() - var relations []relationRow - for rows.Next() { - var relation relationRow - require.NoError(t, rows.Scan(&relation.memoID, &relation.relatedMemoID, &relation.typeName)) - relations = append(relations, relation) - } - require.NoError(t, rows.Err()) - require.Equal(t, []relationRow{ - {memoID: 1, relatedMemoID: 4, typeName: store.MemoRelationReference}, - {memoID: 2, relatedMemoID: 1, typeName: store.MemoRelationComment}, - {memoID: 3, relatedMemoID: 2, typeName: store.MemoRelationComment}, - }, relations) - - insertNextMemo := "INSERT INTO memo (uid, creator_id, content, visibility, payload) VALUES (?, ?, ?, ?, ?)" - if driver == "postgres" { - var nextID int64 - err = ts.GetDriver().GetDB().QueryRowContext(ctx, - "INSERT INTO memo (uid, creator_id, content, visibility, payload) VALUES ($1, $2, $3, $4, $5) RETURNING id", - "after-migration", 0, "after", store.Private, `{}`, - ).Scan(&nextID) - require.NoError(t, err) - require.Equal(t, int64(101), nextID) - } else { - result, err := ts.GetDriver().GetDB().ExecContext(ctx, insertNextMemo, "after-migration", 0, "after", store.Private, `{}`) - require.NoError(t, err) - nextID, err := result.LastInsertId() - require.NoError(t, err) - require.Equal(t, int64(101), nextID) - } - - requireQueryError(ctx, t, ts.GetDriver().GetDB(), "SELECT parent_memo_id, root_memo_id FROM memo LIMIT 0", "memo-local schema must not add canonical-root columns") - requireQueryError(ctx, t, ts.GetDriver().GetDB(), "SELECT row_status FROM space LIMIT 0", "Space has no archived state") - if driver == "sqlite" { - var indexName string - require.NoError(t, ts.GetDriver().GetDB().QueryRowContext(ctx, - "SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'idx_memo_creator_id'", - ).Scan(&indexName)) - require.Equal(t, "idx_memo_creator_id", indexName, "memo rebuild must preserve the creator lookup index") - } -} - -func TestMigrationSpaceMemberStatusBackfillsActive(t *testing.T) { - ctx := context.Background() - skipWithoutLegacySchema(t, getDriverFromEnv()) - ts := NewTestingStore(ctx, t) - - owner, err := createTestingHostUser(ctx, ts) - require.NoError(t, err) - space, err := ts.CreateSpace(ctx, &store.Space{ - UID: "status-migration-space", - Title: "Status migration", - }, owner.ID) - require.NoError(t, err) - - db := ts.GetDriver().GetDB() - _, err = db.ExecContext(ctx, "ALTER TABLE space_member DROP COLUMN status") - require.NoError(t, err) - _, err = db.ExecContext(ctx, "ALTER TABLE space DROP COLUMN payload") - require.NoError(t, err) - - basicSetting, err := ts.GetInstanceBasicSetting(ctx) - require.NoError(t, err) - basicSetting.SchemaVersion = "0.31.4" - _, err = ts.UpsertInstanceSetting(ctx, &storepb.InstanceSetting{ - Key: storepb.InstanceSettingKey_BASIC, - Value: &storepb.InstanceSetting_BasicSetting{BasicSetting: basicSetting}, - }) - require.NoError(t, err) - - require.NoError(t, ts.Migrate(ctx)) - - query := "SELECT status FROM space_member WHERE space_id = ? AND user_id = ?" - if getDriverFromEnv() == "postgres" { - query = "SELECT status FROM space_member WHERE space_id = $1 AND user_id = $2" - } - var status store.SpaceMemberStatus - require.NoError(t, db.QueryRowContext(ctx, query, space.ID, owner.ID).Scan(&status)) - require.Equal(t, store.SpaceMemberStatusActive, status) -} - // TestMigrationMultipleReRuns verifies that migration is idempotent // even when run multiple times in succession. func TestMigrationMultipleReRuns(t *testing.T) { @@ -425,965 +238,3 @@ func TestConcurrentInstanceAccessInitializationKeepsFirstInsert(t *testing.T) { require.NoError(t, err) require.Equal(t, storepb.InstanceAccessMode_INSTANCE_ACCESS_MODE_PRIVATE, setting.GetAccessSetting().AccessMode) } - -// TestMigrationStorageSetting verifies that the legacy singleton storage -// configuration is expanded into a named storage without removing fields used -// by older clients and rollback versions. -func TestMigrationStorageSetting(t *testing.T) { - ctx := context.Background() - driver := getDriverFromEnv() - skipWithoutLegacySchema(t, driver) - - legacyDatabase, err := protojson.Marshal(&storepb.InstanceStorageSetting{ - StorageType: storepb.InstanceStorageSetting_DATABASE, - }) - require.NoError(t, err) - legacyLocal, err := protojson.Marshal(&storepb.InstanceStorageSetting{ - StorageType: storepb.InstanceStorageSetting_LOCAL, - FilepathTemplate: "assets/{filename}", - }) - require.NoError(t, err) - legacyS3, err := protojson.Marshal(&storepb.InstanceStorageSetting{ - StorageType: storepb.InstanceStorageSetting_S3, - S3Config: &storepb.StorageS3Config{ - AccessKeyId: "access-key", - AccessKeySecret: "secret", - Endpoint: "https://s3.example.com", - Region: "us-east-1", - Bucket: "memos", - }, - }) - require.NoError(t, err) - alreadyNamed, err := protojson.Marshal(&storepb.InstanceStorageSetting{ - StorageType: storepb.InstanceStorageSetting_S3, - DefaultStorageId: "custom-s3", - S3Config: &storepb.StorageS3Config{ - AccessKeyId: "access-key", - AccessKeySecret: "secret", - Endpoint: "https://s3.example.com", - Region: "us-east-1", - Bucket: "memos", - }, - Storages: []*storepb.Storage{ - { - Id: "custom-s3", - Name: "Primary", - Type: storepb.StorageType_STORAGE_TYPE_S3, - Config: &storepb.Storage_S3Config{S3Config: &storepb.StorageS3Config{ - AccessKeyId: "access-key", - AccessKeySecret: "secret", - Endpoint: "https://s3.example.com", - Region: "us-east-1", - Bucket: "memos", - }}, - }, - }, - }) - require.NoError(t, err) - - tests := []struct { - name string - value string - wantStorageID string - wantStorageType storepb.StorageType - wantLegacyType storepb.InstanceStorageSetting_StorageType - wantName string - wantRawUnchanged bool - }{ - { - name: "database", - value: string(legacyDatabase), - wantStorageID: "database", - wantStorageType: storepb.StorageType_STORAGE_TYPE_DATABASE, - wantLegacyType: storepb.InstanceStorageSetting_DATABASE, - wantName: "Database", - }, - { - name: "local", - value: string(legacyLocal), - wantStorageID: "local", - wantStorageType: storepb.StorageType_STORAGE_TYPE_LOCAL, - wantLegacyType: storepb.InstanceStorageSetting_LOCAL, - wantName: "Local", - }, - { - name: "s3", - value: string(legacyS3), - wantStorageID: "s3", - wantStorageType: storepb.StorageType_STORAGE_TYPE_S3, - wantLegacyType: storepb.InstanceStorageSetting_S3, - wantName: "S3", - }, - { - name: "already named", - value: string(alreadyNamed), - wantStorageID: "custom-s3", - wantStorageType: storepb.StorageType_STORAGE_TYPE_S3, - wantLegacyType: storepb.InstanceStorageSetting_S3, - wantName: "Primary", - }, - { - name: "invalid JSON", - value: `{oops}`, - wantRawUnchanged: true, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - dsn := getTestingProfileForDriver(t, driver).DSN - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - _, err = db.ExecContext(ctx, legacySchemaFixture(driver)) - require.NoError(t, err) - - basicSettingBytes, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.31.1"}) - require.NoError(t, err) - insertSetting := "INSERT INTO system_setting (name, value, description) VALUES (?, ?, '')" - if driver == "postgres" { - insertSetting = "INSERT INTO system_setting (name, value, description) VALUES ($1, $2, '')" - } - _, err = db.ExecContext(ctx, insertSetting, "BASIC", string(basicSettingBytes)) - require.NoError(t, err) - _, err = db.ExecContext(ctx, insertSetting, "STORAGE", test.value) - require.NoError(t, err) - if test.name == "s3" { - insertStorageMigrationAttachments(ctx, t, db, driver) - } - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, driver, dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - if test.wantRawUnchanged { - query := "SELECT value FROM system_setting WHERE name = ?" - if driver == "postgres" { - query = "SELECT value FROM system_setting WHERE name = $1" - } - var raw string - require.NoError(t, ts.GetDriver().GetDB().QueryRowContext(ctx, query, "STORAGE").Scan(&raw)) - require.Equal(t, test.value, raw) - return - } - - stored, err := ts.GetStoredInstanceSetting(ctx, &store.FindInstanceSetting{Name: storepb.InstanceSettingKey_STORAGE.String()}) - require.NoError(t, err) - require.NotNil(t, stored) - setting := stored.GetStorageSetting() - require.Equal(t, test.wantLegacyType, setting.GetStorageType(), "legacy storage type must be preserved") - require.Equal(t, test.wantStorageID, setting.GetDefaultStorageId()) - require.Len(t, setting.GetStorages(), 1) - require.Equal(t, test.wantStorageID, setting.GetStorages()[0].GetId()) - require.Equal(t, test.wantName, setting.GetStorages()[0].GetName()) - require.Equal(t, test.wantStorageType, setting.GetStorages()[0].GetType()) - if test.wantStorageType == storepb.StorageType_STORAGE_TYPE_S3 { - require.Equal(t, "secret", setting.GetS3Config().GetAccessKeySecret(), "legacy S3 config must be preserved") - require.Equal(t, "secret", setting.GetStorages()[0].GetS3Config().GetAccessKeySecret()) - } - if test.name == "s3" { - assertStorageMigrationAttachments(ctx, t, ts) - } - }) - } -} - -func insertStorageMigrationAttachments(ctx context.Context, t *testing.T, db *sql.DB, driver string) { - t.Helper() - legacyPayload, err := protojson.Marshal(&storepb.AttachmentPayload{ - Payload: &storepb.AttachmentPayload_S3Object_{ - S3Object: &storepb.AttachmentPayload_S3Object{Key: "legacy/no-config.txt"}, - }, - }) - require.NoError(t, err) - embeddedPayload, err := protojson.Marshal(&storepb.AttachmentPayload{ - Payload: &storepb.AttachmentPayload_S3Object_{ - S3Object: &storepb.AttachmentPayload_S3Object{ - Key: "legacy/embedded-config.txt", - S3Config: &storepb.StorageS3Config{ - Endpoint: "https://old-s3.example.com", - Region: "us-east-1", - Bucket: "old-bucket", - }, - }, - }, - }) - require.NoError(t, err) - namedPayload, err := protojson.Marshal(&storepb.AttachmentPayload{ - Payload: &storepb.AttachmentPayload_S3Object_{ - S3Object: &storepb.AttachmentPayload_S3Object{Key: "named/object.txt", StorageId: "existing-s3"}, - }, - }) - require.NoError(t, err) - - insertAttachment := "INSERT INTO attachment (uid, creator_id, filename, type, size, storage_type, reference, payload) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" - if driver == "postgres" { - insertAttachment = "INSERT INTO attachment (uid, creator_id, filename, type, size, storage_type, reference, payload) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)" - } - for _, attachment := range []struct { - uid string - payload []byte - }{ - {uid: "legacy-s3-no-config", payload: legacyPayload}, - {uid: "legacy-s3-embedded-config", payload: embeddedPayload}, - {uid: "legacy-s3-existing-id", payload: namedPayload}, - } { - _, err := db.ExecContext(ctx, insertAttachment, attachment.uid, 1, attachment.uid+".txt", "text/plain", 1, "S3", "", string(attachment.payload)) - require.NoError(t, err) - } -} - -func assertStorageMigrationAttachments(ctx context.Context, t *testing.T, ts *store.Store) { - t.Helper() - find := func(uid string) *storepb.AttachmentPayload_S3Object { - query := "SELECT payload FROM attachment WHERE uid = ?" - if getDriverFromEnv() == "postgres" { - query = "SELECT payload FROM attachment WHERE uid = $1" - } - var rawPayload []byte - err := ts.GetDriver().GetDB().QueryRowContext(ctx, query, uid).Scan(&rawPayload) - require.NoError(t, err) - payload := &storepb.AttachmentPayload{} - require.NoError(t, protojson.Unmarshal(rawPayload, payload)) - require.NotNil(t, payload.GetS3Object()) - return payload.GetS3Object() - } - - legacy := find("legacy-s3-no-config") - require.Equal(t, "s3", legacy.GetStorageId()) - require.Nil(t, legacy.GetS3Config()) - - embedded := find("legacy-s3-embedded-config") - require.Empty(t, embedded.GetStorageId(), "embedded namespace must not be rebound to the current storage") - require.Equal(t, "old-bucket", embedded.GetS3Config().GetBucket()) - - named := find("legacy-s3-existing-id") - require.Equal(t, "existing-s3", named.GetStorageId()) -} - -// TestMigrationReactionMemoID verifies that the reaction migration resolves -// legacy memo resource names to internal memo IDs and discards orphaned rows. -func TestMigrationReactionMemoID(t *testing.T) { - ctx := context.Background() - driver := getDriverFromEnv() - skipWithoutLegacySchema(t, driver) - dsn := getTestingProfileForDriver(t, driver).DSN - - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - _, err = db.ExecContext(ctx, legacySchemaFixture(driver)) - require.NoError(t, err) - - basicSetting, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.31.2"}) - require.NoError(t, err) - insertSetting := "INSERT INTO system_setting (name, value, description) VALUES (?, ?, '')" - insertMemo := "INSERT INTO memo (id, uid) VALUES (?, ?)" - insertReaction := "INSERT INTO reaction (id, creator_id, content_id, reaction_type) VALUES (?, ?, ?, ?)" - if driver == "postgres" { - insertSetting = "INSERT INTO system_setting (name, value, description) VALUES ($1, $2, '')" - insertMemo = "INSERT INTO memo (id, uid) VALUES ($1, $2)" - insertReaction = "INSERT INTO reaction (id, creator_id, content_id, reaction_type) VALUES ($1, $2, $3, $4)" - } - _, err = db.ExecContext(ctx, insertSetting, "BASIC", string(basicSetting)) - require.NoError(t, err) - _, err = db.ExecContext(ctx, insertMemo, 42, "reaction-migration-target") - require.NoError(t, err) - _, err = db.ExecContext(ctx, insertReaction, 100, 7, "memos/reaction-migration-target", "valid") - require.NoError(t, err) - _, err = db.ExecContext(ctx, insertReaction, 101, 7, "memos/missing-target", "orphan") - require.NoError(t, err) - if driver == "postgres" { - _, err = db.ExecContext(ctx, "SELECT setval(pg_get_serial_sequence('reaction', 'id'), 101, true)") - require.NoError(t, err) - } - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, driver, dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - - var reactionID, creatorID, memoID int32 - var reactionType string - err = ts.GetDriver().GetDB().QueryRowContext( - ctx, - "SELECT id, creator_id, memo_id, reaction_type FROM reaction", - ).Scan(&reactionID, &creatorID, &memoID, &reactionType) - require.NoError(t, err) - require.Equal(t, int32(100), reactionID) - require.Equal(t, int32(7), creatorID) - require.Equal(t, int32(42), memoID) - require.Equal(t, "valid", reactionType) - - var reactionCount int - err = ts.GetDriver().GetDB().QueryRowContext(ctx, "SELECT COUNT(*) FROM reaction").Scan(&reactionCount) - require.NoError(t, err) - require.Equal(t, 1, reactionCount, "orphaned reactions must be discarded") - - insertNextReaction := "INSERT INTO reaction (creator_id, memo_id, reaction_type) VALUES (?, ?, ?)" - findNextReaction := "SELECT id FROM reaction WHERE creator_id = ? AND memo_id = ? AND reaction_type = ?" - if driver == "postgres" { - insertNextReaction = "INSERT INTO reaction (creator_id, memo_id, reaction_type) VALUES ($1, $2, $3)" - findNextReaction = "SELECT id FROM reaction WHERE creator_id = $1 AND memo_id = $2 AND reaction_type = $3" - } - _, err = ts.GetDriver().GetDB().ExecContext(ctx, insertNextReaction, 8, 42, "after-migration") - require.NoError(t, err) - var nextReactionID int32 - err = ts.GetDriver().GetDB().QueryRowContext(ctx, findNextReaction, 8, 42, "after-migration").Scan(&nextReactionID) - require.NoError(t, err) - require.Equal(t, int32(102), nextReactionID) -} - -// TestMigrationLegacyS3Attachment verifies the storage upgrade path for an -// attachment created before storage IDs existed. The migration must bind the -// payload to the migrated registry entry, after which the production resolver -// and driver must read and delete it through the S3 protocol. -func TestMigrationLegacyS3Attachment(t *testing.T) { - ctx := context.Background() - driver := getDriverFromEnv() - skipWithoutLegacySchema(t, driver) - server := fakes3.New(t, "legacy-attachments") - config := server.Config("legacy-attachments") - content := []byte("attachment uploaded before named storage migration") - const objectKey = "legacy/no-storage-id.txt" - require.NoError(t, server.PutObject(config.Bucket, objectKey, "text/plain", content)) - - storageSetting, err := protojson.Marshal(&storepb.InstanceStorageSetting{ - StorageType: storepb.InstanceStorageSetting_S3, - S3Config: config, - }) - require.NoError(t, err) - attachmentPayload, err := protojson.Marshal(&storepb.AttachmentPayload{ - Payload: &storepb.AttachmentPayload_S3Object_{ - S3Object: &storepb.AttachmentPayload_S3Object{Key: objectKey}, - }, - }) - require.NoError(t, err) - - dsn := getTestingProfileForDriver(t, driver).DSN - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - _, err = db.ExecContext(ctx, legacySchemaFixture(driver)) - require.NoError(t, err) - - basicSetting, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.31.1"}) - require.NoError(t, err) - insertSetting := "INSERT INTO system_setting (name, value, description) VALUES (?, ?, '')" - insertAttachment := "INSERT INTO attachment (uid, creator_id, filename, type, size, storage_type, reference, payload) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" - if driver == "postgres" { - insertSetting = "INSERT INTO system_setting (name, value, description) VALUES ($1, $2, '')" - insertAttachment = "INSERT INTO attachment (uid, creator_id, filename, type, size, storage_type, reference, payload) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)" - } - _, err = db.ExecContext(ctx, insertSetting, "BASIC", string(basicSetting)) - require.NoError(t, err) - _, err = db.ExecContext(ctx, insertSetting, "STORAGE", string(storageSetting)) - require.NoError(t, err) - _, err = db.ExecContext( - ctx, - insertAttachment, - "legacy-s3-object", - 1, - "legacy.txt", - "text/plain", - len(content), - "S3", - "", - string(attachmentPayload), - ) - require.NoError(t, err) - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, driver, dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - - query := "SELECT payload FROM attachment WHERE uid = ?" - if driver == "postgres" { - query = "SELECT payload FROM attachment WHERE uid = $1" - } - var rawPayload []byte - err = ts.GetDriver().GetDB().QueryRowContext(ctx, query, "legacy-s3-object").Scan(&rawPayload) - require.NoError(t, err) - migratedPayload := &storepb.AttachmentPayload{} - require.NoError(t, protojson.Unmarshal(rawPayload, migratedPayload)) - s3Object := migratedPayload.GetS3Object() - require.NotNil(t, s3Object) - require.Equal(t, "s3", s3Object.GetStorageId()) - require.Nil(t, s3Object.GetS3Config()) - - storedSetting, err := ts.GetStoredInstanceSetting(ctx, &store.FindInstanceSetting{Name: storepb.InstanceSettingKey_STORAGE.String()}) - require.NoError(t, err) - require.NotNil(t, storedSetting) - storageDriver, err := ts.ResolveStorageDriver(ctx, storedSetting.GetStorageSetting(), s3Object.StorageId, s3Object.S3Config) - require.NoError(t, err) - downloaded, err := storageDriver.GetObject(ctx, s3Object.Key) - require.NoError(t, err) - require.Equal(t, content, downloaded) - - require.NoError(t, storageDriver.DeleteObject(ctx, s3Object.Key)) - _, err = server.GetObject(config.Bucket, objectKey) - require.Error(t, err, "deleting the migrated attachment must remove its S3 object") -} - -// TestMigrationMemoViewSetting verifies the 0.31 rename of the SHORTCUTS user setting -// to MEMO_VIEWS on every driver, since each one rewrites the stored JSON with its own -// dialect-specific functions. -func TestMigrationMemoViewSetting(t *testing.T) { - ctx := context.Background() - driver := getDriverFromEnv() - skipWithoutLegacySchema(t, driver) - var dsn string - switch driver { - case "sqlite": - dsn = fmt.Sprintf("%s/memos_memo_view_migration.db", t.TempDir()) - case "mysql": - dsn = GetMySQLDSN(t) - case "postgres": - dsn = GetPostgresDSN(t) - default: - t.Fatalf("unsupported driver: %s", driver) - } - - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - - _, err = db.ExecContext(ctx, legacySchemaFixture(driver)) - require.NoError(t, err) - - basicSettingBytes, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.30.1"}) - require.NoError(t, err) - insertBasicSetting := "INSERT INTO system_setting (name, value, description) VALUES ('BASIC', ?, '')" - if driver == "postgres" { - insertBasicSetting = "INSERT INTO system_setting (name, value, description) VALUES ('BASIC', $1, '')" - } - _, err = db.ExecContext(ctx, insertBasicSetting, string(basicSettingBytes)) - require.NoError(t, err) - - settingKeyColumn := "key" - if driver == "mysql" { - settingKeyColumn = "`key`" - } - // Bound rather than inlined: MySQL treats backslash as an escape character inside - // string literals, so an inlined \" would collapse and corrupt the fixture's JSON. - insertSetting := fmt.Sprintf("INSERT INTO user_setting (user_id, %[1]s, value) VALUES (?, ?, ?)", settingKeyColumn) - if driver == "postgres" { - insertSetting = fmt.Sprintf("INSERT INTO user_setting (user_id, %[1]s, value) VALUES ($1, $2, $3)", settingKeyColumn) - } - settingRows := []struct { - userID int - key string - value string - }{ - // A normal legacy row, must be renamed and rewritten. - {1, "SHORTCUTS", `{"shortcuts":[{"id":"work","title":"shortcuts","filter":"tag in [\"work\"]"}]}`}, - // A corrupt value, must be left alone rather than aborting the upgrade. - {2, "SHORTCUTS", `{oops}`}, - // Already has a MEMO_VIEWS row, must not trip UNIQUE(user_id, key). - {3, "SHORTCUTS", `{"shortcuts":[{"id":"old","title":"old","filter":"tag in [\"old\"]"}]}`}, - {3, "MEMO_VIEWS", `{"memoViews":[{"id":"new","title":"new","filter":"tag in [\"new\"]"}]}`}, - {4, "SHORTCUTS", `"scalar"`}, - {5, "SHORTCUTS", `[]`}, - {6, "SHORTCUTS", `null`}, - } - for _, row := range settingRows { - _, err = db.ExecContext(ctx, insertSetting, row.userID, row.key, row.value) - require.NoError(t, err) - } - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, driver, dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - - migratedUserID := int32(1) - setting, err := ts.GetUserSetting(ctx, &store.FindUserSetting{ - UserID: &migratedUserID, - Key: storepb.UserSetting_MEMO_VIEWS, - }) - require.NoError(t, err) - require.NotNil(t, setting) - require.Len(t, setting.GetMemoViews().GetMemoViews(), 1) - require.Equal(t, "work", setting.GetMemoViews().GetMemoViews()[0].GetId()) - require.Equal(t, "shortcuts", setting.GetMemoViews().GetMemoViews()[0].GetTitle()) - require.Equal(t, `tag in ["work"]`, setting.GetMemoViews().GetMemoViews()[0].GetFilter()) - - // Malformed object-like JSON must neither abort the migration nor be renamed. - findCorruptSetting := fmt.Sprintf("SELECT value FROM user_setting WHERE user_id = ? AND %s = ?", settingKeyColumn) - if driver == "postgres" { - findCorruptSetting = fmt.Sprintf("SELECT value FROM user_setting WHERE user_id = $1 AND %s = $2", settingKeyColumn) - } - var corruptValue string - err = ts.GetDriver().GetDB().QueryRowContext(ctx, findCorruptSetting, 2, "SHORTCUTS").Scan(&corruptValue) - require.NoError(t, err) - require.Equal(t, `{oops}`, corruptValue) - for userID, rawValue := range map[int]string{4: `"scalar"`, 5: `[]`, 6: `null`} { - var value string - err = ts.GetDriver().GetDB().QueryRowContext(ctx, findCorruptSetting, userID, "SHORTCUTS").Scan(&value) - require.NoError(t, err) - require.Equal(t, rawValue, value) - } - - // The pre-existing MEMO_VIEWS row wins; the legacy row is left behind untouched. - conflictUserID := int32(3) - conflicting, err := ts.GetUserSetting(ctx, &store.FindUserSetting{ - UserID: &conflictUserID, - Key: storepb.UserSetting_MEMO_VIEWS, - }) - require.NoError(t, err) - require.NotNil(t, conflicting) - require.Len(t, conflicting.GetMemoViews().GetMemoViews(), 1) - require.Equal(t, "new", conflicting.GetMemoViews().GetMemoViews()[0].GetId()) -} - -// TestMigrationCopiesInstanceTagsToUserSettings verifies instance tag metadata is copied into user settings. -func TestMigrationCopiesInstanceTagsToUserSettings(t *testing.T) { - if getDriverFromEnv() != "sqlite" { - t.Skip("skipping focused migration fixture for non-sqlite driver") - } - - ctx := context.Background() - dsn := fmt.Sprintf("%s/memos_tag_migration.db", t.TempDir()) - - db, err := sql.Open("sqlite", dsn) - require.NoError(t, err) - - _, err = db.ExecContext(ctx, legacySchemaFixture("sqlite")) - require.NoError(t, err) - - basicSettingBytes, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.29.1"}) - require.NoError(t, err) - tagsSettingBytes, err := protojson.Marshal(&storepb.InstanceTagsSetting{ - Tags: map[string]*storepb.InstanceTagMetadata{ - "bug": { - BackgroundColor: &colorpb.Color{Red: 0.9, Green: 0.1, Blue: 0.1}, - }, - "private/.*": { - BlurContent: true, - }, - }, - }) - require.NoError(t, err) - existingUserTagsBytes, err := protojson.Marshal(&storepb.TagsUserSetting{ - Tags: map[string]*storepb.UserTagMetadata{ - "existing": { - BlurContent: true, - }, - }, - }) - require.NoError(t, err) - - _, err = db.ExecContext(ctx, "INSERT INTO system_setting (name, value) VALUES ('BASIC', ?), ('TAGS', ?)", string(basicSettingBytes), string(tagsSettingBytes)) - require.NoError(t, err) - _, err = db.ExecContext(ctx, ` - INSERT INTO user (id, username, role, password_hash, avatar_url) - VALUES (1, 'tag-owner', 'USER', 'legacy-hash', ''), (2, 'keeps-existing', 'USER', 'legacy-hash', '') - `) - require.NoError(t, err) - _, err = db.ExecContext(ctx, "INSERT INTO user_setting (user_id, key, value) VALUES (2, 'TAGS', ?)", string(existingUserTagsBytes)) - require.NoError(t, err) - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, "sqlite", dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - - copiedUserID := int32(1) - copied, err := ts.GetUserSetting(ctx, &store.FindUserSetting{ - UserID: &copiedUserID, - Key: storepb.UserSetting_TAGS, - }) - require.NoError(t, err) - require.Contains(t, copied.GetTags().GetTags(), "bug") - bugMetadata := copied.GetTags().GetTags()["bug"] - require.NotNil(t, bugMetadata.GetBackgroundColor()) - require.InDelta(t, 0.9, bugMetadata.GetBackgroundColor().GetRed(), 1e-6) - require.InDelta(t, 0.1, bugMetadata.GetBackgroundColor().GetGreen(), 1e-6) - require.InDelta(t, 0.1, bugMetadata.GetBackgroundColor().GetBlue(), 1e-6) - require.True(t, copied.GetTags().GetTags()["private/.*"].GetBlurContent()) - - existingUserID := int32(2) - existing, err := ts.GetUserSetting(ctx, &store.FindUserSetting{ - UserID: &existingUserID, - Key: storepb.UserSetting_TAGS, - }) - require.NoError(t, err) - require.Contains(t, existing.GetTags().GetTags(), "existing") - require.NotContains(t, existing.GetTags().GetTags(), "bug") -} - -// TestMigrationCaseSensitiveUsername is named to match the smoke workflow's -// -run 'TestMigration|...' filter so its per-driver assertions run on every driver. -func TestMigrationCaseSensitiveUsername(t *testing.T) { - ctx := context.Background() - driver := getDriverFromEnv() - skipWithoutLegacySchema(t, driver) - var dsn string - switch driver { - case "sqlite": - dsn = fmt.Sprintf("%s/memos_username_migration.db", t.TempDir()) - case "mysql": - dsn = GetMySQLDSN(t) - case "postgres": - dsn = GetPostgresDSN(t) - default: - t.Fatalf("unsupported driver: %s", driver) - } - - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - - _, err = db.ExecContext(ctx, legacySchemaFixture(driver)) - require.NoError(t, err) - - basicSettingBytes, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.30.1"}) - require.NoError(t, err) - insertBasicSetting := "INSERT INTO system_setting (name, value, description) VALUES ('BASIC', ?, '')" - if driver == "postgres" { - insertBasicSetting = "INSERT INTO system_setting (name, value, description) VALUES ('BASIC', $1, '')" - } - _, err = db.ExecContext(ctx, insertBasicSetting, string(basicSettingBytes)) - require.NoError(t, err) - insertUser := "INSERT INTO user (username, role, password_hash, avatar_url) VALUES ('Alice', 'USER', 'legacy-hash', '')" - if driver == "mysql" { - insertUser = "INSERT INTO `user` (username, role, password_hash, avatar_url) VALUES ('Alice', 'USER', 'legacy-hash', '')" - } else if driver == "postgres" { - insertUser = `INSERT INTO "user" (username, role, password_hash, avatar_url) VALUES ('Alice', 'USER', 'legacy-hash', '')` - } - _, err = db.ExecContext(ctx, insertUser) - require.NoError(t, err) - insertHighUser := "INSERT INTO user (id, username, role, password_hash, avatar_url) VALUES (100, 'deleted-high-user', 'USER', 'legacy-hash', '')" - deleteHighUser := "DELETE FROM user WHERE id = 100" - if driver == "mysql" { - insertHighUser = "INSERT INTO `user` (id, username, role, password_hash, avatar_url) VALUES (100, 'deleted-high-user', 'USER', 'legacy-hash', '')" - deleteHighUser = "DELETE FROM `user` WHERE id = 100" - } else if driver == "postgres" { - insertHighUser = `INSERT INTO "user" (id, username, role, password_hash, avatar_url) VALUES (100, 'deleted-high-user', 'USER', 'legacy-hash', '')` - deleteHighUser = `DELETE FROM "user" WHERE id = 100` - } - _, err = db.ExecContext(ctx, insertHighUser) - require.NoError(t, err) - _, err = db.ExecContext(ctx, deleteHighUser) - require.NoError(t, err) - if driver == "postgres" { - _, err = db.ExecContext(ctx, `SELECT setval(pg_get_serial_sequence('"user"', 'id'), 100, true)`) - require.NoError(t, err) - } - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, driver, dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - - lower, err := createTestingUserWithRole(ctx, ts, "alice", store.RoleUser) - require.NoError(t, err) - require.Equal(t, int32(101), lower.ID) - - upperUsername := "Alice" - upper, err := ts.GetUser(ctx, &store.FindUser{Username: &upperUsername}) - require.NoError(t, err) - require.NotEqual(t, upper.ID, lower.ID) - require.Equal(t, "Alice", upper.Username) -} - -// skipWithoutLegacySchema skips migration tests that start from a pre-0.31 -// schema on drivers introduced after it, which have no legacy layout to migrate. -func skipWithoutLegacySchema(t *testing.T, driver string) { - t.Helper() - if driver == "d1" { - t.Skip("D1 databases start at the current schema; there is no legacy schema to migrate") - } -} - -func legacySchemaFixture(driver string) string { - switch driver { - case "mysql": - return ` - CREATE TABLE system_setting ( - name VARCHAR(256) NOT NULL PRIMARY KEY, - value LONGTEXT NOT NULL, - description TEXT NOT NULL - ); - CREATE TABLE ` + "`user`" + ` ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - created_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - row_status VARCHAR(256) NOT NULL DEFAULT 'NORMAL', - username VARCHAR(256) NOT NULL UNIQUE, - role VARCHAR(256) NOT NULL DEFAULT 'USER', - email VARCHAR(256) NOT NULL DEFAULT '', - nickname VARCHAR(256) NOT NULL DEFAULT '', - password_hash VARCHAR(256) NOT NULL, - avatar_url LONGTEXT NOT NULL, - description VARCHAR(256) NOT NULL DEFAULT '' - ); - CREATE TABLE user_setting ( - user_id INT NOT NULL, - ` + "`key`" + ` VARCHAR(256) NOT NULL, - value LONGTEXT NOT NULL, - UNIQUE(user_id, ` + "`key`" + `) - ); - CREATE TABLE memo ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - uid VARCHAR(256) NOT NULL UNIQUE, - creator_id INT NOT NULL DEFAULT 0, - created_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - row_status VARCHAR(256) NOT NULL DEFAULT 'NORMAL', - content TEXT NOT NULL DEFAULT (''), - visibility VARCHAR(256) NOT NULL DEFAULT 'PRIVATE', - pinned BOOLEAN NOT NULL DEFAULT FALSE, - payload JSON NOT NULL DEFAULT (JSON_OBJECT()) - ); - CREATE TABLE memo_relation ( - memo_id INT NOT NULL, - related_memo_id INT NOT NULL, - type VARCHAR(256) NOT NULL, - UNIQUE(memo_id, related_memo_id, type) - ); - CREATE TABLE reaction ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - created_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - creator_id INT NOT NULL, - content_id VARCHAR(256) NOT NULL, - reaction_type VARCHAR(256) NOT NULL, - UNIQUE(creator_id, content_id, reaction_type) - ); - CREATE TABLE attachment ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - uid VARCHAR(256) NOT NULL UNIQUE, - creator_id INT NOT NULL, - created_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - filename TEXT NOT NULL, - type VARCHAR(256) NOT NULL DEFAULT '', - size INT NOT NULL DEFAULT 0, - memo_id INT DEFAULT NULL, - storage_type VARCHAR(256) NOT NULL DEFAULT '', - reference TEXT NOT NULL, - payload TEXT NOT NULL - ); - ` - case "postgres": - return ` - CREATE TABLE system_setting ( - name TEXT NOT NULL PRIMARY KEY, - value TEXT NOT NULL, - description TEXT NOT NULL - ); - CREATE TABLE "user" ( - id SERIAL PRIMARY KEY, - created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - row_status TEXT NOT NULL DEFAULT 'NORMAL', - username TEXT NOT NULL UNIQUE, - role TEXT NOT NULL DEFAULT 'USER', - email TEXT NOT NULL DEFAULT '', - nickname TEXT NOT NULL DEFAULT '', - password_hash TEXT NOT NULL, - avatar_url TEXT NOT NULL, - description TEXT NOT NULL DEFAULT '' - ); - CREATE TABLE user_setting ( - user_id INTEGER NOT NULL, - key TEXT NOT NULL, - value TEXT NOT NULL, - UNIQUE(user_id, key) - ); - CREATE TABLE memo ( - id SERIAL PRIMARY KEY, - uid TEXT NOT NULL UNIQUE, - creator_id INTEGER NOT NULL DEFAULT 0, - created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - row_status TEXT NOT NULL DEFAULT 'NORMAL', - content TEXT NOT NULL DEFAULT '', - visibility TEXT NOT NULL DEFAULT 'PRIVATE', - pinned BOOLEAN NOT NULL DEFAULT FALSE, - payload JSONB NOT NULL DEFAULT '{}' - ); - CREATE TABLE memo_relation ( - memo_id INTEGER NOT NULL, - related_memo_id INTEGER NOT NULL, - type TEXT NOT NULL, - UNIQUE(memo_id, related_memo_id, type) - ); - CREATE TABLE reaction ( - id SERIAL PRIMARY KEY, - created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - creator_id INTEGER NOT NULL, - content_id TEXT NOT NULL, - reaction_type TEXT NOT NULL, - UNIQUE(creator_id, content_id, reaction_type) - ); - CREATE TABLE attachment ( - id SERIAL PRIMARY KEY, - uid TEXT NOT NULL UNIQUE, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), - filename TEXT NOT NULL, - blob BYTEA, - type TEXT NOT NULL DEFAULT '', - size INTEGER NOT NULL DEFAULT 0, - memo_id INTEGER DEFAULT NULL, - storage_type TEXT NOT NULL DEFAULT '', - reference TEXT NOT NULL DEFAULT '', - payload TEXT NOT NULL DEFAULT '{}' - ); - ` - case "sqlite": - return ` - CREATE TABLE system_setting ( - name TEXT NOT NULL, - value TEXT NOT NULL, - description TEXT NOT NULL DEFAULT '', - UNIQUE(name) - ); - CREATE TABLE user ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - username TEXT NOT NULL UNIQUE, - role TEXT NOT NULL DEFAULT 'USER', - email TEXT NOT NULL DEFAULT '', - nickname TEXT NOT NULL DEFAULT '', - password_hash TEXT NOT NULL, - avatar_url TEXT NOT NULL DEFAULT '', - description TEXT NOT NULL DEFAULT '' - ); - CREATE TABLE user_setting ( - user_id INTEGER NOT NULL, - key TEXT NOT NULL, - value TEXT NOT NULL, - UNIQUE(user_id, key) - ); - CREATE TABLE memo ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - uid TEXT NOT NULL UNIQUE, - creator_id INTEGER NOT NULL DEFAULT 0, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', - content TEXT NOT NULL DEFAULT '', - visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE', - pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0, - payload TEXT NOT NULL DEFAULT '{}' - ); - CREATE TABLE memo_relation ( - memo_id INTEGER NOT NULL, - related_memo_id INTEGER NOT NULL, - type TEXT NOT NULL, - UNIQUE(memo_id, related_memo_id, type) - ); - CREATE TABLE reaction ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - creator_id INTEGER NOT NULL, - content_id TEXT NOT NULL, - reaction_type TEXT NOT NULL, - UNIQUE(creator_id, content_id, reaction_type) - ); - CREATE TABLE attachment ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - uid TEXT NOT NULL UNIQUE, - creator_id INTEGER NOT NULL, - created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')), - filename TEXT NOT NULL DEFAULT '', - blob BLOB DEFAULT NULL, - type TEXT NOT NULL DEFAULT '', - size INTEGER NOT NULL DEFAULT 0, - memo_id INTEGER, - storage_type TEXT NOT NULL DEFAULT '', - reference TEXT NOT NULL DEFAULT '', - payload TEXT NOT NULL DEFAULT '{}' - ); - ` - default: - return "" - } -} - -// TestMigrationFromStableVersion verifies that upgrading from a stable Memos version -// to the current version works correctly. This is the critical upgrade path test. -// -// Test flow: -// 1. Start a stable Memos container to create a database with the old schema -// 2. Stop the container and wait for cleanup -// 3. Use the store directly to run migration with current code -// 4. Verify the migration succeeded and data can be written -// -// Note: This test is skipped when running with -race flag because testcontainers -// has known race conditions in its reaper code that are outside our control. -func TestMigrationFromStableVersion(t *testing.T) { - // Skip for non-SQLite drivers (simplifies the test) - if getDriverFromEnv() != "sqlite" { - t.Skip("skipping upgrade test for non-sqlite driver") - } - - skipIfContainerProviderUnavailable(t) - - ctx := context.Background() - dataDir := t.TempDir() - - // 1. Start stable Memos container to create database with old schema - cfg := MemosContainerConfig{ - Driver: "sqlite", - DataDir: dataDir, - Version: StableMemosVersion, - } - - t.Logf("Starting Memos %s container to create old-schema database...", cfg.Version) - container, err := StartMemosContainer(ctx, cfg) - require.NoError(t, err, "failed to start stable memos container") - - // Wait for the container to fully initialize the database - time.Sleep(10 * time.Second) - - // Stop the container gracefully - t.Log("Stopping stable Memos container...") - err = container.Terminate(ctx) - require.NoError(t, err, "failed to stop memos container") - - // Wait for file handles to be released - time.Sleep(2 * time.Second) - - // 2. Connect to the database directly and run migration with current code - dsn := fmt.Sprintf("%s/memos_prod.db", dataDir) - t.Logf("Connecting to database at %s...", dsn) - - ts := NewTestingStoreWithDSN(ctx, t, "sqlite", dsn) - - // Get the schema version before migration - oldSetting, err := ts.GetInstanceBasicSetting(ctx) - require.NoError(t, err) - t.Logf("Old schema version: %s", oldSetting.SchemaVersion) - - // 3. Run migration with current code - t.Log("Running migration with current code...") - err = ts.Migrate(ctx) - require.NoError(t, err, "migration from stable version should succeed") - - // 4. Verify migration succeeded - newVersion, err := ts.GetCurrentSchemaVersion() - require.NoError(t, err) - t.Logf("New schema version: %s", newVersion) - - newSetting, err := ts.GetInstanceBasicSetting(ctx) - require.NoError(t, err) - require.Equal(t, newVersion, newSetting.SchemaVersion, "schema version should be updated") - - // Verify we can write data to the migrated database - user, err := createTestingHostUser(ctx, ts) - require.NoError(t, err, "should create user after migration") - - memo, err := ts.CreateMemo(ctx, &store.Memo{ - UID: "post-upgrade-memo", - CreatorID: user.ID, - Content: "Content after upgrade from stable", - Visibility: store.Public, - }) - require.NoError(t, err, "should create memo after migration") - require.Equal(t, "Content after upgrade from stable", memo.Content) - - t.Logf("Migration successful: %s -> %s", oldSetting.SchemaVersion, newVersion) -} diff --git a/store/test/migrator_unique_email_test.go b/store/test/migrator_unique_email_test.go deleted file mode 100644 index 163587bad..000000000 --- a/store/test/migrator_unique_email_test.go +++ /dev/null @@ -1,144 +0,0 @@ -package test - -import ( - "context" - "database/sql" - "fmt" - "testing" - - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/encoding/protojson" - - storepb "github.com/usememos/memos/proto/gen/store" - "github.com/usememos/memos/store" -) - -// TestMigrationUniqueEmail drives 0.31/07__unique_email.sql, together with the -// migrator's Go-side canonicalization pass, against a pre-0.31 schema holding -// the cases the migration must resolve: mixed-case and non-ASCII duplicates, -// surrounding whitespace, empty values, display-name forms, and values that -// are not addresses. -func TestMigrationUniqueEmail(t *testing.T) { - ctx := context.Background() - driver := getDriverFromEnv() - skipWithoutLegacySchema(t, driver) - var dsn string - switch driver { - case "sqlite": - dsn = fmt.Sprintf("%s/memos_email_migration.db", t.TempDir()) - case "mysql": - dsn = GetMySQLDSN(t) - case "postgres": - dsn = GetPostgresDSN(t) - default: - t.Fatalf("unsupported driver: %s", driver) - } - - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - - _, err = db.ExecContext(ctx, legacySchemaFixture(driver)) - require.NoError(t, err) - - basicSettingBytes, err := protojson.Marshal(&storepb.InstanceBasicSetting{SchemaVersion: "0.30.1"}) - require.NoError(t, err) - insertBasicSetting := "INSERT INTO system_setting (name, value, description) VALUES ('BASIC', ?, '')" - if driver == "postgres" { - insertBasicSetting = "INSERT INTO system_setting (name, value, description) VALUES ('BASIC', $1, '')" - } - _, err = db.ExecContext(ctx, insertBasicSetting, string(basicSettingBytes)) - require.NoError(t, err) - - userTable := "user" - switch driver { - case "mysql": - userTable = "`user`" - case "postgres": - userTable = `"user"` - default: - } - insertUser := func(id int, username, email string) { - t.Helper() - stmt := fmt.Sprintf("INSERT INTO %s (id, username, role, email, password_hash, avatar_url) VALUES (%d, '%s', 'USER', '%s', 'legacy-hash', '')", userTable, id, username, email) - _, err := db.ExecContext(ctx, stmt) - require.NoError(t, err) - } - insertUser(1, "alice-upper", "Alice@Example.com") - insertUser(2, "alice-spaced", " alice@example.com ") - insertUser(3, "alice-lower", "alice@example.com") - insertUser(4, "bob", "bob@example.com") - insertUser(5, "no-address", "") - insertUser(6, "junk", "not-an-address") - insertUser(7, "umlaut-upper", "Ä@EXAMPLE.COM") - insertUser(8, "umlaut-lower", "ä@example.com") - insertUser(9, "display-name", "Carol ") - insertUser(10, "inner-space", "jo hn@example.com") - insertUser(100, "deleted-high-user", "gone@example.com") - _, err = db.ExecContext(ctx, fmt.Sprintf("DELETE FROM %s WHERE id = 100", userTable)) - require.NoError(t, err) - if driver == "postgres" { - _, err = db.ExecContext(ctx, `SELECT setval(pg_get_serial_sequence('"user"', 'id'), 100, true)`) - require.NoError(t, err) - } - require.NoError(t, db.Close()) - - ts := NewTestingStoreWithDSN(ctx, t, driver, dsn) - require.NoError(t, ts.Migrate(ctx)) - defer ts.Close() - - emailOf := func(id int32) string { - t.Helper() - user, err := ts.GetUser(ctx, &store.FindUser{ID: &id}) - require.NoError(t, err) - require.NotNil(t, user, "user %d should survive the migration", id) - return user.Email - } - require.Equal(t, "alice@example.com", emailOf(1), "the oldest account keeps the address") - require.Equal(t, "", emailOf(2), "a later duplicate is cleared") - require.Equal(t, "", emailOf(3), "a later duplicate is cleared") - require.Equal(t, "bob@example.com", emailOf(4)) - require.Equal(t, "", emailOf(5)) - require.Equal(t, "", emailOf(6), "a value without '@' is cleared") - require.Equal(t, "ä@example.com", emailOf(7), "non-ASCII uppercase is folded before deduplication") - require.Equal(t, "", emailOf(8), "the Unicode-folded duplicate is cleared") - require.Equal(t, "", emailOf(9), "a display-name form is cleared") - require.Equal(t, "", emailOf(10), "interior whitespace is cleared") - - // The index is in place and case folding applies to lookups and writes. - lookup := "ALICE@EXAMPLE.COM" - holder, err := ts.GetUser(ctx, &store.FindUser{Email: &lookup}) - require.NoError(t, err) - require.NotNil(t, holder) - require.Equal(t, int32(1), holder.ID) - - // IDs issued before the migration, including deleted ones, are never reused. - // This runs before any failing insert because MySQL and PostgreSQL consume - // an auto-increment value even when the insert is rejected. - created, err := ts.CreateUser(ctx, &store.User{Username: "post-migration", Role: store.RoleUser, Email: ""}) - require.NoError(t, err) - require.Equal(t, int32(101), created.ID) - - _, err = ts.CreateUser(ctx, &store.User{Username: "alice-again", Role: store.RoleUser, Email: "Alice@example.com"}) - require.ErrorIs(t, err, store.ErrEmailTaken) - - umlautLookup := "Ä@example.com" - umlautHolder, err := ts.GetUser(ctx, &store.FindUser{Email: ¨autLookup}) - require.NoError(t, err) - require.NotNil(t, umlautHolder) - require.Equal(t, int32(7), umlautHolder.ID) - _, err = ts.CreateUser(ctx, &store.User{Username: "umlaut-again", Role: store.RoleUser, Email: "Ä@EXAMPLE.COM"}) - require.ErrorIs(t, err, store.ErrEmailTaken) - - // The bare form of the cleared display-name value is free to claim. - carol, err := ts.CreateUser(ctx, &store.User{Username: "carol-bare", Role: store.RoleUser, Email: "carol@example.com"}) - require.NoError(t, err) - require.Equal(t, "carol@example.com", carol.Email) - - // Users without an address never conflict with one another. - another, err := ts.CreateUser(ctx, &store.User{Username: "post-migration-2", Role: store.RoleUser, Email: ""}) - require.NoError(t, err) - require.Equal(t, "", another.Email) - - // Re-running the migrator is a no-op. - require.NoError(t, ts.Migrate(ctx)) -} diff --git a/store/test/migrator_upgrade_test.go b/store/test/migrator_upgrade_test.go index 9bdd96c6d..86663546e 100644 --- a/store/test/migrator_upgrade_test.go +++ b/store/test/migrator_upgrade_test.go @@ -1,127 +1,12 @@ package test import ( - "context" - "database/sql" "fmt" - "strings" "testing" - "time" - "github.com/pkg/errors" "github.com/stretchr/testify/require" - - storepb "github.com/usememos/memos/proto/gen/store" - "github.com/usememos/memos/store" ) -func TestMigrationFromV0262PreservesLegacyData(t *testing.T) { - if testing.Short() { - t.Skip("skipping container-based upgrade test in short mode") - } - skipIfContainerProviderUnavailable(t) - - ctx := context.Background() - driver := getDriverFromEnv() - - cfg, hostDSN := prepareV0262MigrationTest(t, driver) - t.Logf("Starting Memos %s container for %s schema bootstrap...", cfg.Version, driver) - container, err := StartMemosContainer(ctx, cfg) - require.NoError(t, err, "failed to start v0.26.2 memos container") - t.Cleanup(func() { - if container != nil { - _ = container.Terminate(ctx) - } - }) - - legacyStore := NewTestingStoreWithDSN(ctx, t, driver, hostDSN) - require.Eventually(t, func() bool { - setting, err := legacyStore.GetInstanceBasicSetting(ctx) - return err == nil && setting != nil && setting.SchemaVersion != "" - }, 45*time.Second, 500*time.Millisecond, "legacy schema should be initialized by old container") - - settingBeforeSeed, err := legacyStore.GetInstanceBasicSetting(ctx) - require.NoError(t, err) - t.Logf("Legacy schema version before migration: %s", settingBeforeSeed.SchemaVersion) - - err = container.Terminate(ctx) - require.NoError(t, err, "failed to stop v0.26.2 memos container") - container = nil - - db := openMigrationSQLDB(t, driver, hostDSN) - defer db.Close() - - seedLegacyMigrationData(ctx, t, driver, db) - - count, err := countSystemSetting(ctx, db, "STORAGE") - require.NoError(t, err) - require.Zero(t, count, "v0.26.2 database should not have a STORAGE setting before migration") - - ts := NewTestingStoreWithDSN(ctx, t, driver, hostDSN) - err = ts.Migrate(ctx) - require.NoError(t, err, "migration from v0.26.2 should succeed for %s", driver) - - currentVersion, err := ts.GetCurrentSchemaVersion() - require.NoError(t, err) - currentSetting, err := ts.GetInstanceBasicSetting(ctx) - require.NoError(t, err) - require.Equal(t, currentVersion, currentSetting.SchemaVersion, "schema version should be updated") - - storageSetting, err := ts.GetInstanceStorageSetting(ctx) - require.NoError(t, err) - require.Equal(t, storepb.InstanceStorageSetting_DATABASE, storageSetting.StorageType, "existing installs should stay on DATABASE storage") - - idps, err := ts.ListIdentityProviders(ctx, &store.FindIdentityProvider{}) - require.NoError(t, err) - require.Len(t, idps, 2) - idpUIDsByName := map[string]string{} - for _, idp := range idps { - idpUIDsByName[idp.Name] = idp.Uid - } - require.Equal(t, "00000191", idpUIDsByName["Legacy Google"]) - require.Equal(t, "00000192", idpUIDsByName["Legacy GitHub"]) - - inboxes, err := ts.ListInboxes(ctx, &store.FindInbox{}) - require.NoError(t, err) - require.Len(t, inboxes, 1) - require.NotNil(t, inboxes[0].Message) - require.Equal(t, storepb.InboxMessage_MEMO_COMMENT, inboxes[0].Message.Type) - require.Equal(t, int32(102), inboxes[0].Message.GetMemoComment().MemoId) - require.Equal(t, int32(101), inboxes[0].Message.GetMemoComment().RelatedMemoId) - - activityExists, err := tableExists(ctx, db, driver, "activity") - require.NoError(t, err) - require.False(t, activityExists, "activity table should be removed after migration") - - memoShareExists, err := tableExists(ctx, db, driver, "memo_share") - require.NoError(t, err) - require.True(t, memoShareExists, "memo_share table should be created") - - share, err := ts.CreateMemoShare(ctx, &store.MemoShare{ - UID: "post-upgrade-share", - MemoID: 101, - CreatorID: 11, - }) - require.NoError(t, err) - require.Equal(t, "post-upgrade-share", share.UID) - - postUpgradeUser, err := createTestingUserWithRole(ctx, ts, "postupgrade", store.RoleUser) - require.NoError(t, err) - postUpgradeMemo, err := ts.CreateMemo(ctx, &store.Memo{ - UID: "post-upgrade-memo-v0262", - CreatorID: postUpgradeUser.ID, - Content: "created after v0.26.2 migration", - Visibility: store.Public, - }) - require.NoError(t, err) - require.Equal(t, "created after v0.26.2 migration", postUpgradeMemo.Content) -} - -func prepareV0262MigrationTest(t *testing.T, driver string) (MemosContainerConfig, string) { - t.Helper() - return prepareUpgradeFixture(t, driver, "0.26.2") -} - // prepareUpgradeFixture returns the container config needed to bootstrap a real // schema for the given Memos version, plus the DSN the host uses to reach it. func prepareUpgradeFixture(t *testing.T, driver, version string) (MemosContainerConfig, string) { @@ -161,119 +46,3 @@ func prepareUpgradeFixture(t *testing.T, driver, version string) (MemosContainer return MemosContainerConfig{}, "" } } - -func openMigrationSQLDB(t *testing.T, driver, dsn string) *sql.DB { - t.Helper() - - db, err := sql.Open(driver, dsn) - require.NoError(t, err) - require.NoError(t, db.Ping()) - return db -} - -func seedLegacyMigrationData(ctx context.Context, t *testing.T, driver string, db *sql.DB) { - t.Helper() - - execMigrationSQL(t, db, legacyInsertUserSQL(driver, 11, "owner")) - execMigrationSQL(t, db, legacyInsertUserSQL(driver, 12, "commenter")) - execMigrationSQL(t, db, legacyInsertMemoSQL(101, 11, "legacy-parent", "parent memo")) - execMigrationSQL(t, db, legacyInsertMemoSQL(102, 12, "legacy-comment", "comment memo")) - execMigrationSQL(t, db, legacyInsertActivitySQL(201, 12)) - execMigrationSQL(t, db, legacyInsertInboxSQL(301, 12, 11, 201)) - execMigrationSQL(t, db, legacyInsertIDPSQL(401, "Legacy Google")) - execMigrationSQL(t, db, legacyInsertIDPSQL(402, "Legacy GitHub")) - - var message string - err := db.QueryRowContext(ctx, "SELECT message FROM inbox WHERE id = 301").Scan(&message) - require.NoError(t, err) - require.Contains(t, message, "\"activityId\":201") - require.NotContains(t, message, "\"memoComment\"") -} - -func execMigrationSQL(t *testing.T, db *sql.DB, query string) { - t.Helper() - _, err := db.Exec(query) - require.NoError(t, err, "failed to execute SQL: %s", query) -} - -func legacyInsertUserSQL(driver string, id int, username string) string { - table := "user" - switch driver { - case "mysql": - table = "`user`" - case "postgres", "sqlite": - table = `"user"` - default: - // Keep the unquoted fallback for unknown test drivers. - } - - return fmt.Sprintf( - "INSERT INTO %s (id, username, role, email, nickname, password_hash, avatar_url, description) VALUES (%d, '%s', 'USER', '%s@example.com', '%s', 'legacy-hash', '', 'legacy user')", - table, id, username, username, username, - ) -} - -func legacyInsertMemoSQL(id, creatorID int, uid, content string) string { - payload := "{}" - return fmt.Sprintf( - "INSERT INTO memo (id, uid, creator_id, content, visibility, payload) VALUES (%d, '%s', %d, '%s', 'PRIVATE', '%s')", - id, uid, creatorID, content, payload, - ) -} - -func legacyInsertActivitySQL(id, creatorID int) string { - payload := `{"memoComment":{"memoId":102,"relatedMemoId":101}}` - return fmt.Sprintf( - "INSERT INTO activity (id, creator_id, type, level, payload) VALUES (%d, %d, 'MEMO_COMMENT', 'INFO', '%s')", - id, creatorID, payload, - ) -} - -func legacyInsertInboxSQL(id, senderID, receiverID, activityID int) string { - message := fmt.Sprintf(`{"type":"MEMO_COMMENT","activityId":%d}`, activityID) - return fmt.Sprintf( - "INSERT INTO inbox (id, sender_id, receiver_id, status, message) VALUES (%d, %d, %d, 'UNREAD', '%s')", - id, senderID, receiverID, message, - ) -} - -func legacyInsertIDPSQL(id int, name string) string { - config := `{"clientId":"legacy-client","clientSecret":"legacy-secret","authUrl":"https://example.com/auth","tokenUrl":"https://example.com/token","userInfoUrl":"https://example.com/userinfo"}` - return fmt.Sprintf( - "INSERT INTO idp (id, name, type, identifier_filter, config) VALUES (%d, '%s', 'OAUTH2', '', '%s')", - id, name, config, - ) -} - -func countSystemSetting(ctx context.Context, db *sql.DB, name string) (int, error) { - var count int - err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM system_setting WHERE name = ?", name).Scan(&count) - if err == nil { - return count, nil - } - - err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM system_setting WHERE name = $1", name).Scan(&count) - return count, err -} - -func tableExists(ctx context.Context, db *sql.DB, driver, table string) (bool, error) { - switch driver { - case "sqlite": - var name string - err := db.QueryRowContext(ctx, "SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?", table).Scan(&name) - if err == sql.ErrNoRows { - return false, nil - } - return err == nil, err - case "mysql": - var count int - err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?", table).Scan(&count) - return count > 0, err - case "postgres": - var regclass sql.NullString - err := db.QueryRowContext(ctx, "SELECT to_regclass($1)", "public."+table).Scan(®class) - return regclass.Valid && strings.EqualFold(regclass.String, table), err - default: - return false, errors.Errorf("unsupported driver: %s", driver) - } -} diff --git a/store/test/space_payload_test.go b/store/test/space_payload_test.go index 21c67c205..1884ae9e1 100644 --- a/store/test/space_payload_test.go +++ b/store/test/space_payload_test.go @@ -52,35 +52,3 @@ func TestSpacePayloadRoundTrip(t *testing.T) { require.NoError(t, ts.GetDriver().GetDB().QueryRowContext(ctx, "SELECT payload FROM space WHERE uid = 'icon-space'").Scan(&raw)) require.JSONEq(t, `{}`, raw) } - -func TestMigrationSpacePayloadBackfillsDefault(t *testing.T) { - ctx := context.Background() - skipWithoutLegacySchema(t, getDriverFromEnv()) - ts := NewTestingStore(ctx, t) - defer ts.Close() - owner, err := createTestingHostUser(ctx, ts) - require.NoError(t, err) - space, err := ts.CreateSpace(ctx, &store.Space{UID: "legacy-space", Title: "Legacy"}, owner.ID) - require.NoError(t, err) - require.NotNil(t, space.Payload) - require.Nil(t, space.Payload.Icon) - _, err = ts.GetDriver().GetDB().ExecContext(ctx, "ALTER TABLE space DROP COLUMN payload") - require.NoError(t, err) - setting, err := ts.GetInstanceBasicSetting(ctx) - require.NoError(t, err) - setting.SchemaVersion = "0.31.6" - _, err = ts.UpsertInstanceSetting(ctx, &storepb.InstanceSetting{ - Key: storepb.InstanceSettingKey_BASIC, - Value: &storepb.InstanceSetting_BasicSetting{BasicSetting: setting}, - }) - require.NoError(t, err) - require.NoError(t, ts.Migrate(ctx)) - space, err = ts.GetSpace(ctx, &store.FindSpace{ID: &space.ID}) - require.NoError(t, err) - require.Equal(t, "Legacy", space.Title) - require.NotNil(t, space.Payload) - require.Nil(t, space.Payload.Icon) - var raw string - require.NoError(t, ts.GetDriver().GetDB().QueryRowContext(ctx, "SELECT payload FROM space WHERE uid = 'legacy-space'").Scan(&raw)) - require.JSONEq(t, `{}`, raw) -} diff --git a/web/src/lib/release-version.ts b/web/src/lib/release-version.ts new file mode 100644 index 000000000..3b953d0d3 --- /dev/null +++ b/web/src/lib/release-version.ts @@ -0,0 +1,8 @@ +// Release links accept current calendar versions and historical 0.x releases. +const isReleaseVersion = (version: string): boolean => + /^(?:[1-9]\d\.(?:0[1-9]|1[0-2])(?:\.[1-9]\d*)?|0\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(?:-rc\.[1-9]\d*)?$/.test(version); + +export const getReleaseTag = (version: string): string | undefined => { + if (!isReleaseVersion(version)) return undefined; + return version.startsWith("0.") ? `v${version}` : version; +}; diff --git a/web/src/pages/About.tsx b/web/src/pages/About.tsx index 22db304b8..6f90d9a39 100644 --- a/web/src/pages/About.tsx +++ b/web/src/pages/About.tsx @@ -8,17 +8,17 @@ import { MEMOS_WEBSITE_URL, WEB_CLIPPER_URL, } from "@/lib/constants"; +import { getReleaseTag } from "@/lib/release-version"; import { useTranslate } from "@/utils/i18n"; const GITHUB_COMMIT_URL_PREFIX = "https://github.com/usememos/memos/commit/"; -const GITHUB_RELEASE_URL_PREFIX = "https://github.com/usememos/memos/releases/tag/v"; +const GITHUB_RELEASE_URL_PREFIX = "https://github.com/usememos/memos/releases/tag/"; const DEFAULT_TITLE = "Memos"; const DEFAULT_TAGLINE = "Capture first. Keep it yours."; const DEFAULT_LOGO = "/logo.webp"; const isCommitSha = (commit: string) => /^[0-9a-f]{7,40}$/i.test(commit); -const isSemver = (version: string) => /^\d+\.\d+\.\d+/.test(version); const Chip = ({ href, children }: { href?: string; children: React.ReactNode }) => { const className = "inline-flex items-center rounded-full bg-muted px-2.5 py-0.5 font-mono text-xs text-muted-foreground"; @@ -46,9 +46,9 @@ const About = () => { const instanceLogo = customProfile?.logoUrl || DEFAULT_LOGO; const isCustomBranded = instanceTitle !== DEFAULT_TITLE; - const hasSemver = isSemver(profile.version); - const releaseUrl = hasSemver ? `${GITHUB_RELEASE_URL_PREFIX}${profile.version}` : ""; - const versionLabel = hasSemver ? `v${profile.version}` : profile.version; + const releaseTag = getReleaseTag(profile.version); + const releaseUrl = releaseTag ? `${GITHUB_RELEASE_URL_PREFIX}${releaseTag}` : ""; + const versionLabel = releaseTag ?? profile.version; const hasCommitSha = isCommitSha(profile.commit); const commitUrl = hasCommitSha ? `${GITHUB_COMMIT_URL_PREFIX}${profile.commit}` : ""; const shortCommit = hasCommitSha ? profile.commit.slice(0, 7) : ""; diff --git a/web/tests/release-version.test.ts b/web/tests/release-version.test.ts new file mode 100644 index 000000000..e159f3fa4 --- /dev/null +++ b/web/tests/release-version.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from "vitest"; +import { getReleaseTag } from "@/lib/release-version"; + +describe("release version links", () => { + it.each(["26.09", "26.09.1", "26.09.10", "26.09-rc.1", "26.09.1-rc.2", "27.01", "0.31.0", "0.31.0-rc.2"])("links release %s", (version) => + expect(getReleaseTag(version)).toBe(version.startsWith("0.") ? `v${version}` : version)); + + it.each([ + "dev", + "manual-abcdef0", + "v26.09", + "26.9", + "26.00", + "26.13", + "26.09.0", + "26.09.01", + "26.09-rc.0", + "26.09extra", + "0.31.0oops", + ])("does not link non-release %s", (version) => expect(getReleaseTag(version)).toBeUndefined()); +});