Auto-renaming columns in PowerDesigner LDM/PDM
I want to rename columns in a PowerDesigner LDM/PDM according to the state of the Primary checkbox. To be more specific, I want the column renamed from "oldname" to "id_oldname" if Primary is checked.
I think it is possible 开发者_StackOverflow中文版with a custom check/autofix script like the one in "MSSQLSRV2008::Profile\Column\Custom Checks\Identity Seed and Increment validity" but I'm really not a VBScript expert :)
Is there an easy way to achieve that in PowerDesigner 15?
The solution is quite simple. Unfortunately not a flawless one, because PowerDesigner fails to execute the event handler in some cases (for some unknown reason). The small vbscript below should be able to handle it. An extended model definition file is to be created and attached to the project. The script is a Validate Event Handler of the Table metaclass (though it's rather an autofix than a validation).
Function %Validate%(obj, ByRef message)
' Implement your object validation rule on <parent> here
' and return True in case of success, False otherwise with a message
dim col
for each col in obj.columns
if col.Primary = true then
if left(col.name,3) <> "id_" then
With col
.name = "id_" & .name
.SetNameAndCode .Name, "", True
End With
end if
else
if left(col.name,3) = "id_" then
with col
.name = right(.name, len(.name)-3)
.SetNameAndCode .Name, "", True
end with
end if
end if
next
%Validate% = True
End Function
The credit goes to Richard Kier who supplied the original code. Thanks, Richard.
One can write the VBScript to trawl the object model, looking for columns that are members of primary keys and renaming them.
Or:
One can bring up a list of columns (Right click on a package or the model, List of -> Columns)
Press control-U (or click on the funnel-and-pencil icon) to bring up Customize Columns and Filter.
- Find the Primary Key entry in the Column Heading column.
- In the Filter Expression, set the expression to True.
- Check the U column for the Primary Key entry, and make sure no other rows have that checked.
- Press Apply.
You should now see all the columns that are part of keys. You can similarly filter with wildcards for non-compliant names. You can also select multiple rows and rename them at the same time.
There is a much simpler method to this.
- Go to Database - Generate Database - Save the generated sql file.
- Use a text editor to rename or whatever edits are needed.
- Go to Database - Update Model from Database - point to the sql file generated.
The tool shows the updated model.
精彩评论