Skip to content

fix(backend): resolve correct database path in reset_database.py#1378

Open
AbiramiR-27 wants to merge 5 commits into
AOSSIE-Org:mainfrom
AbiramiR-27:fix/reset-database
Open

fix(backend): resolve correct database path in reset_database.py#1378
AbiramiR-27 wants to merge 5 commits into
AOSSIE-Org:mainfrom
AbiramiR-27:fix/reset-database

Conversation

@AbiramiR-27

@AbiramiR-27 AbiramiR-27 commented Jul 15, 2026

Copy link
Copy Markdown

Addressed Issues:

Fixes #1375

Screenshots/Recordings:

N/A (This is a backend utility script update with no user interface changes).

Additional Notes:

Previously, the backend/reset_database.py script was hardcoded to search for database files using glob.glob("app/database/*.db"). However:

  1. No database files exist in that directory (only Python source code).
  2. The actual application database is saved dynamically in the system's local AppData directory, as configured by DATABASE_PATH in app/config/settings.py.

This meant that running the reset database script did not actually clean or delete the active database.

Changes made in this PR:

  • Imported the configured DATABASE_PATH from app.config.settings.
  • Updated delete_db_files() to explicitly target DATABASE_PATH along with any associated SQLite journaling or transaction files (-journal, -wal, -shm).
  • Scans the database's parent directory dynamically to clean up any other .db or .sqlite3 files.
  • Maintained compatibility for local testing files (e.g. test_db.sqlite3 generated during unit tests).
  • Verified the script by running linter tests (ruff) and unit tests (pytest), all of which passed successfully.

AI Usage Disclosure:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: Gemini 3.5 Flash (Medium) via Antigravity coding assistant.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • Bug Fixes
    • Improved database reset cleanup to remove the configured SQLite database file along with its journal/WAL/SHM companion artifacts.
    • Expanded cleanup to also remove the local test database and its journal/WAL/SHM companions.
    • Added clearer per-file success/error reporting, a “nothing found” message when no files are deleted, and a non-zero exit status if any deletion fails.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The database reset script now uses the configured database path, removes SQLite companion and test database files, normalizes and deduplicates candidates, reports deletion results, and exits on errors. A frontend destructuring statement receives a syntax-only trailing comma.

Changes

Database reset behavior

Layer / File(s) Summary
Configured database cleanup
backend/reset_database.py
delete_db_files() imports DATABASE_PATH, builds normalized SQLite artifact paths, deletes existing files with stdout and stderr reporting, handles deletion errors, and retains the __main__ entry point.

Frontend syntax cleanup

Layer / File(s) Summary
Zoomable image destructuring
frontend/src/components/Media/ZoomableImage.tsx
Adds a trailing comma to the useZoomTransform destructuring list without changing runtime behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: Python, TypeScript/JavaScript

Poem

I’m a bunny with databases bright,
Clearing stale files left and right.
Journals and WALs hop away,
Shiny clean paths greet the day.
Reset complete—hip-hop hooray! 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning A frontend formatting-only change in ZoomableImage.tsx is unrelated to the database reset issue. Remove the ZoomableImage.tsx edit or split it into a separate formatting PR.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the backend database reset path fix and matches the main change.
Linked Issues check ✅ Passed The reset script now targets the configured database path and its SQLite companion files, satisfying issue #1375.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
backend/reset_database.py (3)

17-17: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Verify that the path is a directory.

Using os.path.isdir() is safer than os.path.exists() to ensure that the path is actually a directory before attempting to construct file paths and search within it.

💡 Proposed refactor
-    if os.path.exists(db_dir):
+    if os.path.isdir(db_dir):
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/reset_database.py` at line 17, Update the path check in the database
reset flow to use os.path.isdir(db_dir) instead of os.path.exists(db_dir),
ensuring subsequent file construction and searching only occur when db_dir is a
directory.

33-33: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove redundant list() conversion.

The list() call is unnecessary because sorted() accepts any iterable and natively returns a list.

💡 Proposed refactor
-    unique_db_files = sorted(list(set(os.path.abspath(f) for f in db_files)))
+    unique_db_files = sorted(set(os.path.abspath(f) for f in db_files))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/reset_database.py` at line 33, Remove the redundant list conversion
in the unique_db_files assignment while preserving the set-based deduplication,
absolute-path mapping, and sorted list result.

6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add return type hint.

As per path instructions, ensure proper use of type hints by explicitly indicating that this function returns None.

