Question:
I'm trying to set up a bat to create the database on the mysql server from an EER (.mwb) model of mysql-workbench, in other words, in command line, is it possible to carry out this process? Could someone give a light?
Edition:
Opening it in cmd I have the following:
MySQLWorkbench [<options>] [<name of a model file or sql script>]
Options:
--query [<connection>|<connection string>]
Open a query tab and ask for connection if nothing is specified.
If named connection is specified it will be opened,
else connection will be created based on the given connection string,
which should be in form <user>@<host>:<port>
--admin <instance> Open a administration tab to the named instance
--upgrade-mysql-dbs Open a migration wizard tab
--model <model file> Open the given EER model file
--script <sql file> Open the given SQL file in an connection, best in conjunction
with a query parameter
--run-script <file> Execute Python code from a file
--run <code> Execute the given Python code
--run-python <code> Execute the given Python code
--migration Open the Migration Wizard tab
--quit-when-done Quit Workbench when the script is done
--log-to-stderr Also log to stderr
--help, -h Show command line options and exit
--log-level=<level> Valid levels are: error, warning, info, debug1, debug2, debug3
--verbose, -v Enable diagnostics output
--version Show Workbench version number and exit
--open <file> Open the given file at startup (deprecated, use script, model etc.)
So I could use –model plus –run-script and then –quit-when-done, but in that case what would that script look like, in what language? Any tips on how to write it?
Edition 2
I found a similar question on the English OS, there really doesn't seem to be a way to do this.
https://stackoverflow.com/questions/9556330/command-line-foward-engineering-using-a-mwb-file
Edition 3
Of course there is an answer, after researching I put it down there in case anyone needs it.
Answer:
I'll give you the path to the stones, but I'm not going to write the entire .bat file here.
- the .mwb file is a zipped file, rename it to .zip and unzip it.
- search for the .xml file and open it in a text editor
Inside this file you have all the necessary Tag's marks to build your .sql that then dump it into mysql.
So yes there is, and no, I'm not going to manipulate this file, you choose the best technique and apply it on top of this xml file, do replace by hand, use php xml to array, do it with json, in your own way, I'll leave the example of how the mwb file looks after unzipped:
<?xml version="1.0"?>
<data grt_format="2.0" document_type="MySQL Workbench Model" version="1.4.4">
<value type="object" struct-name="workbench.Document" id="{A6AEAF1F-556E-433D-9483-5253F37D41EE}" struct-checksum="0x7131bf99">
<value type="object" struct-name="workbench.logical.Model" id="{3183BE53-D18E-4B6F-AD8A-AE08B7BD19A2}" struct-checksum="0xf4220370" key="logicalModel">
<value _ptr_="0B831168" type="list" content-type="object" content-struct-name="workbench.logical.Diagram" key="diagrams"/>
<value _ptr_="0B8313E8" type="dict" key="customData"/>
<value _ptr_="0B832C98" type="list" content-type="object" content-struct-name="model.Marker" key="markers"/>
<value _ptr_="0B8308F8" type="dict" key="options"/>
<value type="string" key="name"></value>
<link type="object" struct-name="GrtObject" key="owner">{A6AEAF1F-556E-433D-9483-5253F37D41EE}</link>
</value>
<value _ptr_="0B831348" type="list" content-type="object" content-struct-name="workbench.OverviewPanel" key="overviewPanels"/>
<value _ptr_="0B830E98" type="list" content-type="object" content-struct-name="workbench.physical.Model" key="physicalModels">
<value type="object" struct-name="workbench.physical.Model" id="{2E273679-67EA-48F4-A08F-92A272B4D13F}" struct-checksum="0x5f896d18">
<value type="object" struct-name="db.mysql.Catalog" id="{ECE8278F-2DB8-4352-B627-6552022356F5}" struct-checksum="0x82ad3466" key="catalog">
<value _ptr_="0B831398" type="list" content-type="object" content-struct-name="db.mysql.LogFileGroup" key="logFileGroups"/>
<value _ptr_="0B830858" type="list" content-type="object" content-struct-name="db.mysql.Schema" key="schemata">
<value type="object" struct-name="db.mysql.Schema" id="{5278BE8F-6DD9-4F97-978C-C55DFCEE2B47}" struct-checksum="0x20b94c22">
<value _ptr_="0B8312F8" type="list" content-type="object" content-struct-name="db.mysql.RoutineGroup" key="routineGroups"/>
<value _ptr_="0B831C58" type="list" content-type="object" content-struct-name="db.mysql.Routine" key="routines">
<value type="object" struct-name="db.mysql.Routine" id="{7BB0B591-6EA6-409B-8F04-24B8E9076FA4}" struct-checksum="0x991f611c">
<value _ptr_="0B8318E8" type="list" content-type="object" content-struct-name="db.mysql.RoutineParam" key="params">
<value type="object" struct-name="db.mysql.RoutineParam" id="{C7FBF5C3-B6D8-43F5-9927-68FCC119125F}" struct-checksum="0x3f238dee">
<value type="string" key="datatype">INT</value>
<value type="string" key="paramType">IN</value>
<value type="string" key="name">cpf</value>
<link type="object" struct-name="GrtObject" key="owner">{7BB0B591-6EA6-409B-8F04-24B8E9076FA4}</link>
</value>
</value>
<value type="string" key="returnDatatype"></value>
<value type="string" key="security"></value>
<value type="string" key="name">duplicadoCpf</value>
<value type="string" key="routineType">procedure</value>
<value type="int" key="sequenceNumber">0</value>
<value type="string" key="definer">marcio`@`%</value>
<value type="string" key="sqlBody">BEGIN
DECLARE EXIT HANDLER FOR SQLSTATE '23000'
BEGIN
SELECT 'CPF CADASTRADO PARA OUTRO MOTORISTA' AS Msg;
END;
INSERT INTO tab_proprietario SET prop_cpf = cpf;
END</value>
<value type="string" key="sqlDefinition">
CREATE DEFINER=`marcio`@`%` PROCEDURE `duplicadoCpf`(IN cpf INT)
BEGIN
DECLARE EXIT HANDLER FOR SQLSTATE '23000'
BEGIN
SELECT 'CPF CADASTRADO PARA OUTRO MOTORISTA' AS Msg;
END;
INSERT INTO tab_proprietario SET prop_cpf = cpf;
END</value>
<value type="int" key="commentedOut">0</value>
<value type="string" key="createDate">2013-04-17 09:17</value>
<value _ptr_="0B831578" type="dict" key="customData"/>
<value type="string" key="lastChangeDate">2013-09-05 08:06</value>
<value type="int" key="modelOnly">0</value>
<link type="object" struct-name="GrtNamedObject" key="owner">{5278BE8F-6DD9-4F97-978C-C55DFCEE2B47}</link>
<value type="string" key="temp_sql"></value>
<value type="string" key="comment"></value>
<value type="string" key="oldName">duplicadoCpf</value>
</value>
.
.
.
Good luck!
And here the citation of the source give credit to those who deserve it https://stackoverflow.com/questions/19956525/how-to-convert-mwb-into-sql-without-workbench