Return-Path: X-Original-To: apmail-aurora-dev-archive@minotaur.apache.org Delivered-To: apmail-aurora-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 10ECB191B0 for ; Thu, 24 Mar 2016 14:25:49 +0000 (UTC) Received: (qmail 80174 invoked by uid 500); 24 Mar 2016 14:25:48 -0000 Delivered-To: apmail-aurora-dev-archive@aurora.apache.org Received: (qmail 80120 invoked by uid 500); 24 Mar 2016 14:25:48 -0000 Mailing-List: contact dev-help@aurora.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aurora.apache.org Delivered-To: mailing list dev@aurora.apache.org Received: (qmail 80102 invoked by uid 99); 24 Mar 2016 14:25:48 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Mar 2016 14:25:48 +0000 Received: from mail-qg0-f50.google.com (mail-qg0-f50.google.com [209.85.192.50]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 08F2E1A01A6 for ; Thu, 24 Mar 2016 14:25:47 +0000 (UTC) Received: by mail-qg0-f50.google.com with SMTP id j35so39320702qge.0 for ; Thu, 24 Mar 2016 07:25:47 -0700 (PDT) X-Gm-Message-State: AD7BkJLwCyaIwX20wMbaCdoLPpiEzNMpDwX+ffyxjegWPmg8x29ySkRcdNnyqr7bB+XohcRGEJxV3GTvxIEckA== MIME-Version: 1.0 X-Received: by 10.140.19.52 with SMTP id 49mr10911674qgg.103.1458829547109; Thu, 24 Mar 2016 07:25:47 -0700 (PDT) Received: by 10.55.188.196 with HTTP; Thu, 24 Mar 2016 07:25:47 -0700 (PDT) In-Reply-To: References: Date: Thu, 24 Mar 2016 09:25:47 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Handling migrations if dbScript exists in snapshot? From: Joshua Cohen To: dev@aurora.apache.org Cc: John Sirois Content-Type: multipart/alternative; boundary=001a113540d8f1a49c052ecc38e7 --001a113540d8f1a49c052ecc38e7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Flyway has a fairly well reasoned response to the downgrades question: https://flywaydb.org/documentation/faq#downgrade I think in the event that we have to rollback after applying a change like you describe we'd either have to resort to a manual fix or restore from backup. The other thing to keep in mind is that this problem is not solved by rolling our own migration solution either. Another option that may be worth considering is mybatis migrations: http://www.mybatis.org/migrations/runtime-migration.html. On Wed, Mar 23, 2016 at 11:34 PM, Maxim Khutornenko wrote: > +1 to giving flyway a try. I have used it before and it *mostly* > worked. There were a few hiccups occasionally when it couldn=E2=80=99t > properly recognize the DB drift and failed to apply the update but > that was entirely incremental build-related problem (flyway was > integrated into the build process). > > What flyway does not support is version rollbacks. It's not applicable > to this particular change but I am sure there will be changes where > we'd need to move data as part of DB upgrade. If we then decide to > rollback due to an unforeseen problem we would have to have reverse > migration script(s). Not impossible but something to keep in mind. > > > > On Wed, Mar 23, 2016 at 4:41 PM, Florian Pfeiffer > wrote: > > We're using flyway for our services, and from an ops perspective I'm > quite > > happy with it. On test it's allowed to apply the migrations > > automatically... on prod we're doing it manually after reviewing. No > > problems so far. > > I can't really tell anything from the dev side, beside that I haven't > > heard them complaining about it (and normally they are complaining quit= e > > fast ;) )... > > > > Another thing that's similar to flyway is http://www.liquibase.org/ but > for > > that I have zero experience. > > > > Flo > > > > > > On 23 March 2016 at 22:41, Joshua Cohen wrote: > > > >> If we go with option 2 (which I'm leaning towards as well), does anyon= e > >> have thoughts on using (or experience with) something like Flyway: > >> https://flywaydb.org/ rather than implementing from scratch? > >> > >> On Wed, Mar 23, 2016 at 3:29 PM, John Sirois > wrote: > >> > >> > On Wed, Mar 23, 2016 at 2:21 PM, Joshua Cohen > wrote: > >> > > >> > > Hi Aurorans, > >> > > > >> > > As you may have seen ( > >> https://issues.apache.org/jira/browse/AURORA-1648 > >> > ), > >> > > we ran into an issue when upgrading a cluster that uses dbScripts = in > >> > > snapshots. To restate the problem from the ticket, when the > scheduler > >> > > starts up it creates the H2 database from schema.sql which contain= s > >> newly > >> > > added (or changed) tables. If the dbScript exists in the snapshot, > it > >> > then > >> > > drops all tables and runs the script which re-creates the database > in > >> the > >> > > form it was previously in and repopulates all the data. At this > point, > >> > if a > >> > > table was added that was not in the snapshot, that table is lost. > >> > > > >> > > The solution here is to be run a migration after restoring the > >> database, > >> > my > >> > > question is what level of complexity do we want for migrations. I > see > >> two > >> > > possible options: > >> > > > >> > > > >> > > 1. The relatively simple approach where we have a single > >> migration.sql > >> > > alongside schema.sql which contains any changes to run against > the > >> > > database. After restoring the db from a dbScript in the > snapshot, we > >> > > would > >> > > run this script. On release boundaries(?), we clear the script > out. > >> > The > >> > > main caveat here is that the ddl statements in this script must > be > >> > > idempotent since they would potentially be run multiple times. > >> Another > >> > > issue is this would make it more complicated to jump over > versions > >> > > (upgrading from v0.12.0 to v0.14.0 means you might miss a > migration > >> > that > >> > > only existed in the 0.13.0 release). > >> > > 2. A slightly more involved approach would be to track the sche= ma > >> > > version in the database itself. Instead of having a single > >> > migration.sql > >> > > script that contains all migrations, we could instead have > >> > > migrations/001.sql, migrations/002.sql, etc. We'd add a new > table to > >> > the > >> > > database to track which migrations have been run. After restori= ng > >> via > >> > > dbScript, we'd check the table and run any migrations necessary > (or > >> > all > >> > > of > >> > > the table does not exist). > >> > > > >> > > Thoughts on these options? > >> > > > >> > > >> > I have used 2 a few times in the past and my take is it only more > complex > >> > in 1 fixed piece of (java) code that can be well unit tested. The s= ql > >> > scripts are easier to read and write and reason about for devs and > >> > operators alike. > >> > > >> > > >> > > > >> > > Anyone have any alternatives? > >> > > > >> > > Cheers, > >> > > > >> > > Joshua > >> > > > >> > > >> > > > > > > > > -- > > Head of Data & Infrastructure > > florian.pfeiffer@gutefrage.net > > +49-89-515146-173 > > > > gutefrage.net GmbH > > Ein Unternehmen der Verlagsgruppe Georg von Holtzbrinck > > Erika-Mann-Str 23 > > 80636 M=C3=BCnchen > --001a113540d8f1a49c052ecc38e7--