💡 Proposed refactor
-def delete_db_files():
+def delete_db_files() -> None:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/reset_database.py` at line 6, Update the delete_db_files function
signature to explicitly annotate its return type as None, without changing its
behavior or implementation.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/reset_database.py`:
- Line 37: Update the database cleanup condition in the reset logic to use
os.path.isfile(db_file) instead of os.path.exists(db_file), ensuring os.remove()
is only called for matching files and not directories.

---

Nitpick comments:
In `@backend/reset_database.py`:
- Line 17: Update the path check in the database reset flow to use
os.path.isdir(db_dir) instead of os.path.exists(db_dir), ensuring subsequent
file construction and searching only occur when db_dir is a directory.
- Line 33: Remove the redundant list conversion in the unique_db_files
assignment while preserving the set-based deduplication, absolute-path mapping,
and sorted list result.
- Line 6: Update the delete_db_files function signature to explicitly annotate
its return type as None, without changing its behavior or implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1937a5c0-c6c0-482f-8a02-ff3aec22553d

📥 Commits

Reviewing files that changed from the base of the PR and between f66e017 and f8b7a0b.

📒 Files selected for processing (1)
  • backend/reset_database.py

Comment thread backend/reset_database.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll soon be having a scripts/ directory inside the backend/ folder. When that happens we'll be moving this file into that directory.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thanks for letting me know!

@github-actions github-actions Bot added backend bug Something isn't working labels Jul 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/reset_database.py`:
- Around line 18-24: Update the pattern handling in the database reset logic to
remove SQLite companion files for .sqlite3 databases as well as the base files.
Extend the patterns used by the reset routine to include .sqlite3-journal,
.sqlite3-wal, and .sqlite3-shm variants, preserving the existing cleanup
behavior for other database extensions.
- Around line 35-48: Update the deletion flow in the reset database script so
any PermissionError or other exception while removing files causes the script to
exit unsuccessfully, rather than only printing the error. Preserve the existing
successful deletion messages and no-files behavior, but propagate or explicitly
raise a failure after deletion errors so automation cannot continue with a stale
database.
- Around line 15-30: Restrict the file patterns in the database cleanup flow to
the configured DATABASE_PATH stem and its journal, WAL, SHM, and sqlite
variants, while retaining only the explicitly supported test database files.
Remove broad "*.db" and "*.sqlite3" globs so unrelated databases in the database
directory cannot be deleted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d12118d-392a-45d0-b464-fb45dd6a331d

📥 Commits

Reviewing files that changed from the base of the PR and between e8cb013 and 4835cbb.

📒 Files selected for processing (2)
  • backend/reset_database.py
  • frontend/src/components/Media/ZoomableImage.tsx

Comment thread backend/reset_database.py Outdated
Comment thread backend/reset_database.py Outdated
Comment thread backend/scripts/reset_database.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
backend/reset_database.py (1)

24-25: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Simplify set creation and sorting.

As per path instructions regarding Python best practices, using a set comprehension directly within sorted() is more idiomatic and concise. The list() conversion is unnecessary because sorted() inherently returns a new list.

♻️ Proposed refactor
     # Normalize paths and remove duplicates
-    unique_db_files = sorted(list(set(os.path.abspath(f) for f in db_files)))
+    unique_db_files = sorted({os.path.abspath(f) for f in db_files})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/reset_database.py` around lines 24 - 25, Update the unique_db_files
assignment to pass a set comprehension directly to sorted(), removing the
unnecessary list() conversion while preserving absolute-path normalization,
deduplication, and ordering.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@backend/reset_database.py`:
- Around line 24-25: Update the unique_db_files assignment to pass a set
comprehension directly to sorted(), removing the unnecessary list() conversion
while preserving absolute-path normalization, deduplication, and ordering.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 10a73a30-5e99-47e2-bb58-b30060fcb585

📥 Commits

Reviewing files that changed from the base of the PR and between 4835cbb and dc037e2.

📒 Files selected for processing (1)
  • backend/reset_database.py

@AbiramiR-27

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@rohan-pandeyy

Copy link
Copy Markdown
Member

@AbiramiR-27 you can go ahead with the move now!

@AbiramiR-27

Copy link
Copy Markdown
Author

@rohan-pandeyy Done! I've moved the script to backend/scripts/reset_database.py and updated the branch. Ready for another look when you have a moment!

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

Labels

backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: reset_database.py does not delete the actual application database

2 participants