Skip to content

Add database:install console command - #322

Closed
tmgbedu wants to merge 1 commit into
mainfrom
task/database-install-command
Closed

tmgbedu wants to merge 1 commit into
mainfrom
task/database-install-command

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a core database:install console command, registered by AppProvider so it's available before the database is set up.

  • Publishes config/database.py from the installer's database stub (--driver sqlite|postgres|mysql, default sqlite). An existing file is kept unless --force is passed.
  • Registers (DatabaseProvider, DatabaseConfig) in bootstrap/application.py. It finds Application(...) with ast and inserts the provider and any missing imports at exact positions, so the file's formatting stays the same.
  • Idempotent: if DatabaseProvider is already listed, the command changes nothing. If no bootstrap file is found, it prints manual steps and exits 1.
  • DRIVER_CLASSES is moved into installer/plan.py so the installer and this command use the same mapping.

Reusable InstallCommand base

console/install_command.py gives every package the same install behavior through a fluent class builder:

CacheInstallCommand = (
    InstallCommand.register("cache:install", "Install the cache.")
    .copy(files("my_package").joinpath("stubs/cache.py"), "config/cache.py")
    .add_provider(CacheProvider, "config.cache.CacheConfig")
)
  • Each chain call returns a new subclass, so the result can be passed straight to self.commands([...]).
  • add_provider accepts classes or dotted strings. Use strings for app-side configs and for optional extras that shouldn't be imported.
  • The base class provides --force, publish_file (skips existing files unless forced), and the AST-based registration in bootstrap/application.py (register_provider).
  • database:install subclasses it to add --driver and template rendering.

ADR renumber

The ADR was renumbered from 035 → 041 (docs/adr/041-database-install-command.md), and its index entry was updated. 035 collides with the Config-subclass ADR on #313. 036–040 are taken by main and the open PRs (#314/#315/#317/#318).

Rebase

Rebased onto latest origin/main (284d097). The only conflict was in docs/adr/AGENTS.md, where both index rows were kept.

Test results

  • pytest tests/console/test_install_command.py tests/console/test_database_install_command.py: 23 passed
  • Full suite (--ignore=tests/masoniteorm/postgres --cov): 3352 passed, 10 skipped, coverage 91.69% (threshold 80)
  • ruff check / ruff format --check: clean. The new test file needed reformatting, which was folded into the commit.
  • basedpyright: no new errors. The one remaining error is pre-existing on main (ai/ai.py, unresolved optional langchain.chat_models import).
  • Manual smoke test on a copy of example/fastapi-app: the first run created the config and registered the provider. The second run skipped both.

🤖 Generated with Claude Code

Publishes config/database.py from the installer's database stub and
registers (DatabaseProvider, DatabaseConfig) in bootstrap/application.py.
Re-running is idempotent; an existing config is kept unless --force.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude-tmgbedu

Copy link
Copy Markdown

Superseded by a PR opened from the claude-tmgbedu account

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

3 participants