script.append(grt.modules.DbMySQL.makeCreateScriptForObject(routine)) script.append(';\n\n') else: script.append(grt.modules.DbMySQL.makeCreateScriptForObject(obj)) Workbench.copyToClipboard(''.join(script)) return 0 @ModuleInfo.plugin('wb.util.copyColumnNamesToClipboard', caption='Copy Column Names to Clipboard', input= [wbinputs.objectOfClass('db.Table')], groups= ['Catalog/Utilities', 'Menu/Objects']) @ModuleInfo.export(grt.INT, grt.classes.db_Table) def copyColumnNamesToClipboard(table): data = ', '.join([column.name for column in table.columns]) Workbench.copyToClipboard(data) return 0 @ModuleInfo.plugin('wb.util.copyTableListToClipboard', caption='Copy Table List to Clipboard', input= [wbinputs.currentCatalog()], groups= ['Catalog/Utilities', 'Menu/Catalog']) @ModuleInfo.export(grt.INT, grt.classes.db_Catalog) def copyTableListToClipboard(cat): #insert = ['`'+schema.name+'`.`'+tbl.name+'`' for tbl in schema.tables for schema in cat.schemata ] insert = '' for schema in cat.schemata: insert = insert + ', '.join(['`'+schema.name+'`.`'+tbl.name+'`' for tbl in schema.tables]) Workbench.copyToClipboard(insert) return 0 def generateName(name_prefix, names_map): name_suffix = 0 byte_a = ord('a') while True: for i in range(0, 25):
Schema::table('{tableName}', function (Blueprint $table) {{ ''' indexKeyTemplate = ''' $table->{indexType}([{keys}], '{indexType}_{tableName}'); ''' migrationEndingTemplate = ''' Schema::dropIfExists('{tableName}'); }} }} ''' @ModuleInfo.plugin('wb.util.generate_laravel5_migration', caption='Export Laravel 5 Migration', input=[wbinputs.currentCatalog()], groups=['Catalog/Utilities', 'Menu/Catalog']) @ModuleInfo.export(grt.INT, grt.classes.db_Catalog) def generate_laravel5_migration(cat): def create_tree(table_schema): tree = {} for tbl in sorted(table_schema.tables, key=lambda table: table.name): table_references = [] for key in tbl.foreignKeys: if key.name != '' and tbl.name != key.referencedColumns[ 0].owner.name and hasattr(key, 'referencedColumns'): table_references.append( key.referencedColumns[0].owner.name) tree[tbl.name] = table_references
script.append(grt.modules.DbMySQL.makeCreateScriptForObject(routine)) script.append(';\n\n') else: script.append(grt.modules.DbMySQL.makeCreateScriptForObject(obj)) grt.modules.Workbench.copyToClipboard(''.join(script)) return 0 @ModuleInfo.plugin('wb.util.copyColumnNamesToClipboard', caption='Copy Column Names to Clipboard', input= [wbinputs.objectOfClass('db.Table')], groups= ['Catalog/Utilities', 'Menu/Objects'], accessibilityName="Copy Column Names to Clipboard") @ModuleInfo.export(grt.INT, grt.classes.db_Table) def copyColumnNamesToClipboard(table): data = ', '.join([column.name for column in table.columns]) grt.modules.Workbench.copyToClipboard(data) return 0 @ModuleInfo.plugin('wb.util.copyTableListToClipboard', caption='Copy Table List to Clipboard', input= [wbinputs.currentCatalog()], groups= ['Catalog/Utilities', 'Menu/Catalog'], accessibilityName="Copy Table List to Clipboard") @ModuleInfo.export(grt.INT, grt.classes.db_Catalog) def copyTableListToClipboard(cat): #insert = ['`'+schema.name+'`.`'+tbl.name+'`' for tbl in schema.tables for schema in cat.schemata ] insert = '' for schema in cat.schemata: insert = insert + ', '.join(['`'+schema.name+'`.`'+tbl.name+'`' for tbl in schema.tables]) grt.modules.Workbench.copyToClipboard(insert) return 0 def generateName(name_prefix, names_map): name_suffix = 0 byte_a = ord('a') while True: for i in range(0, 25):
import grt import mforms from grt.modules import Workbench from wb import DefineModule, wbinputs from workbench.ui import WizardForm, WizardPage from mforms import newButton, newCodeEditor, FileChooser ModuleInfo = DefineModule(name='ExportSQLite', author='Tatsushi Demachi', version='0.1.0') @ModuleInfo.plugin('wb.util.exportSQLite', caption='Export SQLite CREATE script', input=[wbinputs.currentCatalog()], groups=['Catalog/Utilities', 'Menu/Catalog']) @ModuleInfo.export(grt.INT, grt.classes.db_Catalog) def exportSQLite(cat): """Function to go through all schemata in catalog and rename all FKs of table-objects """ def validate_for_sqlite_export(cat): """Check uniqueness of schema, table and index names. Return 0 on success otherwise return 1 (the export process should abort) """ have_errors = False idt = {} for i, schema in enumerate(cat.schemata):
# this is just a function used by the plugin, it's not exported def printTableLine(fields, filler= " "): print "|", for text, size in fields: print text.ljust(size, filler), "|", print # @wbexport makes this function be exported by the module and also describes the return and # argument types of the function # @wbplugin defines the name of the plugin to "wb.catalog.util.dumpColumns", sets the caption to be # shown in places like the menu, where to take input arguments from and also that it should be included # in the Catalog submenu in Plugins. @ModuleInfo.plugin("wb.catalog.util.dumpColumns", caption= "Dump All Table Columns", input= [wbinputs.currentCatalog()], pluginMenu= "Catalog") @ModuleInfo.export(grt.INT, grt.classes.db_Catalog) def printAllColumns(catalog): lines= [] schemalen= 0 tablelen= 0 columnlen= 0 typelen= 0 for schema in catalog.schemata: schemalen= max(schemalen, len(schema.name)) for table in schema.tables: tablelen= max(tablelen, len(table.name)) for column in table.columns: columnlen= max(columnlen, len(column.name)) typelen= max(typelen, len(column.formattedType))
# this is just a function used by the plugin, it's not exported def printTableLine(fields, filler= " "): print "|", for text, size in fields: print text.ljust(size, filler), "|", print # @wbexport makes this function be exported by the module and also describes the return and # argument types of the function # @wbplugin defines the name of the plugin to "wb.catalog.util.dumpColumns", sets the caption to be # shown in places like the menu, where to take input arguments from and also that it should be included # in the Catalog submenu in Plugins. @ModuleInfo.plugin("wb.catalog.util.dumpColumns", caption= "Dump All Table Columns", input= [wbinputs.currentCatalog()], pluginMenu= "Catalog", accessibilityName="Dump Columns") @ModuleInfo.export(grt.INT, grt.classes.db_Catalog) def printAllColumns(catalog): lines= [] schemalen= 0 tablelen= 0 columnlen= 0 typelen= 0 for schema in catalog.schemata: schemalen= max(schemalen, len(schema.name)) for table in schema.tables: tablelen= max(tablelen, len(table.name)) for column in table.columns: columnlen= max(columnlen, len(column.name)) typelen= max(typelen, len(column.formattedType))