dbTalk Databases Forums  

database driven applications: how should DBA's allow developers tomutate the database?

comp.databases comp.databases


Discuss database driven applications: how should DBA's allow developers tomutate the database? in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Ed Prochak
 
Posts: n/a

Default Re: database driven applications: how should DBA's allow developersto mutate the database? - 05-21-2010 , 06:59 PM






On May 20, 3:07*pm, metaperl <metap... (AT) gmail (DOT) com> wrote:
Quote:
On May 13, 12:54*pm, Tom Anderson <t... (AT) urchin (DOT) earth.li> wrote:

[]
I don't understand either of those concepts - either the idea that changes
to the database might not preserve entities and relationships, or E-R
creep. Could you give me some examples?

sure

1 - *changes to the database might not preserve entities and
relationships

Ok, if you have 2 entities joined by a primary-key foreign key
relationship and if you can never add a row to one table without a
related row in the other, and if there is only an advertised stored
proc which does the INSERT in a transaction to both tables, then the
preservation across tables is guaranteed. If developer code can write
to the database, then one table might be written to without the other.
That's why triggers and constraints were invented. Besides, who is
writing that INSERT procedure? The DBA?
Quote:
2 - Entity-relationship creep: here's a good example. You pull 100
rows from a customer table. And then you write a loop in your program
code, skipping over customers based on a series of if-thens, and then
do something with the remaining customers... basically what has
happened is that you were looking for some subset of the customers,
but did not specify that subset with a well-defined and business-
documented label. Instead you created a sub-entity of customers on the
fly with no documentation for that sub-entity.
That "on-the-fly" filtering might exactly be the business requirement.

How is this E-R creep??

Regarding documentation: that is a process issue. If your development
process does not include design documentation steps, you end up with
no documentation. It doesn't matter where the logic resides, or who
develops it.
Quote:


To be honest, my visceral reaction is that you are exactly the kind of
nutjob DBA who makes actually developing software a nightmare. However,i
am conscious that this is my guts talking, not my brain.

metaperl (me) is a Perl programmer ---http://www.metaperl.org

It's just I worked at oracle, which is where I learned the "read any
way you feel, updates are only via stored procedures that I look over
before they get added to the db"
Code reviews are a great step in a development process. Your earlier
comments gave the impression that there are developers and there are
those who write the INSERT procedures. Now it looks like the line is
not so sharp.

BTW even Oracle does not always follow the best practices.

Ed

Reply With Quote
  #12  
Old   
Tom Anderson
 
Posts: n/a

Default Re: database driven applications: how should DBA's allow developersto mutate the database? - 05-22-2010 , 02:18 PM






Whoops! Just realised i had meant to reply to this.

On Thu, 20 May 2010, metaperl wrote:

Quote:
On May 13, 12:54*pm, Tom Anderson <t... (AT) urchin (DOT) earth.li> wrote:
On Thu, 13 May 2010, metaperl wrote:

Instead, all updates and deletions are provided to the developer via
stored procedures. The motivation for controlling insert/update/delete
is to ensure that all changes to the database preserve entities and
relationships. It also prevents developers from "E-R Creep" --- that
is, it prevents developers from fattening their controllers and views
with implicit entities and relations that they identify and build in
program code in an unstructured, undocumented fashion.

I don't understand either of those concepts - either the idea that
changes to the database might not preserve entities and relationships,
or E-R creep. Could you give me some examples?

sure

1 - changes to the database might not preserve entities and
relationships

Ok, if you have 2 entities joined by a primary-key foreign key
relationship and if you can never add a row to one table without a
related row in the other, and if there is only an advertised stored proc
which does the INSERT in a transaction to both tables, then the
preservation across tables is guaranteed. If developer code can write to
the database, then one table might be written to without the other.
You can do this with constraints, can't you? You can make an assertion
right there in the table definition that documents the requirement,
enforces it, and leaves the tables open for access from any direction.

I appreciate that you can do more in a stored procedure than you can in a
constraint, because of the limits on syntax available in constraints (in
some systems, at least). To recycle my product/price example, if you
wanted to modify this definition:

create table product (
product_id integer primary key
-- other fields
);

create table price (
country char(2) not null,
product_id integer not null references product,
constraint price_pk primary key (country_code, product_id),
price integer not null
);

So that you couldn't insert a product without at least one price, then
you'd want to write something like:

create table product (
product_id integer primary key
check (exists (select * from price p where p.product_id = product_id))
);

But i know you can't do that in PostgreSQL, and i suspect you can't do it
in most databases.

You can work around this with a nasty hack:

create table product (
product_id integer primary key,
example_price_country char(2) not null,
constraint product_price_fk foreign key (example_price_country, product_id) references price
);

where you explicitly name a country that will have a price, and use a
foreign key constraint to that. Like i said, nasty.

Quote:
2 - Entity-relationship creep: here's a good example. You pull 100 rows
from a customer table. And then you write a loop in your program code,
skipping over customers based on a series of if-thens, and then do
something with the remaining customers... basically what has happened is
that you were looking for some subset of the customers, but did not
specify that subset with a well-defined and business- documented label.
Instead you created a sub-entity of customers on the fly with no
documentation for that sub-entity.
Except for the code that does it, which is perfectly accurate
documentation. Moving the selection from code into a stored procedure
doesn't improve that documentation, it just moves it out of the code,
where only programmers can read it, into the database, where only DBAs can
read it.

Also, i thought you were talking about only restricting mutation, and
letting programmers do any kind of query?

tom

--
A playwright is not the best person to talk about his own work for
the simple reason that he is often unaware of what he has written. --
Alan Bennett

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.