We have several columns that are required in all tables. Columns are used for audit, record dates, etc. What is the process for configuring PowerDesigner to automatically add these columns to the table when created in the physical model?
I am using PowerDesigner 16.5.
I have already been able to insert default triggers into DBMS Properties in Trigger Template Items, where I can insert several default triggers for all tables (although I am still learning the "language" used in PD), and in each table I will insert the default triggers.
I see several ways to add design helpers to your PDM:
For all these, it is better to define these tools in a separate extension (Tools > Resources > Extensions > Physical Data Models...
), maybe with Auto attach
, so that it can be shared between several models. Then you can attach it to your existing model with the Model > Extensions > Attach an Extension
toolbar item.
And you can do it in standard VBScript, which is an actual language, and not only used in PD...
All the following elements go in this extension.
In the Global Script, the code to actually add the default columns.
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
On the Table class, an Event Handler for Initialize:
Function %Initialize%(obj)
DoCreateColumns obj
%Initialize% = True
End Function
And for the Table contextual menu, you need a Method, e.g. CreateColumns:
Sub %Method%(tab)
DoCreateColumns tab
End Sub
and a Menu, e.g. CreateColumns (the actual contextual menu entry name is taken from the Command Caption, that you edit in the XML tab...):
<Menu>
<Command Name="CreateColumns" Caption="Create Standard Columns" />
</Menu>