bookimed/dbal-schema-provider-lib

There is no license information available for the latest version (v1.0) of this package.

DBAL schema provider

v1.0 2022-02-19 13:41 UTC

This package is auto-updated.

Last update: 2023-09-19 14:56:33 UTC


README

Need to configure doctrine_migration bundle to use custom schema provider via key doctrine_migrations.services:

# config/packages/doctrine_migrations.yaml
doctrine_migrations:
  # unnecessary... 

  services:
    Doctrine\Migrations\Provider\SchemaProvider: doctine.dbal.schema.migration_schema_provider

Using

Own schema provider

For a register new provider: 1) implement interface GameInspire\DBAL\Schema\Provider\DBALSchemaProviderInterface; 2) add it to DI container with tag db.schema.provider.

Generate migration

  1. Run bin/console doctrine:migrations:diff to get auto-generated migration with applied diff changes (doctrine will fetch current DB state and compare with specified in PHP code).

  2. Update migration for lock-free migrate or for another goals and commit it.

Example

Custom provider

<?php
namespace Bookimed\Entity\Storage;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Bookimed\DBAL\Schema\Provider\DBALSchemaProviderInterface;

final class EntityMysqlSchema implements DBALSchemaProviderInterface
{
    public const TABLE_NAME = 'entity';
 
    public const FIELD_1_FIELD = 'field_1';
    public const FIELD_2_FIELD = 'field_2';
    public const FIELD_3_FIELD = 'field_3';
    
    public function specifySchema(Schema $schema): void
    {
        $table = $schema->createTable(self::TABLE_NAME);
    
        $table->addColumn(self::FIELD_1_FIELD, Types::INTEGER);
        $table->addColumn(self::FIELD_2_FIELD, Types::INTEGER);
        $table->addColumn(self::FIELD_3_FIELD, Types::STRING);
        $table->setPrimaryKey([self::FIELD_1_FIELD]);
   }
}

DI:

services:
    service.entity.mysql.schema:
      class: Bookimed\Entity\Storage\EntityMysqlSchema
      tags: [ 'db.schema.provider' ]