PHPackages                             sylvainduval/dynamic-db-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. sylvainduval/dynamic-db-bundle

ActiveLibrary[Database &amp; ORM](/categories/database)

sylvainduval/dynamic-db-bundle
==============================

Build and edit your database schema with PHP.

0.4.0(3mo ago)01MITPHPPHP &gt;=8.4

Since Dec 6Pushed 3mo agoCompare

[ Source](https://github.com/sylvainduval/dynamic-db-bundle)[ Packagist](https://packagist.org/packages/sylvainduval/dynamic-db-bundle)[ RSS](/packages/sylvainduval-dynamic-db-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

DynamicDB
=========

[](#dynamicdb)

**Object-Oriented Database Schema Management for PHP**

Description
-----------

[](#description)

**DynamicDB** is a lightweight and expressive PHP bundle that enables you to manage database schemas dynamically through an object-oriented API.

Unlike traditional ORMs or migration systems that rely on static entity definitions and diffs, DynamicDB gives you full control over your schema operations — explicitly and programmatically.

This makes it ideal for applications where the database structure must adapt to dynamic or user-defined data models, such as:

- Product Information Management (PIM) systems
- Digital Asset Management (DAM) tools
- Reporting or analytics platforms
- Data mining or ETL tools
- Any schema-on-the-fly use case

With DynamicDB, you can:

- Create and drop databases or tables programmatically
- Define fields using PHP objects and set their attributes
- Add, modify or delete fields explicitly
- Run schema operations in install scripts, migrations, or runtime processes

Key Principles &amp; Advantages
-------------------------------

[](#key-principles--advantages)

### Clear Responsibilities

[](#clear-responsibilities)

- You decide what should happen: create, modify, or delete.
- No hidden diffs or magic. DynamicDB executes exactly what you tell it.

### Fluent and Readable API

[](#fluent-and-readable-api)

- Object-oriented syntax makes your schema definition self-documented.
- Easy to version, organize, and replay (e.g. in migrations or CLI scripts).

### Method-Based Flexibility

[](#method-based-flexibility)

Core operations are exposed via stable and testable methods:

- createDatabase()
- deleteDatabase()
- createTable()
- createFields()
- changeField()
- deleteField()
- ...

Each schema component is represented as an object (Database, Table, Field), making it easy to encapsulate logic and manipulate structure dynamically. Database-specific settings for MySQL and PostgreSQL can be provided via dedicated options domain objects.

### Lazy loading

[](#lazy-loading)

No connection is opened, and no SQL is executed, until the first operation is explicitly called. This allows for deferred execution and better control over when and how the database is accessed.

Getting Started
---------------

[](#getting-started)

### Dependencies

[](#dependencies)

- PHP &gt;= 8.4
- PDO or mysqli driver
- MySQL &gt;= 5.7, MariaDB &gt;= 10.7 or PostgreSQL

Also suggested requirements for dependency injection :

- psr/container: Required if you use standalone bridge
- symfony/dependency-injection: Required if you use Symfony

### Development Setup with Docker

[](#development-setup-with-docker)

For development, this project includes a complete Docker environment with PHP 8.4, MySQL, MariaDB, and PostgreSQL.

#### Prerequisites

[](#prerequisites)

- Docker and Docker Compose v2 installed on your system

#### Quick Start

[](#quick-start)

1. Clone the repository and navigate to the project directory
2. Start the Docker environment:

```
make up
```

3. Install dependencies:

```
make install
```

4. Run tests to verify everything works:

```
make test
```

#### Available Make Commands

[](#available-make-commands)

- `make help` - Show all available commands
- `make up` - Start all Docker services
- `make down` - Stop all Docker services
- `make shell` - Open a shell in the PHP container
- `make install` - Install Composer dependencies
- `make test` - Run all PHPUnit tests
- `make test-unit` - Run only unit tests
- `make test-integration` - Run only integration tests
- `make phpstan` - Run PHPStan static analysis
- `make cs-fix` - Fix code style with PHP-CS-Fixer
- `make cs-check` - Check code style without fixing
- `make clean` - Clean up containers, volumes, and caches

#### Manual Docker Commands

[](#manual-docker-commands)

If you prefer not to use the Makefile:

```
# Start services
docker compose up -d

# Run tests
docker compose exec php vendor/bin/phpunit

# Run PHPStan
docker compose exec php vendor/bin/phpstan analyse

# Fix code style
docker compose exec php vendor/bin/php-cs-fixer fix
```

### Installing

[](#installing)

1. Reference it in your composer.json:

```
composer require sylvainduval/dynamic-db-bundle
```

2. With Symfony

This bundle does not have a Symfony Flex recipe yet. You must add this line in config/bundles.php:

```
