Discussion:
Add columns to all entities (LDM)
(too old to reply)
Ndy
2010-09-15 15:30:51 UTC
Permalink
Hi,

We have 300+ entities in our LDM and we want to add column to all or
certain table.
For exemple we want to add lastupdatedate column for all table that
don't have it.
It is way to long to do it manualy for every entities ...

So, is there a way to do it ?


Thank you
Mark Brady
2010-09-15 17:39:46 UTC
Permalink
Post by Ndy
Hi,
We have 300+ entities in our LDM and we want to add column to all or
certain table.
For exemple we want to add lastupdatedate column for all table that
don't have it.
It is way to long to do it manualy for every entities ...
So, is there a way to do it ?
Thank you
First off, why have you decided to put that in a Logical Data Model?
That column is purely a physical database construct and not related to
your entities so it's probably a better fit in your PDM. Besides your
PDM may have more tables than your LDM has entities, do you want that
column on every TABLE?
Ndy
2010-09-15 19:02:26 UTC
Permalink
Post by Mark Brady
Post by Ndy
Hi,
We have 300+ entities in our LDM and we want to add column to all or
certain table.
For exemple we want to add lastupdatedate column for all table that
don't have it.
It is way to long to do it manualy for every entities ...
So, is there a way to do it ?
Thank you
First off, why have you decided to put that in a Logical Data Model?
That column is purely a physical database construct and not related to
your entities so it's probably a better fit in your PDM. Besides your
PDM may have more tables than your LDM has entities, do you want that
column on every TABLE?
I have the complete model on the LDM (all tables, all columns).
I have to generate one PDM for oracle and one PDM for SQL Serveur from
the LDM. Both must have the exact same structure (table name and
column name).
The lastupdatedate column was just an exemple. If i forgot to add an
ROW_IS_DELETED or another column to all entities/tables, or just half
of them : how do i do that ? that is the question ...
rkkier
2010-09-16 14:04:07 UTC
Permalink
Here'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
Mark Brady
2010-09-16 17:14:39 UTC
Permalink
Post by rkkier
Here'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.
rkkier
2010-10-13 03:24:27 UTC
Permalink
Sybase did a webcast the other week which probably gives you a lot of
what you want. The portion on transformations (about half way
through) is fantastic. I've already begun using them for several of
our projects. Basically, you can have PD add what you want
automatically when you generate the PDM based on the target RDBMS.

http://response.sybase.com/forms/NAO_10_SEP_WBCST_PD_Blueprint_Techcast_Replay?mc=SY.com
Loading...