Improve error management in MySQL copy-database preparatory code.

This commit is contained in:
Dimitri Fontaine 2013-11-13 22:46:17 +01:00
parent c16a56690a
commit 6fb3de7043

View File

@ -208,23 +208,34 @@
(with-stats-collection (pg-dbname "create, drop" (with-stats-collection (pg-dbname "create, drop"
:use-result-as-rows t :use-result-as-rows t
:state state-before) :state state-before)
(with-pgsql-transaction (pg-dbname) (handler-case
;; we need to first drop the Foreign Key Constraints, so that we (with-pgsql-transaction (pg-dbname)
;; can DROP TABLE when asked ;; we need to first drop the Foreign Key Constraints, so that we
(when (and foreign-keys include-drop) ;; can DROP TABLE when asked
(drop-fkeys all-fkeys (when (and foreign-keys include-drop)
:dbname pg-dbname (drop-fkeys all-fkeys
:identifier-case identifier-case)) :dbname pg-dbname
:identifier-case identifier-case))
;; now drop then create tables and types, etc ;; now drop then create tables and types, etc
(create-tables all-columns (create-tables all-columns
:identifier-case identifier-case :identifier-case identifier-case
:include-drop include-drop) :include-drop include-drop)
;; MySQL allows the same index name being used against several ;; MySQL allows the same index name being used against several
;; tables, so we add the PostgreSQL table OID in the index name, ;; tables, so we add the PostgreSQL table OID in the index name,
;; to differenciate. Set the table oids now. ;; to differenciate. Set the table oids now.
(set-table-oids all-indexes)))) (set-table-oids all-indexes))
;;
;; In case some error happens in the preparatory transaction, we
;; need to stop now and refrain to try loading the data into an
;; incomplete schema.
;;
(cl-postgres:database-error (e)
(declare (ignore e)) ; a log has already been printed
(log-message :critical "Failed to create the schema, see above.")
(return-from copy-database)))))
(loop (loop
for (table-name . columns) in all-columns for (table-name . columns) in all-columns