]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
mg-schema-test-database: Revamp sequence handling
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 12 Dec 2016 13:18:29 +0000 (13:18 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 20 Dec 2016 17:05:11 +0000 (17:05 +0000)
The initial value (at creation time) of a sequence appears in the
schema, but is not of any consequence.  To avoid the schema diff check
failing in databases created in a slightly different way, it is
necessary to copy the actual original initial sequence value for each
sequence.

Replace the sequence handling code with a setup which, for each
sequence, copies the START WITH and calculates a fresh RESTART WITH.

This replaces both the unconditional copy (done with pgdump) and the
special calculation of the next flight number.  Now all sequences have
the "bump the number somewhat" treatment, which seems nice.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
mg-schema-test-database

index 5ebba39f30ab5f0d8b596222b29b241792a4f76c..a82c044e0700951e204c5c09f766a86af10b1284 100755 (executable)
@@ -413,6 +413,28 @@ END
 
        withtest ./mg-schema-update -q apply $wantupdates
 
+        printf " (seqs)"
+        seq_alters=""
+        for seq in $sequences; do
+               orgseqval=$(psql_query <<END
+                       SELECT start_value || ' ' || last_value FROM $seq
+END
+                )
+                read orgstart orglast <<END
+$orgseqval
+END
+               newlast=$(( 10000 * (2 + $orglast / 10000) ))
+                seq_alters+="
+                       ALTER SEQUENCE $seq
+                               START WITH $orgstart
+                               RESTART WITH $newlast;
+"
+        done
+       (withtest psql_do <<END
+$seq_alters
+END
+        )
+
        printf ".\n"
 
        # Schema should now be identical to main DB
@@ -444,14 +466,6 @@ END
                SET CONSTRAINTS ALL DEFERRED;
 END
 
-       $(get_pgdump_cmd) -a -O -x ${sequences// / -t } >$t.sequences-import
-       perl <$t.sequences-import >>$t.import -ne '
-               next if m/^--/;
-               next if m/^SET /;
-               next unless m/\S/;
-               print or die $!;
-       '
-
        for table in $tables; do
                case " $ftables " in
                *" $table "*)   condition="flight >= $minflight" ;;
@@ -490,19 +504,6 @@ END
 
        rm -f $t.tabledata.*
 
-       printf "flightseq..."
-
-       lastflight=$(psql_query <<END
-               SELECT last_value FROM flights_flight_seq
-END
-               )
-       newlastflight=$(( 10000 * (2 + $lastflight / 10000) ))
-
-       withtest psql_do <<END
-               ALTER SEQUENCE flights_flight_seq
-                       RESTART WITH $newlastflight;
-END
-
        #---------- actually borrow resources ----------
 
        printf "borrow..."