Post by rkkierHere's a basic script that should get you started.
We do something similar but still don't put the columns in our LDMs.
We use a standard PDM script that adds the same audit columns to all
tables but it does a few optimizations for each target RDBMS
(indexing, datatypes etc). If you do put them in the LDM, you might
want to mark them as not displayed to keep things neat and tidy.
dim Col, Tab
for each Tab in ActiveModel.Entities
output "Processing " & Tab.name
Set Col = Tab.CreateObject(PdLDM.cls_EntityAttribute)
With Col
.Name = "Column Name"
.SetNameAndCode .Name, "", True '<-- generate the column code using
the pre-defined naming conventions.
.DataType = "date"
.Mandatory = true
.Comment = "Audit trail column indicating which user created the
record"
End With
next
Ok, whether you generating it to two PDMs or one doesn't mean it has
to be ON the entities. This can be done as part of the generation
process.
I'm hoping that someone will post that here. I'm not as familiar with
that method, but it is the best method and the correct one. I will
give you something that can get you there.
You want to add an extended attribute to Entity Metaclass called
"Logical Delete" (that's the name for having a column represent a
deleted row)
Make the datatype boolean.
Set the value of Logical Delete to TRUE on every entity that you want
to add the column: ROW_IS_DELETED.
An easy way to do this is by changing the columns in a list view of
entities like in the model menu. Have you done that before? (BTW,
these questions are just to see if there are other tips I can pass
along)
You could add another one for "Audited" if you think the
lastupdatedate doesn't belong on 100% of the tables.
Then you would run a script which would look something like this.
For each oEntity in activemodel loop
IF oEntity.ExtendedAttribute("Logical Delete") = TRUE THEN 'no
need for = TRUE, just making it more readable.
bHasColumnAlready = FALSE
For each oAtt in oEntity.Attributes Loop
If uCase(oAtt.Name) = "ROW_IS_DELETED" THEN
bHasColumnAlready = TRUE
END IF
NEXT
If NOT bHasColumnAlready = TRUE THEN
Set oNew = oEntity.attributes.addnew
oNew.Name = "ROW_IS_DELETED"
' the you set the oNew.domain to keep everything the same;
datatype, standard checks etc.
end if
end if
next
I started this yesterday before rkk posted his... you can combine the
two of them.
His script assumes the column is not there yet.
I think that datatype and mandatory should be in a domain that you
set. Especially since your column will be either (Y or N) (Y or null)
or (null or N) so you'll be setting those standard checks as well...
If you'll have big skew in that column and you'll need an index (I
imagine that appears in most where clauses)... you'll want to stick
with one of the later two, at least for Oracle. If you're using Y/N,
ask me why you shouldn't.
You can also use the code in order to set the "displayed" value as
well. That was a great suggestion.