Skip to content

fix: store the Docker SQLite database under STORAGE_DIR - #7345

Open
xixi-box wants to merge 1 commit into
Mintplex-Labs:masterfrom
xixi-box:fix/issue-7344-b014470-3d11e985
Open

xixi-box wants to merge 1 commit into
Mintplex-Labs:masterfrom
xixi-box:fix/issue-7344-b014470-3d11e985

Conversation

@xixi-box

Copy link
Copy Markdown

Fixes #7344

Pull Request Type

  • ✨ feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #7344

Description

Prisma used a hardcoded path under /app/server/storage. Docker deployments with a custom STORAGE_DIR mount wrote their SQLite database to the container filesystem and lost access to it when the container was recreated.

The standard Docker entrypoint resolves STORAGE_DIR from the environment or the mounted server .env and passes one database URL to Prisma migrations and the server. The schema-local fallback uses the original path for direct Prisma commands and startup with an unset STORAGE_DIR.

Visuals (if applicable)

Additional Information

An existing database still present in an older container can be copied into the configured storage directory before upgrading a deployment with a custom mount.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

Tests: npm run test -- --runInBand --runTestsByPath server/__tests__/prisma/dockerStorage.test.js.
Result: npm run test -- --runInBand --runTestsByPath server/tests/prisma/dockerStorage.test.js (base sources with the final regression file): exit 1, two wrong-path assertions and two passing default cases. See OSSCOUT_BASE.log.
Result: npm run test -- --runInBand --runTestsByPath server/tests/prisma/dockerStorage.test.js (patched): exit 0, all four cases passed. See OSSCOUT_PATCHED.log.
Result: npm run test -- --runInBand --silent --runTestsByPath server/tests/models/systemPromptVariables.test.js server/tests/models/memory.test.js server/tests/utils/chats/chatHistoryReset.test.js server/tests/endpoints/mobile/utils/index.test.js (patched): 96 tests across four suites passed.
Result: npm run test -- --runInBand --silent --runTestsByPath server/tests/models/systemPromptVariables.test.js server/tests/models/modelRouter.test.js server/tests/models/memory.test.js server/tests/utils/chats/chatHistoryReset.test.js server/tests/endpoints/mobile/utils/index.test.js (base): 96 tests across four suites passed. ModelRouter failed to load because the scoped dependency install lacked openai.
Result: docker build --build-context deps=../osscout-deps --build-context probe=../osscout-container -f ../osscout-container/Dockerfile -t anythingllm-osscout-7344 .: passed and verified that the Prisma fallback file was included in the build context.
Result: docker run --rm --mount "type=bind,src=$osscout_mount,dst=/data/anythingllm" -e STORAGE_DIR=/data/anythingllm anythingllm-osscout-7344: passed twice using a shared temporary bind mount. The database file existed on the host. The first container reported previous=null and the second reported previous=persisted from /data/anythingllm/anythingllm.db.
Result: docker run --rm --entrypoint bash anythingllm-osscout-7344 -c 'cd /app/server && CHECKPOINT_DISABLE=1 npx prisma generate && CHECKPOINT_DISABLE=1 npx prisma migrate deploy && CHECKPOINT_DISABLE=1 npx prisma db seed && test -s storage/anythingllm.db': passed.
Result: npm exec --yes --package=prettier@3.2.5 -- prettier --check server/prisma/dockerDatabaseUrl.js server/tests/prisma/dockerStorage.test.js: passed.
Result: bash -n docker/docker-entrypoint.sh && git diff --check: passed.
Regression coverage: server/__tests__/prisma/dockerStorage.test.js.

Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Docker install unable to set STORAGE_DIR correctly

1 participant