2017 © Pedro Peláez
 

cli mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

image

pierre-vassoilles/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  • Tuesday, September 6, 2016
  • by pierre-vassoilles
  • Repository
  • 1 Watchers
  • 0 Stars
  • 269 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 134 Forks
  • 0 Open issues
  • 8 Versions
  • 22 % Grown

The README.md

README

This is a fork from https://github.com/johmue/mysql-workbench-schema-exporter, in order to improve and cotinue its development, as it looks abandoned in the original repo :(, (*1)

What is MySQL Workbench schema exporter?

The application is intended to create:, (*2)

schema files from MySQL Workbench models (*.mwb). It is inspired by mysql-workbench-doctrine-plugin., (*3)

Doctrine behaviours

Support for behaviours is implemented for Doctrine1. Use the comment fields in tables., (*4)

{d:actAs}
  actAs:
    timestampable:
      [..]
{/d:actAs}

Foreign key name

To replace relations name by the name of the foreign key, start the foreign key name with "d:"., (*5)

Command Line Interface (CLI)

There is a new CLI to simplify the export process named export.php, you can look under the cli folder. The CLI has feature to customize export configuration before exporting. By default, CLI application will use config file export.json located in the current directory to supply the parameter if it find it. To disable this behaviour, see the option below., (*6)

The syntax of CLI:, (*7)

php cli/export.php [options] FILE [DEST]

Where:, (*8)

  • options:
    • --export=type, choose the result of the export, currently available types:
      • doctrine1-yaml, Doctrine 1.0 YAML schema
      • doctrine2-yaml, Doctrine 2.0 YAML schema
      • doctrine2-annotation, Doctrine 2.0 Annotation classes (default)
      • propel1-xml, Propel XML schema
      • zend-dbtable, Zend DbTable
      • zend-rest-controller, Zend Rest Controller
      • sencha-extjs3, Sencha ExtJS3 Model
    • --config=file, read export parameters from file (in JSON format)
    • --saveconfig, save export parameters to file export.json, later can be used as value for --config=file
    • --list-exporter, show all available exporter
    • --no-auto-config, disable automatic config file lookup
    • --zip, compress the result
    • --help, show the usage (or suppress any parameters)
  • FILE, the mwb file to export
  • DEST, the destination directory (optional), if not specified current directory assumed

Sample usage:, (*9)

php cli/export.php --export=doctrine2-annotation example/data/test.mwb example/result

php cli/export.php --config=example/data/config.json example/data/test2.mwb example/result

Sample export paramaters (JSON) for doctrine2-annotation:, (*10)

{
    "export": "doctrine2-annotation",
    "zip": false,
    "dir": "temp",
    "params": {
        "backupExistingFile": true,
        "skipPluralNameChecking": false,
        "enhanceManyToManyDetection": true,
        "bundleNamespace": "",
        "entityNamespace": "",
        "repositoryNamespace": "",
        "useAnnotationPrefix": "ORM\\",
        "useAutomaticRepository": false,
        "indentation": 4,
        "filename": "%entity%.%extension%",
        "quoteIdentifier": false,
        "propertyNameCodingStyle": "lowercamelcase",
        "tableNameCodingStyle": "underscore",
        "columnNameCodingStyle": "underscore"
    }
}

Coding style options:
* raw
* underscore
* uppercamelcase
* lowercamelcase

Exporter Options

General options

General options applied to all formatter., (*11)

  • indentation, (*12)

    The indentation size for generated code., (*13)

  • useTabs, (*14)

    Use tabs for indentation instead of spaces. Setting this option will ignore the indentation-option, (*15)

  • filename, (*16)

    The output filename format, use the following tag %schema%, %table%, %entity%, and %extension% to allow the filename to be replaced with contextual data. Default is %entity%.%extension%., (*17)

  • skipPluralNameChecking, (*18)

    Skip checking the plural name of model and leave as is, useful for non English table names. Default is false., (*19)

  • backupExistingFile, (*20)

    If target already exists create a backup before replacing the content. Default is true., (*21)

  • enhanceManyToManyDetection, (*22)

    If enabled, many to many relations between tables will be added to generated code. Default is true., (*23)

Option list for Doctrine 1.0

  • extendTableNameWithSchemaName, (*24)

    Include schema name beside the table name. Default is false., (*25)

  • {d:externalRelations}, (*26)

Option list for Doctrine 2.0 YAML

  • useAutomaticRepository, (*27)

    Automatically generate entity repository class name., (*28)

  • bundleNamespace, (*29)

    The global namespace prefix for entity class name., (*30)

  • entityNamespace, (*31)

    The entity namespace. Default is Entity., (*32)

  • tablePrefix Default is empty, (*33)

    Define a prefix for tables name. Default is empty., (*34)

  • repositoryNamespace, (*35)

    The namespace prefix for entity repository class name. For this configuration to apply, useAutomaticRepository must be set to true., (*36)

  • extendTableNameWithSchemaName, (*37)

    Include schema name beside the table name. Default is false., (*38)

