feat: ✨ add database bootstrap#31
Conversation
Create a new database.php file to set up database connections and configurations.
Implement registerDatabase method to configure database in Slim application. Co-authored-by: Copilot <copilot@github.com>
Add details on database initialization in contributing.md and readme.md to clarify setup process. Co-authored-by: Copilot <copilot@github.com>
Include instructions for adding custom bootstrap files to enhance application setup and maintain clarity. Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Adds a dedicated database bootstrap hook to the Slim application bootstrap lifecycle, centralizing database setup in a standard place and documenting how to extend the bootstrap system.
Changes:
- Introduces
bootstrap/database.phpas the standard database initialization hook. - Updates
ApplicationFactoryto execute the database bootstrap during app construction (after middleware, before routes). - Updates
README.mdandCONTRIBUTING.mdto document the new database bootstrap and how to add custom bootstrap files.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| bootstrap/database.php | Adds a new bootstrap closure intended for database/ORM setup. |
| app/Infrastructure/Factory/ApplicationFactory.php | Executes the new database bootstrap during application build. |
| README.md | Documents the new bootstrap/database.php location and purpose. |
| CONTRIBUTING.md | Adds contributor guidance for database bootstrap and custom bootstrap extensibility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| use Slim\App; | ||
|
|
||
| return function (App $app): void { |
There was a problem hiding this comment.
In this repo’s other bootstrap files, closures are declared as return function(App $app): void { (no space between function and (). For consistency (and to avoid style-lint churn), consider matching that format here as well.
| return function (App $app): void { | |
| return function(App $app): void { |
|
|
||
| Interface to implementation bindings are defined in `repositories.php`, which maps domain contracts to concrete implementations. | ||
|
|
||
| Database initialisation is configured in `database.php`, which provides a hook for setting up database connections, booting ORMs (Eloquent, Doctrine), configuring raw PDO connections, or running migrations. |
There was a problem hiding this comment.
The docs suggest using the HTTP bootstrap (database.php) to run migrations. Running migrations during app bootstrap can have significant operational impact (adds latency to every request, and can cause concurrency/locking issues). Consider updating this guidance to recommend running migrations via a CLI/deploy step (or at least clearly gating it to non-HTTP contexts) rather than as a normal bootstrap action.
| Database initialisation is configured in `database.php`, which provides a hook for setting up database connections, booting ORMs (Eloquent, Doctrine), configuring raw PDO connections, or running migrations. | |
| Database initialisation is configured in `database.php`, which provides a hook for setting up database connections, booting ORMs (Eloquent, Doctrine), and configuring raw PDO connections. | |
| Database migrations should be executed separately via a CLI command or deployment step, rather than during normal HTTP application bootstrap. |
| This file is intentionally flexible and can be used for establishing connections (PDO, MySQLi), booting ORMs (Eloquent, Doctrine), initialising query builders, running migrations, or any other database setup. The application factory calls this file after the container is built and before routes are registered, giving you access to resolved dependencies while keeping the factory decoupled from specific implementations. | ||
|
|
There was a problem hiding this comment.
This section lists “running migrations” as something that can be done in the HTTP bootstrap. That’s risky operationally because bootstrap runs on every request; migrations should typically be executed in a dedicated CLI/deployment workflow (or explicitly guarded so they never run in normal request handling). Suggest clarifying this to prevent accidental production issues.
| This file is intentionally flexible and can be used for establishing connections (PDO, MySQLi), booting ORMs (Eloquent, Doctrine), initialising query builders, running migrations, or any other database setup. The application factory calls this file after the container is built and before routes are registered, giving you access to resolved dependencies while keeping the factory decoupled from specific implementations. | |
| This file is intentionally flexible and can be used for establishing connections (PDO, MySQLi), booting ORMs (Eloquent, Doctrine), initialising query builders, or performing other database bootstrap setup needed before routes are registered. The application factory calls this file after the container is built and before routes are registered, giving you access to resolved dependencies while keeping the factory decoupled from specific implementations. | |
| Do **not** run database migrations here during normal HTTP request handling, because bootstrap code may execute on every request. Instead, run migrations through a dedicated CLI command or deployment workflow, or only behind an explicit guard that prevents them from running in the standard web bootstrap path. |
This pull request introduces a new, flexible database initialization mechanism to the application bootstrap process. It adds a dedicated
database.phpbootstrap file and integrates it into the application factory, allowing for centralized and customizable database setup. The documentation is updated to reflect these changes, and guidance is provided for extending the bootstrap system with custom files.Database Initialization Integration
bootstrap/database.phpfile as the standard location for all database setup concerns (e.g., establishing connections, booting ORMs, running migrations). [1] [2] [3]ApplicationFactoryto call a newregisterDatabase()method, which loads and executes thedatabase.phpbootstrap file during application construction, just after middleware registration and before route registration. [1] [2]Documentation Updates
README.mdandCONTRIBUTING.mdto document the new database initialization process, including where and how to configure database-related logic. [1] [2] [3]