Command line development using a .mwb file?

I need to be able to execute forward technology from a model located in a .mwb file . All this from the command line, as I would like to automate the process.

Can someone please tell me if this is possible, and if so, how?

+6
source share
3 answers

This is the output on the command line after calling WB with --help :

 mysql-workbench [<options>] [<model file>] Options: --force-sw-render Force Xlib rendering --force-opengl-render Force OpenGL rendering --query <connection> Open a query tab to the named connection --admin <instance> Open a administration tab to the named instance --model <model file> Open the given EER model file --script <script file> Execute the given Python or Lua script file --run <script> Execute the given code in default language for GRT shell --run-python <script> Execute the given code in Python --run-lua <script> Execute the given code in Lua --quit-when-done Quit Workbench when the script is done --help, -h Show command line options and exit --log-level=<level> Valid levels are: error, warning, info, debug1, debug2, debug3 --verbose Enable diagnostics output --version Show Workbench version number and exit 

I assume that you can load your model using the --model parameter, and then create a script that will do forward engineering and run it with the --run parameter, and then instruct WB to exit after completion with --quit-when-done .

You can ask WB for help to learn more about scripting, as well as this guide .

+5
source

In fact, you can automate this task using the Python (or Lua) script. MySQL Workbench already has an interpreter in Scripting . Create a new script and use a stub:

 # -*- coding: utf-8 -*- import os import grt from grt.modules import DbMySQLFE c = grt.root.wb.doc.physicalModels[0].catalog DbMySQLFE.generateSQLCreateStatements(c, c.version, { 'GenerateDrops' : 1, 'GenerateSchemaDrops' : 1, 'OmitSchemata' : 1, 'GenerateUse' : 1 }) DbMySQLFE.generateSQLCreateStatements(c, c.version, { DbMySQLFE.createScriptForCatalogObjects(os.path.dirname(grt.root.wb.docPath) + 'ddl.sql', c, {}) 

It is not activated from the command line, but I believe that you can run it using the --run-script option.

+3
source

This question is too old, but I found a github project that does this below the commands in cmd windows and here is the github repository and a more complete version of the linux sh file.

Window

 @echo off REM generate sql from mwb REM usage: mwb2sql.bat {.mwb file} {output file} SET WORKBENCH="C:\Program Files (x86)\MySQL\MySQL Workbench 6.0 CE\MySQLWorkbench.exe" SET OUTPUT=%~f2 %WORKBENCH% ^ -open %~f1 ^ -run-python "import os;import grt;from grt.modules import DbMySQLFE as fe;c = grt.root.wb.doc.physicalModels[0].catalog;fe.generateSQLCreateStatements(c, c.version, {});fe.createScriptForCatalogObjects(os.getenv('OUTPUT'), c, {})" ^ -quit-when-done 
+2
source

Source: https://habr.com/ru/post/909941/


All Articles