Download a latest package or use Composer:
composer require inlm/schema-generator
Schema Generator requires PHP 5.6.0 or later.
$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');
Supported databases:
- MySQL
- adapter loads old schema if exists. Schema can be stored in file, memory,...
- extractor extracts new schema from entities, file, database,...
- generator generates diff between old and new schema
- dumper dumps differences to SQL file, database,...
- adapter saves new schema (only if is test mode disabled)
Extracts new database schema from given source - entities, database or file.
- LeanMapperExtractor (package
inlm/schema-generator-leanmapper
) - DibiExtractor (package
inlm/schema-generator-dibi
) - NeonExtractor
Persists database schema in file, memory,...
- NeonAdapter
- MemoryAdapter
- DibiAdapter (package
inlm/schema-generator-dibi
)
Dumps changes of database schema into migration file, database,...
- SqlDumper
- SqlMemoryDumper
- DibiDumper (package
inlm/schema-generator-dibi
) - NullDumper
You can use loggers from czproject/logger
.
CzProject\Logger\CliLogger
CzProject\Logger\MemoryLogger
CzProject\Logger\OutputLogger
- or any else
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/