BTW, thanks for a great tool and responses.
On 05/28/2015 12:13 PM, David E. Wheeler wrote:
> On May 28, 2015, at 7:52 AM, Jonathan Rogers <
jonatha...@gmail.com> wrote:
>
>> If there's a table with a bunch of rows in it and you DELETE FROM or
>> TRUNCATE it, how could you get those rows back without consulting some
>> sort of backup? An UPDATE also frequently loses information.
>
> I find that I don’t often have DML in my deployment scripts, usually only for data that rarely changes (like a table listing states or something). If I had to update such a table, I would do so in a single deploy script, and handle any other related updates (FK references, etc.), in a single transaction. It’s rare that I want to do a whole mess of DML at once; generally, I’m able to factor my database changes into discrete chunks that make sense to use as individual changes that depend on each other. But if I did have such a level of interdependency, I would put those in a single script, too.
>
I often need to execute DML statements in deploy scripts. Often, it's in
static tables such as your states example. Sometimes, it's to augment or
correct dynamic tables.
> But that script would just have DML, no DDL. DDL statements would be in their own scripts.
I often have DML and DDL that are mutually dependent. For example, I've
added a column which refers to another table, updated the column, then
added a foreign key. Other times, I've added a constraint on a table
implemented by a CHECK or trigger after updating the table to comply
with the new constraint.
It's a nice idea, but I'm not sure that the extra effort to always
separate DML from DDL is worth it for my needs. I'm also not sure what
this means: "Conditions must deal with side-effects, such as foreign key
constraints." I can't see how it makes sense to describe a declarative
data constraint as a "side-effect."
After experimenting with small, concise Sqitch changes for a while, I'm
wondering if it would be possible to get the benefits of that approach
without abandoning the benefits of transactions. For example, Sqitch
could concatenate the SQL from all scripts to deploy and pass them to
psql as a unit, allowing them all to execute within a single
transaction. Of course, each deploy script would need to be free of
BEGINs and COMMITs.
--
Jonathan Rogers