All Projects → mnapoli → Dbal Schema

mnapoli / Dbal Schema

Licence: mit
DB schema manager for Doctrine DBAL

Labels

Projects that are alternatives of or similar to Dbal Schema

Doctrineenumbundle
📦 Provides support of ENUM type for Doctrine in Symfony applications.
Stars: ✭ 410 (+400%)
Mutual labels:  doctrine
Doctrinemigrations
[DEPRECATED] Use Phinx instead
Stars: ✭ 24 (-70.73%)
Mutual labels:  doctrine
Factory Bot
🤖 Provides a fixture factory for doctrine/orm entities.
Stars: ✭ 57 (-30.49%)
Mutual labels:  doctrine
Flextype
Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS
Stars: ✭ 436 (+431.71%)
Mutual labels:  doctrine
Idea Php Symfony2 Plugin
IntelliJ IDEA / PhpStorm Symfony Plugin
Stars: ✭ 797 (+871.95%)
Mutual labels:  doctrine
Zf Doctrine Graphql
GraphQL for Doctrine using Hydrators
Stars: ✭ 36 (-56.1%)
Mutual labels:  doctrine
Sonatadoctrineormadminbundle
Integrate Doctrine ORM into the SonataAdminBundle
Stars: ✭ 400 (+387.8%)
Mutual labels:  doctrine
Kimai2
Kimai v2 is a web-based multiuser time-tracking application. Free for everyone: freelancers, agencies, companies, organizations - all can track their times, generate invoices and more. SaaS version available at https://www.kimai.cloud
Stars: ✭ 1,216 (+1382.93%)
Mutual labels:  doctrine
Doctrinetraitbundle
Generate the entities stub methods in a trait
Stars: ✭ 6 (-92.68%)
Mutual labels:  doctrine
Parse Comments
Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
Stars: ✭ 53 (-35.37%)
Mutual labels:  doctrine
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+768.29%)
Mutual labels:  doctrine
Doctrinebehaviors
Doctrine2 behavior traits
Stars: ✭ 782 (+853.66%)
Mutual labels:  doctrine
Lumen Doctrine
Doctrine module for the Lumen PHP framework.
Stars: ✭ 41 (-50%)
Mutual labels:  doctrine
Doctrine Json Odm
An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
Stars: ✭ 420 (+412.2%)
Mutual labels:  doctrine
Forkcms
Fork is an easy to use open source CMS using Symfony Components.
Stars: ✭ 1,112 (+1256.1%)
Mutual labels:  doctrine
Doctrinebundle
Symfony Bundle for Doctrine ORM and DBAL
Stars: ✭ 4,225 (+5052.44%)
Mutual labels:  doctrine
Zf Doctrine Hydrator
A collection of common hydrators for phpro/zf-doctrine-hydration-module
Stars: ✭ 9 (-89.02%)
Mutual labels:  doctrine
Graphql Doctrine
Automatic GraphQL types from Doctrine entities
Stars: ✭ 81 (-1.22%)
Mutual labels:  doctrine
Doctrine Stats
Get Doctrine stats : managed entities, lazy loaded entities, hydration time etc.
Stars: ✭ 65 (-20.73%)
Mutual labels:  doctrine
Oneupaclbundle
The missing link between Symfonys Acl implementation and your application.
Stars: ✭ 48 (-41.46%)
Mutual labels:  doctrine

A schema manager for Doctrine DBAL: all the convenience of the Doctrine ORM, without using the ORM.

Why?

Doctrine ORM can automatically manage your DB schema based on your entity mapping. This feature is lost when using the DBAL instead of the ORM.

This package lets you achieve something similar by defining your DB schema with PHP code. It also lets you manage your database using a Symfony Console command similar to Symfony's native doctrine:schema:update command, as well as DB migrations.

Installation

composer require mnapoli/dbal-schema

Usage

1. Define a schema

Define your DB schema by implementing the SchemaDefinition interface:

class MySchemaDefinition implements \DbalSchema\SchemaDefinition
{
    public function define(Schema $schema)
    {
        $usersTable = $schema->createTable('users');
        $usersTable->addColumn('id', 'integer');
        $usersTable->addColumn('email', 'string');
        $usersTable->addColumn('lastLogin', 'datetime');
        $usersTable->addColumn('score', 'float', [
            'notnull' => false,
        ]);
        $usersTable->setPrimaryKey(['id']);
        $usersTable->addUniqueIndex(['email']);
    }
}

You can read the whole API available on Doctrine's documentation.

2. Set up the schema

Doctrine can now generate/update your database based on your schema.

Using Symfony

Here is an example of configuration that can go in your config/services.yml:

services:

    DbalSchema\SchemaDefinition:
        # Replace this with your class name
        alias: App\Database\MySchemaDefinition
    DbalSchema\DbalSchemaProvider:
    # Register the commands:
    DbalSchema\DbalSchemaCommand:
    DbalSchema\Command\UpdateCommand:
    DbalSchema\Command\PurgeCommand:

This configuration assumes your services are autowired.

Once the services are registered, you can now run the commands:

bin/console dbal:schema:update
bin/console dbal:schema:purge

Using Silly

Using Silly you can ignore the many separate command classes and simply use the DbalSchemaCommand class:

$schema = new MySchemaDefinition();
$dbalConnection = /* your DBAL connection, see http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html */

$command = new DbalSchemaCommand($dbalConnection, $schema);

$application = new Silly\Application();
$application->command('db [--force]', [$command, 'update']);
$application->command('db-purge [--force]', [$command, 'purge']);
$application->run();

If you are using the Silly PHP-DI edition it's even simpler as PHP-DI can instantiate the DbalSchemaCommand service:

$application->command('db [--force]', [DbalSchemaCommand::class, 'update']);
$application->command('db-purge [--force]', [DbalSchemaCommand::class, 'purge']);

3. Optional: database migrations

If you prefer using database migrations instead of running bin/console dbal:schema:update, DBAL Schema integrates with Doctrine Migrations.

To set it up, we need the setService() method call to happen like in the example below:

use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Provider\SchemaProvider;
use DbalSchema\DbalSchemaProvider;

$doctrineMigrationDependencyFactory = DependencyFactory::fromConnection(...);

$doctrineMigrationDependencyFactory->setService(SchemaProvider::class, new DbalSchemaProvider(new MySchemaDefinition()));

In Symfony, it can be done by installing the DoctrineMigrationsBundle and editing config/packages/doctrine_migrations.yaml:

doctrine_migrations:
    # ...
    services:
        Doctrine\Migrations\Provider\SchemaProvider: DbalSchema\DbalSchemaProvider

Now, you can run:

bin/console doctrine:migrations:diff

to generate migrations based on your DBAL schema.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].