]> xenbits.xensource.com Git - osstest.git/commitdiff
mg-schema-test-database: posgtres compat: psql transactions
authorIan Jackson <iwj@xenproject.org>
Tue, 27 Apr 2021 17:43:23 +0000 (17:43 +0000)
committerIan Jackson <iwj@xenproject.org>
Tue, 27 Apr 2021 17:57:48 +0000 (18:57 +0100)
Now (postgresql 11):

 * psql transaction behaviour has changed so that now we want to
   use the -1 option.  This obviates a few BEGIN and COMMITs.

 * SET implicitly starts a transaction and DROP and CREATE DATABASE
   aren't transactional and now complain if they are run in a
   transaction.  So we must add COMMIT after SET.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
mg-schema-create
mg-schema-test-database

index 9bb3040a3a69f56b46d27acd0821ae0edb7f9735..3a344db4d5c41763a1ea319e0b71fdd253cc7e5e 100755 (executable)
@@ -89,7 +89,7 @@ fi
 
 $progress "Populating database..."
 
-$(get_psql_cmd) $quietopt -f schema/initial.sql
+$(get_psql_cmd) $quietopt -1 -f schema/initial.sql
 
 if $do_updates; then
     ./mg-schema-update $quietopt apply-all "${updates[@]}"
index dab536c51f3206b601ae699631a7d8c79dd99263..e69b9881e0a6178e98e67c3bb65cd2f571265862 100755 (executable)
@@ -132,7 +132,7 @@ psql_query () {
 }
 
 psql_do_cmd () {
-       echo "$(get_psql_cmd) ${OSSTEST_DEBUG:+-e -a}" 
+       echo "$(get_psql_cmd) ${OSSTEST_DEBUG:+-e -a}" -1
 }
 
 psql_do () {
@@ -411,7 +411,9 @@ END
        #---------- create test db ----------
 
        psql_do <<END
+               COMMIT;
                CREATE DATABASE $dbname;
+               BEGIN;
 END
        withtest ./mg-schema-create -q --no-updates
 
@@ -449,12 +451,10 @@ END
 
        for task in $tasks; do
                psql_do <<END
-                       BEGIN;
                        $(make_xdbref_task $dbname 'borrowed for test db' \
                                $task "$username@$nodename")
                        UPDATE resources SET owntaskid = $(borrowtaskid $task)
                                WHERE owntaskid=$task;
-                       COMMIT;
 END
        done
 
@@ -466,7 +466,6 @@ END
 
        cat >>$t.import <<END
                \o $t.import-output
-               BEGIN;
                SET CONSTRAINTS ALL DEFERRED;
 END
 
@@ -500,7 +499,6 @@ END
                        WHERE owntaskid != $(borrowtaskid $task)
                          AND owntaskid != $(taskid magic shared)
                          AND owntaskid != $(taskid magic preparing);
-               COMMIT;
 END
 
        printf "Copy..."
@@ -519,11 +517,9 @@ END
 
        for task in $tasks; do
                (withtest psql_do <<END
-                       BEGIN;
                        UPDATE resources
                                SET owntaskid = $(taskid magic idle)
                                WHERE owntaskid = $(borrowtaskid $task);
-                       COMMIT;
 END
                 )
        done
@@ -551,7 +547,9 @@ drop)
 
        psql_do <<END
                 SET client_min_messages = WARNING;
+               COMMIT;
                DROP DATABASE IF EXISTS $dbname;
+               BEGIN;
                UPDATE resources
                        SET owntaskid = CAST(tasks.refinfo AS INTEGER)
                        FROM tasks