From: Ian Jackson Subject: Re: [OSSTEST PATCH 5/8] Schema: Support database schema updates Date: Thu, 10 Dec 2015 18:00:52 +0000 Message-ID: <22121.48596.663367.284017@mariner.uk.xensource.com> References: <1449767545-9410-1-git-send-email-ian.jackson@eu.citrix.com> <1449767545-9410-6-git-send-email-ian.jackson@eu.citrix.com> <1449769713.9759.111.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a75WT-0001WB-NN for xen-devel@lists.xenproject.org; Thu, 10 Dec 2015 18:00:57 +0000 In-Reply-To: <1449769713.9759.111.camel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: xen-devel@lists.xenproject.org, Ian Jackson List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("Re: [OSSTEST PATCH 5/8] Schema: Support database sche= ma updates"): > On Thu, 2015-12-10 at 17:12 +0000, Ian Jackson wrote: > > + is a positive integer, which should be unique.=A0=A0Updates= are > > +applied in order. > = > Don't these also need to be monotonically increasing over time/commits? > = > i.e. committing (and applying through all the states) sequence #42 and th= en > later committing #12 would be at best confusing and at worse perhaps > produce different results when recreating the db (which, I think, would r= un > #12 first). > = > So maybe the rule needs to be something about being larger than the large= st > currently applied patch? It does say that updates are applied in order. I will add `and monotonically increasing' after `unique'. > > + reflects the compatibility of various schema versions.=A0=A0I= t is > > +a literal string naming one of the statuses shown in `Update orders', > > +below. > > + > > + depends on the nature of the specific database change, and > > +the behaviour and capabilities of the other code in the same revision > > +of osstest.git.=A0=A0But, so does not depend on the state of = the > > +database.=A0=A0Applying a schema update to a database does not change = its > > +`status'. > = > "But, so ..." ? I think maybe s/But, s/S/ is what you meant? Or maybe the= re > was a missing thought? I reordered this, and the `so' is spurious. It should just say `But, does not depend...'. > It's not stated outright, but AIUI the of an update changes in a > commit which either adds/edits a schema update, or which adds code which > adds compatibility/requirements for a particular schema update. Is that > right? Yes. I think it should be clear from the rest of the discussion and I'm not sure that adding some more text here would help clarify things overall. > > +=A0=A0=A0Such a schema change always has status: > > +=A0=A0=A0=A0=A0=A0Harmless > = > What happens if some subsequent change (perhaps a long time later) causes > the code to require the changes made by a "Harmless" schema update? > = > Would that be a bug in that later code for not coping with the old schema, > or a bug in the commit adding it for not updating the header of the schema > update (to "Needed", presumably) or is it not an issue because there is > some point at which a schema update becomes part of the assumed baseline? If code starts to depend on the schema change, it should be changed to Needed when the code is changed. In practice this is not likely to be a problem because the update will have been applied a long time ago. > > + * Explicit conditional: first update the code to understand both > > +=A0=A0=A0versions of the schema; then update the schema; then drop the > > +=A0=A0=A0compatibility code. > > + > > +=A0=A0=A0Such a schema change always has status: > > +=A0=A0=A0=A0=A0=A0Unfinished (or absent)=A0=A0=A0in old code > > +=A0=A0=A0=A0=A0=A0Ready=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0in intermediate code > > +=A0=A0=A0=A0=A0=A0Needed=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0in the final code > = > So, a plausible sequence of commits to osstest.git might be: > = > 1: Add schema/foo.update with initial status "Unfinished". > 2a: Add code to partially implement compat with the new schema: > no status change > [2b,2c...] more compat or unrelated changes > 3: Add final code to completely implement compat with the new schema: > status changed to "Ready" in that same commit > 4a,b,c: Maybe other unrelated changes > 5: Remove any piece code which provides support for the old schema: > status changes to "Needed" > 6: Eventually remove remove other compat code. > = > I've broken down the addition/removal of compat code into stages to > illustrate, that code might really all come/go in a single commit. Yes. > > +Update order for Populate-then-rely > > +----------------------------------- > > + > > +This is for when we want to record new information and then later rely > > +on it.=A0=A0There are typically two schema changes: > > + > > +* To add the column(s).=A0=A0I will call this `add'.=A0=A0It is a `Sch= ema > > +=A0=A0first' change, in the taxonomy above. > > + > > +* To add appropriate constraints, to prevent the new information being > > +=A0=A0left blank.=A0=A0I will call this `constraint'.=A0=A0This is a `= Code first' > > +=A0=A0or `Explicit conditional' change in the taxonomy above. > > + > > +1. Commit: new schema update `add', status Preparatory. > > + > > +2. Commit: new schema update `constraint', status Unfinished. > = > At this point we want to wait for those commits to pass the push gate, > before we can apply `add', since applying `add' should be done from a > "properly acked version of osstest.git". > = > This is made pretty clear by the following commentary, for `Apply' but I > wanted to check I'd got the placement of the wait correct. Yes. > > +Statuses and rules for push and db update > > +----------------------------------------- > > + > > +=A0=A0Harmless > > +=A0=A0Preparatory > > +=A0=A0=A0=A0=A0No restrictions > > + > > +=A0=A0Unfinished > > +=A0=A0(sql fragment entirely missing is equivalent to Unfinished) > > +=A0=A0=A0=A0=A0Schema update: prevented > = > In the case of "entirely missing" "prevented" must really mean "there can= 't > possibly be anything to do/prevent"? Well, if you say ./mg-schema-update apply this-update-does-not-exist it will bomb out. And ./mg-schema-update apply-all will not invent imaginary schema changes out of thin air so that it can apply them. So, application of nonexistent schema changes is indeed prevented by their nonexistence. Ian.