On Fri, May 6, 2011 at 12:05 PM, <no-re...@cfengine.com> wrote: > Forum: Cfengine Help > Subject: Re: Running a command just once. > Author: jeromebaum > Link to topic: https://cfengine.com/forum/read.php?3,21797,21800#msg-21800 > > Was just working on a config today. Part of it was "create a database w/ its > tables, add some stored procedures, import a development snapshot dump" but > only if this wasn't already done (obviously). How do you do that in a > convergent fashion? > > So: > > > 1. Create database > 2. Import schema > 3. Import stored procedures > 4. Import a dump > > > All of these only if necessary. I can see handling #1 -- just check if the > database exists. #2 dito, #3 would be a bit more hard but I guess dito. #4 is > the troublesome thing. How do I know if "the dump has been imported" in a > clean fashion? Check if there is "some data" in the DB? What if it was > partially applied? etc. > > I think using a flag file sounds fine. Yes, if it's deleted then re-running > the script should bring it back to an expected state, not break it. But yes, > the flag file sounds good to prevent starting a long-running script, or > something. > > What's your take? Is cfengine the wrong tool to import the dump? This, btw, > is for provisioning a devel workstation.
In effect, you have a non-idempotent process. It needs to be more like: 1. If database does not exist then 1.1 Create database 2. If schema seems not to be loaded then 2.1 Load schema 3. Load stored procedures (this is quite likely idempotent-ish already), but perhaps with a "guard" that says, "don't do it if they're already there!" 4. If schema is empty then 4.1 Load data dump into schema That's a rather more "convergent" way to cope with those actions. The exact logic for the "is it there?" tests is certainly open to debate; it's possible that the schema might have gotten only partly loaded, in which case it would be apropos to either drop and retry or to try to continue what failed to be loaded. In a database that supports transactional DDL, I'd be keen on loading the schema in as a single transaction, so it would either *ALL* load, or *ALL* fail, so that the "partial" question doesn't emerge. Most databases these days support loading data in a transaction, which makes it mighty attractive for "load data dump" to come as a single transaction (assuming it's not so large you have to worry about Oracle rollback segment size, or such), so that, again, it'll either "all load" or "all fail." _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine