[PR #414] [MERGED] Standardize tenant workspace DB directory to db/ with legacy migration support #717

Closed
opened 2026-03-13 21:05:37 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/414
Author: @AJaySi
Created: 3/12/2026
Status: Merged
Merged: 3/12/2026
Merged by: @AJaySi

Base: mainHead: codex/refactor-database-directory-for-workspaces


📝 Commits (1)

  • 7557feb Standardize tenant DB directory to db with legacy migration

📊 Changes

8 files changed (+87 additions, -44 deletions)

View changed files

📝 backend/check_cols.py (+5 -2)
📝 backend/scripts/debug_usage_v2.py (+2 -12)
📝 backend/scripts/inspect_user_db.py (+6 -5)
📝 backend/scripts/verify_db_path.py (+5 -13)
📝 backend/services/database.py (+51 -4)
📝 backend/services/research/deep_crawl_service.py (+1 -1)
📝 backend/services/user_workspace_manager.py (+12 -5)
📝 backend/verify_schema.py (+5 -2)

📄 Description

Motivation

  • Stop creating database/ for new user workspaces and make db/ the single canonical tenant DB directory.
  • Centralize all tenant DB path derivation so services/database.py is the single source of truth for DB locations.
  • Preserve backward compatibility by safely handling existing database/ layouts during rollout.

Description

  • Added ensure_user_workspace_db_directory(user_id) and _sanitize_user_id in services/database.py to create/ensure workspace/workspace_<id>/db/ and migrate a legacy database/ directory via rename or hard-link/copy fallback.
  • Updated get_user_db_path to call the new ensure function, prefer files under db/, and continue to resolve legacy files if migration has not yet occurred.
  • Modified UserWorkspaceManager to stop provisioning a database/ folder and delegate DB-directory setup to services.database by calling ensure_user_workspace_db_directory before creating other subdirectories.
  • Updated internal scripts and tooling (backend/scripts/*, backend/check_cols.py, backend/verify_schema.py) to derive DB paths via get_user_db_path instead of custom path logic and corrected an outdated comment in deep_crawl_service.py to reference the db/ location.

Testing

  • Compiled updated modules with python -m compileall for the modified files, which completed successfully.
  • Performed a smoke test by setting WORKSPACE_DIR to a temp directory and creating a workspace_<id>/database/ containing an old DB file, then called get_user_db_path which triggered migration and returned the expected canonical db/ path (migration and resolution verified).
  • Ran a PYTHONPATH=backend import-based smoke run to ensure the new helpers are reachable and that existing scripts using get_user_db_path work as expected and reported success.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/414 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/12/2026 **Status:** ✅ Merged **Merged:** 3/12/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/refactor-database-directory-for-workspaces` --- ### 📝 Commits (1) - [`7557feb`](https://github.com/AJaySi/ALwrity/commit/7557feb830ff76b36a66383c4c5f963a13cbae54) Standardize tenant DB directory to db with legacy migration ### 📊 Changes **8 files changed** (+87 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `backend/check_cols.py` (+5 -2) 📝 `backend/scripts/debug_usage_v2.py` (+2 -12) 📝 `backend/scripts/inspect_user_db.py` (+6 -5) 📝 `backend/scripts/verify_db_path.py` (+5 -13) 📝 `backend/services/database.py` (+51 -4) 📝 `backend/services/research/deep_crawl_service.py` (+1 -1) 📝 `backend/services/user_workspace_manager.py` (+12 -5) 📝 `backend/verify_schema.py` (+5 -2) </details> ### 📄 Description ### Motivation - Stop creating `database/` for new user workspaces and make `db/` the single canonical tenant DB directory. - Centralize all tenant DB path derivation so `services/database.py` is the single source of truth for DB locations. - Preserve backward compatibility by safely handling existing `database/` layouts during rollout. ### Description - Added `ensure_user_workspace_db_directory(user_id)` and `_sanitize_user_id` in `services/database.py` to create/ensure `workspace/workspace_<id>/db/` and migrate a legacy `database/` directory via rename or hard-link/copy fallback. - Updated `get_user_db_path` to call the new ensure function, prefer files under `db/`, and continue to resolve legacy files if migration has not yet occurred. - Modified `UserWorkspaceManager` to stop provisioning a `database/` folder and delegate DB-directory setup to `services.database` by calling `ensure_user_workspace_db_directory` before creating other subdirectories. - Updated internal scripts and tooling (`backend/scripts/*`, `backend/check_cols.py`, `backend/verify_schema.py`) to derive DB paths via `get_user_db_path` instead of custom path logic and corrected an outdated comment in `deep_crawl_service.py` to reference the `db/` location. ### Testing - Compiled updated modules with `python -m compileall` for the modified files, which completed successfully. - Performed a smoke test by setting `WORKSPACE_DIR` to a temp directory and creating a `workspace_<id>/database/` containing an old DB file, then called `get_user_db_path` which triggered migration and returned the expected canonical `db/` path (migration and resolution verified). - Ran a `PYTHONPATH=backend` import-based smoke run to ensure the new helpers are reachable and that existing scripts using `get_user_db_path` work as expected and reported success. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69afb0f2a0e4832886d01e3f012b505a) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:05:37 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#717
No description provided.