Created
May 25, 2010 04:25
-
-
Save elmariofredo/412756 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
# | |
# wb_utils.grt.py | |
# MySQLWorkbench | |
# | |
# Created by Kuru on 25/Mar/10. | |
# Copyright (c) 2010 KuruLab. There are many rights to fuckup... Ricky TPB. | |
# | |
# This Pyhon script simply export your MySQLWorkBench project to rails scaffold commandline | |
# This is just concept of final plugin which i hope will be in old good pure ruby... depends on oracle now ;-) | |
# | |
# import the wb module | |
from wb import * | |
# import the grt module | |
import grt | |
# import regular expression module | |
import re | |
# define this Python module as a GRT module | |
ModuleInfo = DefineModule(name= "PyWbBrails", author= "KuruLab", version="0.1") | |
# Translate mysql types to rails ones | |
# TODO: add these types using wbDataType | |
# :float | |
# :datetime | |
# :timestamp | |
# :time | |
# :binary | |
# :boolean | |
def rDataTypes(wbCurrentColumnType): | |
if re.match("VARCHAR", wbCurrentColumnType): | |
return "string" | |
elif re.match(".*INT", wbCurrentColumnType): | |
return "integer" | |
elif re.match("TEXT", wbCurrentColumnType): | |
return "text" | |
elif re.match("DATE", wbCurrentColumnType): | |
return "date" | |
else: | |
return "!!!-UNKNOWN-TYPE-"+wbCurrentColumnType+"-!!!" | |
@ModuleInfo.plugin("wb.catalog.barils.dumpColumns", caption= "BRails Simple Scaffold Export", input= [wbinputs.currentCatalog()], pluginMenu= "Catalog") | |
@ModuleInfo.export(grt.INT, grt.classes.db_Catalog) | |
def printBrails(catalog): | |
for schema in catalog.schemata: | |
print ">>Schema:", schema.name | |
for table in schema.tables: | |
# TODO: singularize&capitalize table name see http://code.activestate.com/recipes/82102/ | |
print "rails g scaffold ", table.name, " ", | |
for column in table.columns: | |
print column.name+":"+rDataTypes(column.formattedType), | |
print "<<Schema:", schema.name | |
print "Well done... and don't forget always smile 8)" | |
return 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment