Skip to content

Fix CLI crash when database not initialized#791

Merged
seapagan merged 1 commit into
mainfrom
bugfix/cli-database-initialization-crash
Dec 28, 2025
Merged

Fix CLI crash when database not initialized#791
seapagan merged 1 commit into
mainfrom
bugfix/cli-database-initialization-crash

Conversation

@seapagan

Copy link
Copy Markdown
Owner

Summary

Fixes CLI crash when database is not initialized. Commands now display a helpful error message directing users to run api-admin db init instead of crashing with SQL errors.

Changes

  • Added is_database_initialized() helper function in app/database/helpers.py
  • Added database initialization checks to all user commands: create, list, show, search, verify, ban, admin, delete
  • Added checks to db populate and seed commands
  • Added comprehensive test coverage (100%)
  • Parameterized similar tests to reduce duplication

Test Coverage

  • 472 tests passing
  • 100% code coverage
  • 13 new tests added (3 unit tests, 10 integration tests)
  • Parameterized 7 similar tests into 1

Before

$ api-admin user list
(crashes with SQL error about missing alembic_version table)

After

$ api-admin user list

-> ERROR: Database has not been initialized.
Please run 'api-admin db init' to initialize the database first.

🤖 Generated with Claude Code

@codacy-production

codacy-production Bot commented Dec 28, 2025

Copy link
Copy Markdown

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c144a82) 1676 1676 100.00%
Head commit (45211bf) 1704 (+28) 1704 (+28) 100.00% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#791) 29 29 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@seapagan seapagan force-pushed the bugfix/cli-database-initialization-crash branch from 056f96c to f544306 Compare December 28, 2025 16:02
@seapagan seapagan self-assigned this Dec 28, 2025
@seapagan seapagan added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Dec 28, 2025
Add database initialization checks to all CLI user and db commands.
Commands now display a helpful error message directing users to run
'api-admin db init' instead of crashing with SQL errors.

- Add is_database_initialized() helper function
- Add checks to all user commands (create, list, show, search, verify,
ban, admin, delete)
- Add checks to db populate and seed commands
- Add comprehensive test coverage (100%)
- Parameterize similar tests to reduce duplication
@seapagan seapagan force-pushed the bugfix/cli-database-initialization-crash branch from f544306 to 45211bf Compare December 28, 2025 16:09
@seapagan seapagan merged commit 88eee9e into main Dec 28, 2025
17 checks passed
@seapagan seapagan deleted the bugfix/cli-database-initialization-crash branch December 28, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant