定制 hamichen/mysql-workbench-schema-exporter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hamichen/mysql-workbench-schema-exporter

Composer 安装命令:

composer require hamichen/mysql-workbench-schema-exporter

包简介

MySQL Workbench Schema Exporter

README 文档

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 5.4+ (PHP 8.0+ required for Attribute support)
  • Composer to install the dependencies

Installation

Using Composer

  1. In your project directory issue:
```
php composer.phar 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:

php composer.phar require --dev mysql-workbench-schema-exporter/doctrine2-exporter
  1. For PHP 8 Attribute support (Doctrine 2 only), ensure you have doctrine2-exporter installed as mentioned above. The attribute formatter is included in the exporter package.

Stand alone

  1. Get the source code using Git or download from Github.
  2. Get composer.
  3. Install dependencies:
```
php composer.phar install
```
  1. You then can invoke the CLI script using bin/mysql-workbench-schema-export.

Configuring MySQL Workbench Schema Exporter

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

  • Setup options.
  • Model comment, either applied to table, column, or foreign key object.

Both methods accept different options, and generally divided as common options and exporter (formatter) specific options.

Common Setup 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.

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

Formatter Setup Options

解決常見問題

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

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

Sample usage:

php bin/mysql-workbench-schema-export --export=doctrine1-yaml example/data/test.mwb ./generated
php bin/mysql-workbench-schema-export --export=doctrine2-attribute 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
    }
}

Sample export parameters (JSON) for doctrine2-attribute (PHP 8+):

{
    "export": "doctrine2-attribute",
    "zip": false,
    "dir": "temp",
    "params": {
        "backupExistingFile": true,
        "skipPluralNameChecking": false,
        "enhanceManyToManyDetection": true,
        "bundleNamespace": "",
        "entityNamespace": "",
        "repositoryNamespace": "",
        "useAttributePrefix": "ORM\\",
        "useAutomaticRepository": true,
        "indentation": 4,
        "filename": "%entity%.%extension%",
        "quoteIdentifier": false
    }
}

Note: When using doctrine2-attribute, the generated code will use PHP 8 attribute syntax #[ORM\Entity] instead of annotation syntax @ORM\Entity. This requires PHP 8.0 or higher.

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

mysql-workbench-schema-exporter

hamichen/mysql-workbench-schema-exporter 适用场景与选型建议

hamichen/mysql-workbench-schema-exporter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.35k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「propel」 「cli」 「mysql」 「zend」 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hamichen/mysql-workbench-schema-exporter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hamichen/mysql-workbench-schema-exporter 我们能提供哪些服务?
定制开发 / 二次开发

基于 hamichen/mysql-workbench-schema-exporter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.35k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-15