From 8355b2140ed62cba4b2088fedbf92e86050b5ef1 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Wed, 23 Dec 2015 21:56:10 +0100 Subject: [PATCH] Implement before/after load support for SQLite, fix #321. If there ever was a good reason not to implement before/after support for SQLite, it's no longer valid: done. --- src/main.lisp | 4 +++- src/parsers/command-sqlite.lisp | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main.lisp b/src/main.lisp index 56a612a..d27db96 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -605,7 +605,9 @@ (lisp-code-for-loading-from-sqlite source target :gucs gucs :casts casts - :sqlite-options options)) + :sqlite-options options + :before before + :after after)) (mysql-connection (lisp-code-for-loading-from-mysql source target diff --git a/src/parsers/command-sqlite.lisp b/src/parsers/command-sqlite.lisp index 0db2b37..f36053e 100644 --- a/src/parsers/command-sqlite.lisp +++ b/src/parsers/command-sqlite.lisp @@ -90,7 +90,9 @@ load database gucs casts including-like - excluding-like)) + excluding-like + before-load + after-load)) (:lambda (clauses-list) (alexandria:alist-plist clauses-list))) @@ -108,7 +110,7 @@ load database (defun lisp-code-for-loading-from-sqlite (sqlite-db-conn pg-db-conn &key - gucs casts + gucs casts before after ((:sqlite-options options)) ((:including incl)) ((:excluding excl))) @@ -123,16 +125,23 @@ load database (make-instance 'pgloader.sqlite::copy-sqlite :target-db ,pg-db-conn :source-db source-db))) + + ,(sql-code-block pg-db-conn :pre before "before load") + (pgloader.sqlite:copy-database source :including ',incl :excluding ',excl - ,@(remove-batch-control-option options))))) + ,@(remove-batch-control-option options)) + + ,(sql-code-block pg-db-conn :post after "after load")))) (defrule load-sqlite-database load-sqlite-command (:lambda (source) (destructuring-bind (sqlite-uri pg-db-uri - &key gucs casts sqlite-options including excluding) + &key + gucs casts before after + sqlite-options including excluding) source (cond (*dry-run* (lisp-code-for-sqlite-dry-run sqlite-uri pg-db-uri)) @@ -140,6 +149,8 @@ load database (lisp-code-for-loading-from-sqlite sqlite-uri pg-db-uri :gucs gucs :casts casts + :before before + :after after :sqlite-options sqlite-options :including including :excluding excluding))))))