Giter Site home page Giter Site logo

eniuz / mysql-workbench-schema-exporter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mysql-workbench-schema-exporter/mysql-workbench-schema-exporter

0.0 2.0 0.0 953 KB

a php written mysql workbench file reader to transform the database scheme to useful other schemes like Doctrine

License: MIT License

mysql-workbench-schema-exporter's Introduction

README

ATTENTION

This software is EXPERIMENTAL and not ready for production. It is just a proof of concept.

What is MySQL Workbench schema exporter?

The application is intended to create:

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

Doctrine behaviours

Support for behaviours is implemented for Doctrine1. Use the comment fields in tables.

{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:".

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.

The syntax of CLI:

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

Where:

  • 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:

php cli/export.php --export=doctrine1 example/data/test.mwb ./generated
php cli/export.php --zip example/data/test.mwb

Sample export paramaters (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
    }
}

Exporter Options

General options

General options applied to all formatter.

  • indentation

    The indentation size for generated code.

  • 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%.

  • 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.

Option list for Doctrine 1.0

  • extendTableNameWithSchemaName

    Include schema name beside the table name. Default is false.

  • {d:externalRelations}

Option list for Doctrine 2.0 YAML

  • useAutomaticRepository

    Automatically generate entity repository class name.

  • bundleNamespace

    The global namespace prefix for entity class name.

  • entityNamespace

    The entity namespace. Default is Entity.

  • repositoryNamespace

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

  • extendTableNameWithSchemaName

    Include schema name beside the table name. Default is false.

Option list for Doctrine 2.0 Annotation

  • useAnnotationPrefix

    Doctrine annotation prefix. Default is ORM\.

  • useAutomaticRepository

    See above.

  • bundleNamespace

    See above.

  • entityNamespace

    See above.

  • repositoryNamespace

    See above.

  • skipGetterAndSetter

    Don't generate columns getter and setter. Default is false.

  • generateEntitySerialization

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

  • quoteIdentifier

    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.

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.

Links

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());

?>

mysql-workbench-schema-exporter's People

Contributors

johmue avatar tohenk avatar meven avatar armandabric avatar allansun avatar fgaudin avatar yoda-bzh avatar drowe avatar xeader avatar easen avatar

Watchers

Mariusz Szot avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.