Giter Site home page Giter Site logo

doctrine2-exporter's Introduction

Build Status Latest Stable Version Total Downloads License

README

What is MySQL Workbench Schema Exporter?

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:

Prerequisites

  • PHP 7.2+
  • Composer to install the dependencies

Installation

  1. In your project directory issue:
composer require --dev mysql-workbench-schema-exporter/mysql-workbench-schema-exporter
  1. You then can invoke the CLI script using vendor/bin/mysql-workbench-schema-export.

  2. You can directly require an exporter for your project:

composer require --dev mysql-workbench-schema-exporter/doctrine2-exporter

Command Line Interface (CLI)

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.

Command usage:

vendor/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=type

Choose 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=file

Read export parameters from file (in JSON format).

  • --save-config

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

Sample usage:

vendor/bin/mysql-workbench-schema-export --export=doctrine1-yaml example/data/test.mwb ./generated
vendor/bin/mysql-workbench-schema-export --zip example/data/test.mwb

Configuring MySQL Workbench Schema Exporter

MySQL Workbench Schema Exporter can be configured at runtime using methods:

  • Configuration files.
  • Model comment, either applied to table, column, or foreign key object.

Refers to exporter project to show detailed information.

Common Model Comment Behavior

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

Using MySQL Workbench Schema Exporter as Library

If you want to use MySQL Workbench Schema Exporter as a library for other project. See the included usage in the example folder.

Test Database

Links

doctrine2-exporter's People

Contributors

adrianbardan avatar allansun avatar damienharper avatar defyasdf avatar doncem avatar drymek avatar hobiecat avatar johmue avatar leocavalcante avatar meven avatar rvock avatar s2x avatar tohenk avatar verticka avatar yoda-bzh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doctrine2-exporter's Issues

Column name Casing

Quick question:
My database is designed with snake_case columns and table names... but when I generate the entity classes the attribute names are snake_case and the relations columns are camelCase... This is very inconvenient... is there any setting that allows the conversion of the column names to camelCase and add the name attribute to the column annotation?

/** @Column(type="string", name="snake_cased_column") */
protected $snakeCasedColumn;

Thanks!

Duplicate "use" in Entity class

In 3.0.x no problem.
I try to upgrade to 3.1 but symfony raise an exception after class are generated:
I use this json:

{"export": "doctrine2-annotation",
    "zip": false,
    "dir": "/MyFolder/src/Entity",
    "params":
            {"indentation": 4,
                "useTabs": false, 
                "filename": "%entity%.%extension%",
                "skipPluralNameChecking": true,
                "backupExistingFile": false,
                "addGeneratorInfoAsComment": false,
                "useLoggedStorage": false,
                "enhanceManyToManyDetection": true,
                "logToConsole": false,
                "logFile": "",
                "bundleNamespace": "App",
                "entityNamespace": "Entity",
                "repositoryNamespace": "App\\Entity",
                "useAutomaticRepository": false,
                "generateExtendableEntity": true,
                "extendableEntityHasDiscriminator": false,
                "extendTableNameWithSchemaName": false
            }
}

App\Entity\Base\BaseTest is ok.

App\Entity\Test has 2 use with same declaration :

<?php

namespace App\Entity;

use App\Entity\Base\BaseTest;             <--- OK

use Doctrine\ORM\Mapping as ORM; 
use App\Entity\BaseTest;                      <--- Error

/**
 * App\Entity\Test
 *
 * @ORM\Entity()
 * @ORM\Table(name="Test")
 */
class Test extends BaseTest
{
}

Symfony error:

Compile Error: Cannot use App\Entity\BaseTest as BaseTest because the name is already in use

I suppose the problem is in

https://github.com/mysql-workbench-schema-exporter/doctrine2-exporter/blob/master/lib/Annotation/Model/Table.php#L330

For my case if I comment this line:
https://github.com/mysql-workbench-schema-exporter/doctrine2-exporter/blob/master/lib/Annotation/Model/Table.php#L478
the class is generated correctly

yml instead annotations

Hi and thank you for sharing your work

I am using diagram exporting starting from when there was the LUA plugin for doing that.
Now I am wondering if is it possible to have ...orm.yml generated together with classes instead of annotations only in the entity classes ?

Generating Trigger

Hi
I don't see the triggers printing once retrieved from my mwb file. I have tried Doctorine2Yml and Doctorine2Annotation.

tnx

Getter and setter generator not working properly (doctrine2-annotation) [with possible solution]

So I have been using your exporter for a while and have experienced some problems with generating getters and setters.

Version: 3.1.3

The problem:

Without touching anything the some of the setters are the following:

    /**
     * Set Brand entity (many to one).
     */
    public function setBrand($brands)
    {
        $this->brands = $Brand;
        return $this;
    }

And the problem here is obvious.

The possible solution to this:

Open file "project_folder_name/public/vendor/mysql-workbench-schema-exporter/doctrine2-exporter/lib/Annotation/Model/Table.php", and edit the writer.

