mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-07 23:07:00 +02:00
Add BEFORE/AFTER LOAD clauses to IXF and DBF commands.
This commit is contained in:
parent
f352b39284
commit
07b5aa3ed6
2
Makefile
2
Makefile
@ -127,7 +127,7 @@ pgloader-standalone:
|
||||
--compress-core \
|
||||
--output $(PGLOADER)
|
||||
|
||||
test:
|
||||
test: $(PGLOADER)
|
||||
$(MAKE) PGLOADER=$(realpath $(PGLOADER)) -C test regress
|
||||
|
||||
deb: docs
|
||||
|
@ -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))
|
||||
|
||||
,(sql-code-block dbname 'state-after after "after load")
|
||||
|
||||
;; reporting
|
||||
(when summary
|
||||
(report-full-summary "Total import time" *state*
|
||||
:before state-before)))))))
|
||||
: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))
|
||||
|
||||
,(sql-code-block dbname 'state-after after "after load")
|
||||
|
||||
(when summary
|
||||
(report-full-summary "Total import time" *state*
|
||||
:before state-before)))))))
|
||||
:before state-before
|
||||
:finally state-after))))))))
|
||||
|
||||
|
||||
#|
|
||||
|
@ -16,6 +16,7 @@ REGRESS= allcols.load \
|
||||
dbf.load \
|
||||
errors.load \
|
||||
fixed.load \
|
||||
ixf.load \
|
||||
overflow.load \
|
||||
partial.load \
|
||||
serial.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; $$;
|
||||
|
4
test/regress/expected/ixf.out
Normal file
4
test/regress/expected/ixf.out
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user