Componette

Componette

inlm

inlm / schema-generator v0.7.3

Universal database schema generator from entities and more.

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

Schema Generator

Tests Status

Support Me

Do you like Schema Generator? Are you looking forward to the new features?

PayPal or credit/debit card

Bitcoin bc1qaak7swthhrk8qsfccmulkhxel8ad6amapuz09m

Thank you!

Installation

Download a latest package or use Composer:

composer require inlm/schema-generator

Schema Generator requires PHP 7.2.0 or later.

Usage

$extractor = new Inlm\SchemaGenerator\Extractors\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


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

  • 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
  • v0.6.0 Version 0.6.0

    • DibiMysqlExtractor renamed to DibiExtractor (BC break)
    • added DibiAdapter
    • LeanMapperExtractor autoloads entities
    • Diffs\CreatedTable & Diffs\UpdatedTable - added method getTableName() (BC break)
    • added SqlMemoryDumper
    • diffs are ordered by foreign keys
    • Utils\Generator massively improved (BC break)
    • LeanMapperExtractor - added annotation @schemaIgnore
    • SchemaGenerator & AbstractSqlDumper requires name of database (constant from Inlm\SchemaGenerator\Database) (BC break)
    • AbstractSqlDumper - added setHeader()
    • added IIntegration & LeanMapperIntegration
    • Integrations: added bridge for czproject/phpcli
    • improved support for Single Table Inheritance
    • improved tests
    • updated docs
    • many fixes & improvements
  • v0.5.2 Version 0.5.2

    • SchemaGenerator - added method removeOption()
    • improved handling of datatypes
    • updated README & docs
  • v0.5.1 Version 0.5.1

    • added parameter $description to $generator->generate()
  • v0.5.0 Version 0.5.0

    • added NeonExtractor
    • added MemoryAdapter
    • fixed Utils\Generator
    • DibiDumper - fixed $dibi->query()
    • LeanMapperExtractor - fixed DateTime recognition
    • Utils\Generator - improved column updating
    • uses czproject/logger
  • v0.4.0 Version 0.4.0

    • SqlDumper: throws exception if file already exists
    • SqlDumper: setDeepStructure replaced by setOutputStructure
  • v0.3.1 Version 0.3.1

    • DataTypeParser - added support for strings & enum
    • Readme: updated
  • v0.3.0 Version 0.3.0

    First public release.

Componette Componette felix@nette.org