mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-04 10:31:02 +02:00
Cleanup and fix yesterday's refactoring of pgconn parameters.
This commit is contained in:
parent
85cff5f993
commit
47c22776f2
@ -17,6 +17,7 @@
|
||||
#:*copy-batch-size*
|
||||
#:*concurrent-batches*
|
||||
#:*pgconn*
|
||||
#:pgconn-dbname
|
||||
#:*pg-settings*
|
||||
#:*myconn-host*
|
||||
#:*myconn-port*
|
||||
@ -127,6 +128,12 @@
|
||||
:table-name nil
|
||||
:use-ssl nil)
|
||||
"Default PostgreSQL connection string.")
|
||||
|
||||
(defun pgconn-dbname ()
|
||||
"Return the current dbname from *pgconn* setting."
|
||||
(destructuring-bind (&key dbname &allow-other-keys) *pgconn*
|
||||
dbname))
|
||||
|
||||
(defparameter *pg-settings* nil "An alist of GUC names and values.")
|
||||
|
||||
;;;
|
||||
|
||||
@ -97,7 +97,7 @@
|
||||
;; alter table if exists ... drop constraint if exists ...
|
||||
(format nil "ALTER TABLE ~a DROP CONSTRAINT ~a" table-name constraint-name))))
|
||||
|
||||
(defun drop-pgsql-fkeys (all-fkeys &key (dbname *pg-dbname*))
|
||||
(defun drop-pgsql-fkeys (all-fkeys &key (dbname (pgconn-dbname)))
|
||||
"Drop all Foreign Key Definitions given, to prepare for a clean run."
|
||||
(let ((all-pgsql-fkeys (list-tables-and-fkeys dbname)))
|
||||
(loop for (table-name . fkeys) in all-fkeys
|
||||
@ -112,7 +112,7 @@
|
||||
|
||||
(defun create-pgsql-fkeys (all-fkeys
|
||||
&key
|
||||
(dbname *pg-dbname*)
|
||||
(dbname (pgconn-dbname))
|
||||
state
|
||||
(label "Foreign Keys"))
|
||||
"Actually create the Foreign Key References that where declared in the
|
||||
@ -302,7 +302,7 @@
|
||||
;;; Sequences
|
||||
;;;
|
||||
(defun reset-sequences (table-names
|
||||
&key (dbname *pg-dbname*) state)
|
||||
&key (dbname (pgconn-dbname)) state)
|
||||
"Reset all sequences created during this MySQL migration."
|
||||
(log-message :notice "Reset sequences")
|
||||
(with-stats-collection ("Reset Sequences"
|
||||
|
||||
@ -225,12 +225,12 @@
|
||||
;;
|
||||
;; Turn UNIQUE indexes into PRIMARY KEYS now
|
||||
;;
|
||||
(pgstate-add-table state *pg-dbname* "Primary Keys")
|
||||
(pgstate-add-table state (pgconn-dbname) "Primary Keys")
|
||||
(loop :for sql :in pkeys
|
||||
:when sql
|
||||
:do (progn
|
||||
(log-message :notice "~a" sql)
|
||||
(pgsql-execute-with-timing *pg-dbname* "Primary Keys" sql state)))
|
||||
(pgsql-execute-with-timing (pgconn-dbname) "Primary Keys" sql state)))
|
||||
|
||||
;;
|
||||
;; Foreign Key Constraints
|
||||
@ -369,7 +369,7 @@
|
||||
:include-drop include-drop))
|
||||
(t
|
||||
(when truncate
|
||||
(truncate-tables *pg-dbname* (mapcar #'car all-columns)))))
|
||||
(truncate-tables (pgconn-dbname) (mapcar #'car all-columns)))))
|
||||
;;
|
||||
;; In case some error happens in the preparatory transaction, we
|
||||
;; need to stop now and refrain from trying to load the data into
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
|
||||
(defmacro with-stats-collection ((table-name
|
||||
&key
|
||||
dbname
|
||||
(dbname (pgconn-dbname))
|
||||
summary
|
||||
use-result-as-read
|
||||
use-result-as-rows
|
||||
@ -73,26 +73,23 @@
|
||||
&body forms)
|
||||
"Measure time spent in running BODY into STATE, accounting the seconds to
|
||||
given DBNAME and TABLE-NAME"
|
||||
(destructuring-bind (&key ((:dbname pgconn-dbname)) &allow-other-keys)
|
||||
*pgconn*
|
||||
(let ((result (gensym "result"))
|
||||
(secs (gensym "secs"))
|
||||
(dbname (or dbname pgconn-dbname)))
|
||||
`(prog2
|
||||
(pgstate-add-table ,pgstate ,dbname ,table-name)
|
||||
(multiple-value-bind (,result ,secs)
|
||||
(timing ,@forms)
|
||||
(cond ((and ,use-result-as-read ,use-result-as-rows)
|
||||
(pgstate-incf ,pgstate ,table-name
|
||||
:read ,result :rows ,result :secs ,secs))
|
||||
(,use-result-as-read
|
||||
(pgstate-incf ,pgstate ,table-name :read ,result :secs ,secs))
|
||||
(,use-result-as-rows
|
||||
(pgstate-incf ,pgstate ,table-name :rows ,result :secs ,secs))
|
||||
(t
|
||||
(pgstate-incf ,pgstate ,table-name :secs ,secs)))
|
||||
,result)
|
||||
(when ,summary (report-summary))))))
|
||||
(let ((result (gensym "result"))
|
||||
(secs (gensym "secs")))
|
||||
`(prog2
|
||||
(pgstate-add-table ,pgstate ,dbname ,table-name)
|
||||
(multiple-value-bind (,result ,secs)
|
||||
(timing ,@forms)
|
||||
(cond ((and ,use-result-as-read ,use-result-as-rows)
|
||||
(pgstate-incf ,pgstate ,table-name
|
||||
:read ,result :rows ,result :secs ,secs))
|
||||
(,use-result-as-read
|
||||
(pgstate-incf ,pgstate ,table-name :read ,result :secs ,secs))
|
||||
(,use-result-as-rows
|
||||
(pgstate-incf ,pgstate ,table-name :rows ,result :secs ,secs))
|
||||
(t
|
||||
(pgstate-incf ,pgstate ,table-name :secs ,secs)))
|
||||
,result)
|
||||
(when ,summary (report-summary)))))
|
||||
|
||||
(defun report-full-summary (legend state
|
||||
&key before finally parallel)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user