From (last method):

->write('public function set'.$nameSingular.'('.$typehints['set_arg'].'$'.$this->getNaming($foreign->getReferencedTable()->getName()).')'.$typehints['set_return'])
                    ->write('{')
                    ->indent()
                        ->write('$this->'.$this->getNaming($this->getRelatedVarName($foreign->getReferencedTable()->getName(), $related)).' = $'.$this->getNaming($foreign->getReferencedTable()->getModelName()).';')

To:

->write('public function set'.$nameSingular.'('.$typehints['set_arg'].'$'.$this->getNaming($foreign->getReferencedTable()->getName()).')'.$typehints['set_return'])
                    ->write('{')
                    ->indent()
                        ->write('$this->'.$this->getNaming($this->getRelatedVarName($foreign->getReferencedTable()->getName(), $related)).' = $'.$this->getNaming($foreign->getReferencedTable()->getName()).';')

Which fixes the setter methods like:

   /**
    * Set Brand entity (many to one).
    */
   public function setBrand($brands)
   {
       $this->brands = $brands;

       return $this;
   }

The export.json I am using to generate entities:

"export": "doctrine2-annotation",
 "zip": false,
 "dir": "...",
 "params": {
     "logToConsole": false,
     "logFile": "doc/wbexporter.log",
     "filename": "%entity%.%extension%",
     "indentation": 4,
     "useTabs": false,
     "eolDelimeter": "unix",
     "backupExistingFile": true,
     "addGeneratorInfoAsComment": false,
     "skipPluralNameChecking": false,
     "useLoggedStorage": false,
     "sortTablesAndViews": true,
     "exportOnlyTableCategorized": "",
     "enhanceManyToManyDetection": true,
     "skipManyToManyTables": true,
     "bundleNamespace": "App",
     "entityNamespace": "Entity",
     "repositoryNamespace": "",
     "useAutomaticRepository": true,
     "skipColumnWithRelation": false,
     "relatedVarNameFormat": "%name%%related%",
     "nullableAttribute": "auto",
     "generatedValueStrategy": "auto",
     "defaultCascade": false,
     "useAnnotationPrefix": "ORM\\",
     "skipGetterAndSetter": false,
     "generateEntitySerialization": true,
     "generateExtendableEntity": false,
     "quoteIdentifierStrategy": "auto",
     "extendsClass": "",
     "propertyTypehint": false,
     "extendableEntityHasDiscriminator": false
 }

Ensure generated attribute is not duplicated

When use english inflector, using sakila.mwb model, both OneToMany and ManyToOne relation of Staff in Stores, resulting in duplicated attribute because staff is singular and also plural.

Unidirectional Model Comment Behavior

I'm noticing some of the model comment behaviors aren't working such as:
{d:unidirectional}true{/d:unidirectional}

If anyone can verify this so that I can make sure I'm not doing something wrong, I'd appreciate it. I did test {d:bundleNamespace}AcmeBundle{/d:bundleNamespace} which works fine so it's not all the behaviors that are broke.

misleading translation in fieldname (plural / singular)

Thank you for your work.
I'm using MySQL Workbench to create a Model.
One of the used tables is called "unternehmen" (it is german for "company").
I have a One-to-Many relation to "niederlassung".
When I create the entity classes with your tool the following happens:

  1. The entity is called "unternehman" (a instead of e)
  2. The annotation is: @Orm\Table(name="unternehmen")

This is maybe a feature of auto translating plural/singular, but a little bit confusing.
What can I do to change this behavior, the entity has to have the same name as the table in the mwb-Model.

Thanks for your advice.

generateEntitySerialization is not aware of skipColumnWithRelation

Hi!

I'm using Doctrine 2.0 Annotation.

I set skipColumnWithRelation && generateEntitySerialization to true: concerned columns are not added as class properties, which is great, but these ignored properties are still added to magic _sleep() function, which is not congruent.

Repository File doens generate

Hy,

my config for generate Entity and Repository Class.

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

But the exporter only generate Entity Class Files not the Repository Class Files. :-(

Undefined class constant 'USERDATATYPE_JSON'

Missing constant definition:

in DatatypeConverterInterface from https://github.com/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter repo.

This is causes:
PHP Fatal error: Uncaught Error: Undefined class constant 'USERDATATYPE_JSON' in /home/piotr/work/test/vendor/mysql-workbench-schema-exporter/doctrine2-exporter/lib/MwbExporter/Formatter/Doctrine2/DatatypeConverter.php:98

Column Default Value

Hi
I don't see default value of column such as CURRENT_TIMESTAMP retrieving from mwb file.

tnx

XML export support

Hi there.. I've been using this exporter for a very long time... always used the Annotation option.. but lately I've seen that is not the best option.. that I should use an external annotation to separate the domain from the infrastructure... first thought was YAML, but then I learned that it's being deprecated in future doctrine versions. So, my only option is XML, which this exporter seems to not support.

Question is, anyone is working on it? or there is no plan for it?

Thanks!

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.