擅长:python、mysql、java
<p>我知道有人问这个问题已经两年了</p>
<pre><code>import grt
#import mforms
# tables you want to skip
skip_tables = ["main_defs","some_other_table"]
def addColumn(table,name,datatype,defaultvalue):
# skip this column_name if there is already a column with this name
column_names = [x.name for x in table.columns]
if name in column_names:
return
column = grt.classes.db_mysql_Column()
column.name = name
table.addColumn(column)
column.setParseType(datatype, datatypes)
column.defaultValue = defaultvalue
column.isNotNull=1
# get a reference to the schema in the model. This will get the 1st schema in it.
schema = grt.root.wb.doc.physicalModels[0].catalog.schemata[0]
datatypes = grt.root.wb.rdbmsMgmt.rdbms[0].simpleDatatypes
# iterate through all tables
for table in schema.tables:
# skip the current table if it is in skip_tables
if table.name in skip_tables:
continue
addColumn(table,"created_at","varchar(45)","")
addColumn(table,"updated_at","varchar(45)","")
</code></pre>
<p>这提供了一个基本的理解如何做到这一点</p>