diff --git a/Makefile b/Makefile index 9331ce0..9eb7d7d 100644 --- a/Makefile +++ b/Makefile @@ -127,7 +127,7 @@ pgloader-standalone: --compress-core \ --output $(PGLOADER) -test: +test: $(PGLOADER) $(MAKE) PGLOADER=$(realpath $(PGLOADER)) -C test regress deb: docs diff --git a/src/parser.lisp b/src/parser.lisp index 6ff36d7..585123e 100644 --- a/src/parser.lisp +++ b/src/parser.lisp @@ -1345,7 +1345,10 @@ load database (declare (ignore load dbf from)) source))) -(defrule load-dbf-optional-clauses (* (or dbf-options gucs)) +(defrule load-dbf-optional-clauses (* (or dbf-options + gucs + before-load + after-load)) (:lambda (clauses-list) (alexandria:alist-plist clauses-list))) @@ -1356,13 +1359,16 @@ load database (defrule load-dbf-file load-dbf-command (:lambda (command) - (destructuring-bind (source pg-db-uri &key ((:dbf-options options)) gucs) + (destructuring-bind (source pg-db-uri + &key ((:dbf-options options)) gucs before after) command (destructuring-bind (&key dbname table-name &allow-other-keys) pg-db-uri `(lambda () (let* ((state-before (pgloader.utils:make-pgstate)) - (*state* (pgloader.utils:make-pgstate)) + (summary (null *state*)) + (*state* (or *state* (pgloader.utils:make-pgstate))) + (state-after ,(when after `(pgloader.utils:make-pgstate))) ,@(pgsql-connection-bindings pg-db-uri gucs) ,@(batch-control-bindings options) (source @@ -1388,12 +1394,19 @@ load database :source source :target ,table-name))) + ,(sql-code-block dbname 'state-before before "before load") + (pgloader.sources:copy-from source :state-before state-before ,@(remove-batch-control-option options)) - (report-full-summary "Total import time" *state* - :before state-before))))))) + ,(sql-code-block dbname 'state-after after "after load") + + ;; reporting + (when summary + (report-full-summary "Total import time" *state* + :before state-before + :finally state-after)))))))) #| @@ -1417,7 +1430,10 @@ load database (declare (ignore load ixf from)) source))) -(defrule load-ixf-optional-clauses (* (or ixf-options gucs)) +(defrule load-ixf-optional-clauses (* (or ixf-options + gucs + before-load + after-load)) (:lambda (clauses-list) (alexandria:alist-plist clauses-list))) @@ -1428,13 +1444,16 @@ load database (defrule load-ixf-file load-ixf-command (:lambda (command) - (destructuring-bind (source pg-db-uri &key ((:ixf-options options)) gucs) + (destructuring-bind (source pg-db-uri + &key ((:ixf-options options)) gucs before after) command (destructuring-bind (&key dbname table-name &allow-other-keys) pg-db-uri `(lambda () (let* ((state-before (pgloader.utils:make-pgstate)) - (*state* (pgloader.utils:make-pgstate)) + (summary (null *state*)) + (*state* (or *state* (pgloader.utils:make-pgstate))) + (state-after ,(when after `(pgloader.utils:make-pgstate))) ,@(pgsql-connection-bindings pg-db-uri gucs) ,@(batch-control-bindings options) (source @@ -1460,12 +1479,18 @@ load database :source source :target ,table-name))) + ,(sql-code-block dbname 'state-before before "before load") + (pgloader.sources:copy-from source :state-before state-before ,@(remove-batch-control-option options)) - (report-full-summary "Total import time" *state* - :before state-before))))))) + ,(sql-code-block dbname 'state-after after "after load") + + (when summary + (report-full-summary "Total import time" *state* + :before state-before + :finally state-after)))))))) #| diff --git a/test/Makefile b/test/Makefile index e5442cc..3fa3c6c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,6 +16,7 @@ REGRESS= allcols.load \ dbf.load \ errors.load \ fixed.load \ + ixf.load \ overflow.load \ partial.load \ serial.load \ diff --git a/test/ixf.load b/test/ixf.load index ab47dbc..ea322e5 100644 --- a/test/ixf.load +++ b/test/ixf.load @@ -1,4 +1,8 @@ LOAD IXF FROM data/nsitra.test1.ixf INTO postgresql:///pgloader?nsitra.test1 - WITH truncate, create table; + WITH truncate, create table + + BEFORE LOAD DO + $$ create schema if not exists nsitra; $$, + $$ drop table if exists nsitra.test1; $$; diff --git a/test/regress/expected/ixf.out b/test/regress/expected/ixf.out new file mode 100644 index 0000000..1f8724a --- /dev/null +++ b/test/regress/expected/ixf.out @@ -0,0 +1,4 @@ +1 77 77 foobar foobar baz baz +2 \N 88 \N abcdef \N ghijkl +3 179 179 FOOBAR FOOBAR BAZ BAZ +4 \N 179 \N FOOBAR \N BAZ