powerdesigner - 在 PowerDesigner 中创建表时如何插入默认列
问题描述
我们有几个列在所有表中都是必需的。列用于审计、记录日期等。配置 PowerDesigner 以在物理模型中创建时自动将这些列添加到表中的过程是什么?
我正在使用 PowerDesigner 16.5。
我已经能够将默认触发器插入到触发器模板项中的 DBMS 属性中,我可以在其中为所有表插入几个默认触发器(尽管我仍在学习 PD 中使用的“语言”),并且在每个表中我将插入默认触发器。
解决方案
我看到了几种将设计助手添加到 PDM 的方法:
- 将其添加到 Table 类的 Initialize 事件处理程序中
- 在 Table 类中创建一个 Menu 以将它们添加到现有表中
对于所有这些,最好将这些工具定义在一个单独的扩展 ( Tools > Resources > Extensions > Physical Data Models...
) 中,也许使用Auto attach
,以便它可以在多个模型之间共享。Model > Extensions > Attach an Extension
然后,您可以使用工具栏项将其附加到现有模型。
你可以用标准的VBScript来做,这是一种实际的语言,不仅在 PD 中使用......
以下所有元素都包含在此扩展中。
在全局脚本中,实际添加默认列的代码。
function ColumnExists(tab, name)
if tab.ClassName = "Table" then
dim col
for each col in tab.Columns
if col.Name = name then
ColumnExists = true
exit function
end if
next
end if
ColumnExists = false
end function
Sub DoCreateColumns(tab)
if not tab.ClassName = "Table" then exit sub
dim c
if not ColumnExists(tab,"AuditDate") then
set c = tab.CreateObject(cls_Column)
c.Name = "AuditDate"
c.Code = "ADDT"
c.DataType = "datetime"
output "... adding column AuditDate"
end if
End Sub
在 Table 类上,用于初始化的事件处理程序:
Function %Initialize%(obj)
DoCreateColumns obj
%Initialize% = True
End Function
对于 Table 上下文菜单,您需要一个 Method,例如 CreateColumns:
Sub %Method%(tab)
DoCreateColumns tab
End Sub
和一个菜单,例如 CreateColumns(实际的上下文菜单条目名称取自您在 XML 选项卡中编辑的命令标题...):
<Menu>
<Command Name="CreateColumns" Caption="Create Standard Columns" />
</Menu>