I'm currently looking into automating a software build process that includes a database schema defined in MySQL Workbench.
Using Workbench's scripting capabilities, I'd like to open a Workbench document and export its schema as an SQL CREATE script.
What I'd like to know is if there is a function that exports the entire schema in one step as Workbench's File | Export | Forward Engineer SQL CREATE Script, automatically handling any dependencies between tables.
I've found some candidates in the DbMySQL
module that might do that (generateSQL(GrtNamedObject, dict, string)
and makeSQLExportScript(GrtNamedObject, dict, dict, dict)
), however I'm confused about the parameters they expect – the first one could be the schema object, but what are the other arguments ?
Could anyone tell me if my assumption is correct and/or provide me with usage examples ?
So far, I've come up with a manual solution (note that this currently does not sort the tables according to their FK relations):
local o = assert(io.open("/tmp/create.sql", "wb"));
foreach_table_all(function (t)
o:write(DbMySQL:makeCreateScriptForObject(t) .. ";\n\n")
end)
o:close()
The question is related to How to generate SQL Script from MySQL Workbench using Command Line?, however the answer found there is really abstract and tells nothing about actually using the scripting features of MySQL Workbench.