MySQL Blog Archive
For the latest blogs go to blogs.oracle.com/mysql
Pimp My Workbench

Some weeks ago there was a request about adding a feature that keeps (or gets) datatypes of colums, which are connected via foreign keys, in sync. While we have added this to our ToDo list, I thought of doing some simple LUA exercises to give the user at least a funtion to check if the FKs in the model all have columns with matching datatypes.
As it turned out such tasks can be done quite easily using our GRT-shell. And by writing some functions you can add features to Workbenchs interface.

To get in touch with the shell/GRT environment inside Workbench click the tiny black prompt-window-icon in the top right area of workbench (or choose ‘View->Advanced->GRT Shell’ from the main menu).  Some items in the UI are swapped/added: the sidebar on the right side gets a new tab named ‘GRT Shell’ featuring some more tool-panes (GRT Tree, Modules, Inspector) and on the bottom part of the main window – where the editors usually show up – a black shell Console will pop up.
At the top of the sidebar you can see the module-file-browser. By default the only two files in there are the ones containing our standard modules. When you want to dive further into scripting workbench, its best to look at the functions in the standard-module-files. When you’re ready to add some custom functions to workbench simply create a new user module (click at the “new”-icon at the top of the sidebar) and select the “LUA GRT Module File” Template, give the file a name and click “Add”. You’ll find the needed functions for registring your modules in workbench already set up there for you to adapt. The comments in the code will point out the parts you need to modify. So lets start extending!

As an additional example, I’m adding my approach to the check-FK-problem mentioned at the beginning of this post. Grab the zip, unpack it and put the .lua files into your Workbench-modules directory (detailed instructions can be found in the readme inside the .zip)
UserModules for checking FK-columns consistency