comunedifirenze/mysql-workbench-schema-exporter
Converts MySQL Workbench .mwb models into other schemas via formatter/exporter plugins, including Doctrine 1/2 (YAML/annotations), Propel (XML/YAML), Zend Framework, Sencha ExtJS models, and Node Sequelize. Includes a CLI; install via Composer.
MySQL Workbench Schema Exporter is a library to
transform the MySQL Workbench model (*.mwb) to useful another schemas.
It is inspired by mysql-workbench-doctrine-plugin.
Currently, MySQL Workbench Schema Exporter can export the model to various schemas using a formatter plugin:
The actual conversion to another schema is done using an exporter. These plugins are available in subprojects:
php composer.phar require --dev mysql-workbench-schema-exporter/mysql-workbench-schema-exporter
You then can invoke the CLI script using vendor/bin/mysql-workbench-schema-export.
You can directly require an exporter for your project:
php composer.phar require --dev mysql-workbench-schema-exporter/doctrine2-exporter
php composer.phar install
bin/mysql-workbench-schema-export.MySQL Workbench Schema Exporter can be configured at runtime using methods:
Both methods accept different options, and generally divided as common options and exporter (formatter) specific options.
General options applied to all formatter.
filename
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%.
indentation
The indentation size for generated code.
useTabs
Use tabs for indentation instead of spaces. Setting this option will ignore the
indentation-option.
eolDelimeter
EOL type for generated code. Supported EOLs are win and unix.
addGeneratorInfoAsComment
Add generator information to the generated code as a comment.
Default is true.
skipPluralNameChecking
Skip checking the plural name of model and leave as is, useful for non English table names.
Default is false.
backupExistingFile
If target already exists create a backup before replacing the content.
Default is true.
enhanceManyToManyDetection
If enabled, many to many relations between tables will be added to generated code.
Default is true.
sortTablesAndViews
If enabled, sorting of tables and views is performed prior to code generation for each table and view. For table, it sorted by table model name and for view sorted by view model name.
Default is true.
exportOnlyTableCategorized
If specified, only export the tables if its category matched.
logToConsole
If enabled, output the log to console.
Default is false.
logFile
If specified, output the log to a file. If this option presence, option logToConsole will be
ignored instead.
Default is empty.
stripMultipleUnderscores
If enabled, consider multiple underscores as single ones so for example, a table named user__group
will still produce a UserGroup entity.
Default is false.
asIsUserDatatypePrefix
This option gives the ability to bypass user type convertion and forward user type to models, as is.
For example, if defined to _, and a user type
_BOOLEAN is defined in MySQL Workbench (resolving to TINYINT(1), for example, but no matter), then the model field will have BOOLEAN.
It is usefull for non MySQL types like BOOLEAN or JSONB that certain ORMs can handle.
Default is "" (disabled).
{MwbExporter:external}true{/MwbExporter:external} (applied to Table, View)
Mark table/view as external to skip table/view code generation. For Doctrine use
{d:external}true{/d:external} instead.
{MwbExporter:category}mycategory{/MwbExporter:category} (applied to Table)
Table category used to groups the table for sorting. This way, generated table output can be sorted as you need such as in Propel YAML schema (obviously useful for exporter which results in single file output).
The mysql-workbench-schema-export command helps export a workbench schema model directly
from command line. It has feature to customize export configuration before exporting.
By default, it 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.
Command usage:
php bin/mysql-workbench-schema-export [options] FILE [DEST]
Where:
FILE
The MySQL Workbench model file to export.
DEST
The destination directory (optional), if not specified current directory assumed.
Options:
--export=typeChoose the result of the export, supported type can be obtained using --list-exporter.
If this option is omitted and no config file found, the CLI will prompt to choose which exporter
to use.
--config=fileRead export parameters from file (in JSON format).
--saveconfigSave export parameters to file export.json, later can be used as value for --config=file.
--list-exporterShow all available exporter.
--no-auto-configDisable automatic config file lookup.
--zipCompress the result.
--helpShow the usage (or suppress any parameters).
Sample usage:
php bin/mysql-workbench-schema-export --export=doctrine1-yaml example/data/test.mwb ./generated
php bin/mysql-workbench-schema-export --zip example/data/test.mwb
Sample export parameters (JSON) for doctrine2-annotation:
{
"export": "doctrine2-annotation",
"zip": false,
"dir": "temp",
"params": {
"backupExistingFile": true,
"skipPluralNameChecking": false,
"enhanceManyToManyDetection": true,
"bundleNamespace": "",
"entityNamespace": "",
"repositoryNamespace": "",
"useAnnotationPrefix": "ORM\\",
"useAutomaticRepository": true,
"indentation": 4,
"filename": "%entity%.%extension%",
"quoteIdentifier": false
}
}
If you want to use MySQL Workbench Schema Exporter as a library for other project. See the included usage in the example folder.
How can I help you explore Laravel packages today?