Last active
September 24, 2019 06:31
-
-
Save shishir/709e9d81a63f59256ef43ea958294f58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference: https://dataedo.com/kb/tools/mysql-workbench/how-to-export-data-dictionary | |
from wb import * | |
import grt | |
from mforms import Utilities, FileChooser | |
import mforms | |
import csv | |
ModuleInfo = DefineModule(name="DBReport", author="Shishir Das", version="1.0", description="Database schema dump in csv") | |
@ModuleInfo.plugin("rsn86.DBDocPy.mysqlDbSchemaInCsv", caption="Database schema report in csv format", description="Database schema report in CSV format", input=[wbinputs.currentCatalog()], pluginMenu="Catalog") | |
@ModuleInfo.export(grt.INT, grt.classes.db_Catalog) | |
def dbSchemaInCsv(catalog): | |
schema = catalog.schemata[1] | |
print schema.tables | |
header = ["name", "data type", "nullable", "pk", "fk", "default", "comment"] | |
for table in schema.tables: | |
with open("/tmp/"+table.name+".csv", 'w') as csvfile: | |
writer = csv.writer(csvfile) | |
writer.writerow(header) | |
for column in table.columns: | |
pk = ('No', 'Yes')[bool(table.isPrimaryKeyColumn(column))] | |
fk = ('No', 'Yes')[bool(table.isForeignKeyColumn(column))] | |
nn = ('No', 'Yes')[bool(column.isNotNull)] | |
writer.writerow([column.name,column.formattedType,nn,pk,fk,column.defaultValue,column.comment]) | |
csvfile.close() | |
Utilities.show_message("Report generated", "CSV Report format generated in tmp directory", "OK","","") | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment