Componette

Componette

inlm

inlm / schema-generator v0.9.11

Universal database schema generator from entities and more.

download-cloud-line composer require inlm/schema-generator

Schema Generator

Build Status Downloads this Month Latest Stable Version License

Donate

Installation

Download a latest package or use Composer:

composer require inlm/schema-generator

Schema Generator requires PHP 5.6.0 or later.

Usage

$extractor = new Inlm\SchemaGenerator\LeanMapperBridge\LeanMapperExtractor(__DIR__ . '/model/Entities/', new LeanMapper\DefaultMapper);
$adapter = new Inlm\SchemaGenerator\Adapters\NeonAdapter(__DIR__ . '/.schema.neon');
$dumper = new Inlm\SchemaGenerator\Dumpers\SqlDumper(__DIR__ . '/migrations/structures/');
$logger = new Inlm\SchemaGenerator\Loggers\MemoryLogger;

$generator = new Inlm\SchemaGenerator\SchemaGenerator($extractor, $adapter, $dumper, $logger, Inlm\SchemaGenerator\Database::MYSQL);
// $generator->setTestMode();

$generator->generate();
// or
$generator->generate('changes description');

Documentation

Supported databases:

  • MySQL

How it works?

  1. adapter loads old schema if exists. Schema can be stored in file, memory,...
  2. extractor extracts new schema from entities, file, database,...
  3. generator generates diff between old and new schema
  4. dumper dumps differences to SQL file, database,...
  5. adapter saves new schema (only if is test mode disabled)

Extractors

Extracts new database schema from given source - entities, database or file.

Adapters

Persists database schema in file, memory,...

Dumpers

Dumps changes of database schema into migration file, database,...

Loggers

You can use loggers from czproject/logger.

  • CzProject\Logger\CliLogger
  • CzProject\Logger\MemoryLogger
  • CzProject\Logger\OutputLogger
  • or any else

More

Tip

If you need generate ... AFTER column in ALTER TABLE statements, call:

$schemaGenerator->enablePositionChanges();

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/

  • v0.9.11 Version 0.9.11

    Backported from v0.10.8

    • DiffGenerator - fixes circular references for removed tables
  • v0.10.8 Version 0.10.8

    • DiffGenerator - fixes circular references for removed tables
  • v0.9.10 Version 0.9.10

    Backported from v0.10.7

    • respects foreign keys to another database
  • v0.10.7 Version 0.10.7

    • respects foreign keys to another database
  • v0.9.9 Version 0.9.9

    Backported from v0.10.6

    • DiffGenerator - fixes circular references for created tables
  • v0.10.6 Version 0.10.6

    • DiffGenerator - fixes circular references for created tables
  • v0.9.8 Version 0.9.8

    Backported from v0.10

    • requires czproject/sql-schema ^3.0 & czproject/sql-generator ^2.0
  • v0.9.7 Version 0.9.7

    Backported from v0.10.5

    • LeanMapperExtractor - try load only accepted classes
  • v0.10.5 Version 0.10.5

    • LeanMapperExtractor - try load only accepted classes
  • v0.9.6 Version 0.9.6

    Backported from v0.10.4

    • added some default custom types for MySQL
      • DateInterval is converted to TIME
      • added mapping for some classes from inteve/types
  • v0.9.5 Version 0.9.5

    Backported from v0.10.3

    • uses custom PhpClassFinder instead of nette/robot-loader
  • v0.9.4 Version 0.9.4

    • requires Lean Mapper 3.x

    Backported fromv0.10.2:

    • requires czproject/dependency-php ^2.0
  • v0.10.4 Version 0.10.4

    • added some default custom types for MySQL
      • DateInterval is converted to TIME
      • added mapping for some classes from inteve/types
  • v0.10.3 Version 0.10.3

    • uses custom PhpClassFinder instead of nette/robot-loader
  • v0.10.2 Version 0.10.2

    • requires czproject/dependency-php ^2.0
  • v0.10.1 Version 0.10.1

    • LeanMapperExtractor - fixed findEntities() (ignores traits)
  • v0.10.0 Version 0.10.0

    • fixed compatibility with PHP 8.0
    • requires Lean Mapper 4.x
    • requires PHP 7.2 or newer
  • v0.9.3 Version 0.9.3

    Backported from v0.10.1

    • LeanMapperExtractor - fixed findEntities() (ignores traits)
  • v0.9.2 Version 0.9.2

    • DataTypeProcessor - added support for DateTimeImmutable
  • v0.9.1 Version 0.9.1

    • Integrations: fixed LeanMapperIntegration
  • v0.9.0 Version 0.9.0

  • v0.8.0 Version 0.8.0

    • allows nette/neon, nette/utils & nette/robot-loader ^3.0
    • Integrations: AbstractIntegration - added getDatabaseType()
    • Integrations: LeanMapperIntegration - database type is autodetected from Connection
    • Utils: DataTypeParser - quoted argument is always string
    • some small fixes
  • v0.7.3 Version 0.7.3

    • LeanMapperExtractor: fixed extracting of indexes with relationship
  • v0.7.2 Version 0.7.2

    • LeanMapperExtractor: ignores entities without doc-comment
  • v0.7.1 Version 0.7.1

    • DibiMysql: workaround for PHP bug Cannot use Dibi as Dibi because the name is already in use
  • v0.7.0 Version 0.7.0

    • MySQL - added custom types bcrypt & md5
    • added support for ... AFTER column in ALTER TABLE statements
    • improved detection of column position changes
    • ConfigurationSerializer - updated export of names
    • SqlDumper - doesn't print empty line on begin of file
    • dropped support for Lean Mapper 2.x & Dibi 2.x
    • DiffGenerator - tables are always sorted by name
    • LeanMapperExtractor - entities are sorted by name
  • v0.6.4 Version 0.6.4

    • Utils\Generator - for MySQL automatically adds default parameters (INT => INT(11), INT UNSIGNED => INT(10) UNSIGNED,...)
  • v0.6.3 Version 0.6.3

    • DataTypeParser - returns NULL for empty parameters
    • DataTypeProcessor - fixed handling of custom types
    • MemoryAdapter accepts $schema = NULL (#2)
  • v0.6.2 Version 0.6.2

    • IIntegration - added method initFromDatabase() (little BC break)
  • v0.6.1 Version 0.6.1

    • Utils\Generator - relationships are created after primary indexes
    • Utils\Generator - throws exception only for incompatible primary keys
Componette Componette felix@nette.org