Skip to content

feat: ✨ add database bootstrap#31

Closed
andrewdyer wants to merge 4 commits into
mainfrom
feat/database
Closed

feat: ✨ add database bootstrap#31
andrewdyer wants to merge 4 commits into
mainfrom
feat/database

Conversation

@andrewdyer
Copy link
Copy Markdown
Owner

This pull request introduces a new, flexible database initialization mechanism to the application bootstrap process. It adds a dedicated database.php bootstrap 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

  • Added a new bootstrap/database.php file as the standard location for all database setup concerns (e.g., establishing connections, booting ORMs, running migrations). [1] [2] [3]
  • Updated ApplicationFactory to call a new registerDatabase() method, which loads and executes the database.php bootstrap file during application construction, just after middleware registration and before route registration. [1] [2]

Documentation Updates

  • Expanded the README.md and CONTRIBUTING.md to document the new database initialization process, including where and how to configure database-related logic. [1] [2] [3]
  • Added instructions and best practices for adding custom bootstrap files for other application concerns, ensuring extensibility and maintainability of the bootstrap process.

andrewdyer and others added 4 commits April 28, 2026 23:13
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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.php as the standard database initialization hook.
  • Updates ApplicationFactory to execute the database bootstrap during app construction (after middleware, before routes).
  • Updates README.md and CONTRIBUTING.md to 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.

Comment thread bootstrap/database.php

use Slim\App;

return function (App $app): void {
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
return function (App $app): void {
return function(App $app): void {

Copilot uses AI. Check for mistakes.
Comment thread README.md

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.
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Comment thread CONTRIBUTING.md
Comment on lines +66 to +67
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.

Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
@andrewdyer andrewdyer closed this May 21, 2026
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.

2 participants