[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH 1/9] mg-schema-test-database: Revamp sequence handling



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@xxxxxxxxxxxxx>
---
 mg-schema-test-database | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/mg-schema-test-database b/mg-schema-test-database
index 5ebba39..a82c044 100755
--- a/mg-schema-test-database
+++ b/mg-schema-test-database
@@ -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..."
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.