inlm/schema-generator

Schema generator for Lean Mapper

v0.10.5 2021-05-10 12:09 UTC

README

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/