Option list for Doctrine 2.0 Annotation

  • useAnnotationPrefix, (*39)

    Doctrine annotation prefix. Default is ORM\., (*40)

  • useAutomaticRepository, (*41)

    See above., (*42)

  • bundleNamespace, (*43)

    See above., (*44)

  • entityNamespace, (*45)

    See above., (*46)

  • tablePrefix Default is empty, (*47)

    See above., (*48)

  • repositoryNamespace, (*49)

    See above., (*50)

  • skipGetterAndSetter, (*51)

    Don't generate columns getter and setter. Default is false., (*52)

  • generateEntitySerialization, (*53)

    Generate method __sleep() to include only real columns when entity is serialized. Default is true., (*54)

  • quoteIdentifier, (*55)

    If this option is enabled, all table names and column names will be quoted using backtick (`). Usefull when the table name or column name contains reserved word. Default is false., (*56)

  • {d:m2m}false{/d:m2m}, (*57)

    MySQL Workbench schema exporter tries to automatically guess which tables are many-to-many mapping tables and will not generate entity classes for these tables. A table is considered a mapping table, if it contains exactly two foreign keys to different tables and those tables are not many-to-many mapping tables., (*58)

    Sometimes this guessing is incorrect for you. But you can add a hint in the comment of the table, to show that it is no mapping table. Just use "{d:m2m}false{/d:m2m}" anywhere in the comment of the table., (*59)

  • {d:unidirectional}true{/d:unidirectional}, (*60)

    All foreign keys will result in a bidirectional relation by default. If you only want a unidirectional relation, add a flag to the comment of the foreign key., (*61)

  • {d:owningSide}true{/d:owningSide}, (*62)

    In a bi-directional many-to-many mapping table the owning side of the relation is randomly selected. If you add this hint to one foreign key of the m2m-table, you can define the owning side for Doctrine., (*63)

  • {d:cascade}persist, merge, remove, detach, all{/d:cascade}, (*64)

    You can specify Doctrine cascade options as a comment on a foreign key. The will be generated into the Annotation. (Reference), (*65)

  • {d:fetch}EAGER{/d:fetch}, (*66)

    You can specify the fetch type for relations in the comment of a foreign key. (EAGER or LAZY, doctrine default is LAZY), (*67)

  • {d:orphanRemoval}true{/d:orphanRemoval}, (*68)

    Another option you can set in the comments of foreign key. (Reference), (*69)

Option list for Propel Xml

  • namespace
  • addVendor

Option list for Zend DbTable

  • tablePrefix
  • parentTable
  • generateDRI
  • generateGetterSetter

Option list for Zend Rest Controller

  • tablePrefix
  • parentTable

Option list for Sencha ExtJS3 Model

  • classPrefix
  • parentClass

Requirements

Works with PHP 5.3 and up., (*70)

Test-Database

Example

<?php

// enable autoloading of classes
$libDir = __DIR__.'/lib';
require_once($libDir.'/MwbExporter/SplClassLoader.php');

$classLoader = new SplClassLoader();
$classLoader->setIncludePath($libDir);
$classLoader->register();

// create bootstrap
$bootstrap = new \MwbExporter\Bootstrap();

// define a formatter and do configuration
$formatter = $bootstrap->getFormatter('doctrine2-annotation');
$formatter->setup(array());

// specify the workbench document to load, output directory, and storage type (zip or file)
$mwbfile = 'myDatabaseModel.mwb';
$outDir = getcwd();
$storage = 'zip';
// load document and export
$document = $bootstrap->export($formatter, $mwbfile, $outDir, $storage);

// show the output
echo sprintf("Saved to %s.\n\n", $document->getWriter()->getStorage()->getResult());

?>

The Versions

06/09 2016

dev-stable

dev-stable https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench

02/09 2016

v1.0.6

1.0.6.0 https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench

22/07 2014

v1.0.5

1.0.5.0 https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench

21/07 2014

v1.0.4

1.0.4.0 https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench

18/07 2014

v1.0.3

1.0.3.0 https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench

10/07 2014

v1.0.2

1.0.2.0 https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench

10/07 2014

v1.0.1

1.0.1.0 https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench

10/07 2014

dev-master

9999999-dev https://github.com/johmue/mysql-workbench-schema-exporter

MySQL Workbench Schema Exporter

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Johannes Mueller

database cli doctrine mysql workbench