From 2fef253d28b2bd9d16b0051de04f5b0f0e074c32 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 11 Feb 2020 22:20:08 +0100 Subject: [PATCH] Implement AFTER CREATE SCHEMA DO for more sources. It was only implemented for Postgres sources even though the implementation is generic enough to be shared. It's only a matter of instructing our parser about the new facility, which this patch does. Fixes #1062. --- src/parsers/command-dbf.lisp | 9 +++++++-- src/parsers/command-ixf.lisp | 10 +++++++--- src/parsers/command-mssql.lisp | 7 +++++-- src/parsers/command-mysql.lisp | 13 +++++++++---- src/parsers/command-sqlite.lisp | 7 +++++-- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/parsers/command-dbf.lisp b/src/parsers/command-dbf.lisp index 5f8269d..810fcc7 100644 --- a/src/parsers/command-dbf.lisp +++ b/src/parsers/command-dbf.lisp @@ -59,6 +59,7 @@ gucs casts before-load + after-schema after-load)) (:lambda (clauses-list) (alexandria:alist-plist clauses-list))) @@ -93,7 +94,8 @@ &key target-table-name encoding - gucs casts before after options + gucs casts options + before after-schema after &allow-other-keys) `(lambda () (let* ((*default-cast-rules* ',*db3-default-cast-rules*) @@ -116,6 +118,7 @@ (copy-database source ,@(remove-batch-control-option options) + :after-schema ',after-schema :on-error-stop on-error-stop :create-indexes nil :foreign-keys nil @@ -126,7 +129,8 @@ (defrule load-dbf-file load-dbf-command (:lambda (command) (bind (((source encoding pg-db-uri table-name - &key options gucs casts before after) command)) + &key options gucs casts before after-schema after) + command)) (cond (*dry-run* (lisp-code-for-dbf-dry-run source pg-db-uri)) (t @@ -136,5 +140,6 @@ :gucs gucs :casts casts :before before + :after-schema after-schema :after after :options options)))))) diff --git a/src/parsers/command-ixf.lisp b/src/parsers/command-ixf.lisp index 62ba4a5..562d178 100644 --- a/src/parsers/command-ixf.lisp +++ b/src/parsers/command-ixf.lisp @@ -59,6 +59,7 @@ (defrule load-ixf-optional-clauses (* (or ixf-options gucs before-load + after-schema after-load)) (:lambda (clauses-list) (alexandria:alist-plist clauses-list))) @@ -76,8 +77,8 @@ (defun lisp-code-for-loading-from-ixf (ixf-db-conn pg-db-conn &key - target-table-name - gucs before after options + target-table-name gucs options + before after-schema after &allow-other-keys) `(lambda () (let* (,@(pgsql-connection-bindings pg-db-conn gucs) @@ -101,6 +102,7 @@ options :extras '(:timezone)) :on-error-stop on-error-stop + :after-schema ',after-schema :foreign-keys nil :reset-sequences nil) @@ -109,7 +111,8 @@ (defrule load-ixf-file load-ixf-command (:lambda (command) (bind (((source pg-db-uri table-name - &key options gucs before after) command)) + &key options gucs before after-schema after) + command)) (cond (*dry-run* (lisp-code-for-csv-dry-run pg-db-uri)) (t @@ -117,5 +120,6 @@ :target-table-name table-name :gucs gucs :before before + :after-schema after-schema :after after :options options)))))) diff --git a/src/parsers/command-mssql.lisp b/src/parsers/command-mssql.lisp index daed5c5..b440a2b 100644 --- a/src/parsers/command-mssql.lisp +++ b/src/parsers/command-mssql.lisp @@ -87,6 +87,7 @@ materialize-views distribute-commands before-load + after-schema after-load including-like-in-schema excluding-like-in-schema)) @@ -142,7 +143,7 @@ (defun lisp-code-for-loading-from-mssql (ms-db-conn pg-db-conn &key gucs mssql-gucs - casts before after + casts before after after-schema options distribute views alter-schema alter-table including excluding @@ -171,6 +172,7 @@ :excluding ',excluding :alter-schema ',alter-schema :alter-table ',alter-table + :after-schema ',after-schema :materialize-views ',views :distribute ',distribute :set-table-oids t @@ -183,7 +185,7 @@ (:lambda (source) (bind (((ms-db-uri pg-db-uri &key - gucs mssql-gucs casts views before after + gucs mssql-gucs casts views before after-schema after alter-schema alter-table distribute including excluding options) source)) @@ -196,6 +198,7 @@ :casts casts :views views :before before + :after-schema after-schema :after after :alter-schema alter-schema :alter-table alter-table diff --git a/src/parsers/command-mysql.lisp b/src/parsers/command-mysql.lisp index 0e87f66..baba854 100644 --- a/src/parsers/command-mysql.lisp +++ b/src/parsers/command-mysql.lisp @@ -89,6 +89,7 @@ excluding-matching decoding-tables-as before-load + after-schema after-load distribute-commands)) (:lambda (clauses-list) @@ -164,8 +165,10 @@ (defun lisp-code-for-loading-from-mysql (my-db-conn pg-db-conn &key gucs mysql-gucs - casts views before after options - alter-table alter-schema distribute + casts options views + before after after-schema + alter-table alter-schema + distribute ((:including incl)) ((:excluding excl)) ((:decoding decoding-as)) @@ -192,6 +195,7 @@ :materialize-views ',views :alter-table ',alter-table :alter-schema ',alter-schema + :after-schema ',after-schema :distribute ',distribute :set-table-oids t :on-error-stop on-error-stop @@ -204,8 +208,8 @@ (destructuring-bind (my-db-uri pg-db-uri &key - gucs mysql-gucs casts views before after options - alter-table alter-schema distribute + gucs mysql-gucs casts views before after after-schema + options alter-table alter-schema distribute including excluding decoding) source (cond (*dry-run* @@ -218,6 +222,7 @@ :views views :before before :after after + :after-schema after-schema :options options :alter-table alter-table :alter-schema alter-schema diff --git a/src/parsers/command-sqlite.lisp b/src/parsers/command-sqlite.lisp index a6ff248..23dbfd5 100644 --- a/src/parsers/command-sqlite.lisp +++ b/src/parsers/command-sqlite.lisp @@ -92,7 +92,8 @@ load database (defun lisp-code-for-loading-from-sqlite (sqlite-db-conn pg-db-conn &key - gucs casts before after options + gucs casts options + before after-schema after alter-table alter-schema ((:including incl)) ((:excluding excl)) @@ -116,6 +117,7 @@ load database (copy-database source :alter-table ',alter-table :alter-schema ',alter-schema + :after-schema ',after-schema :set-table-oids t :including ',incl :excluding ',excl @@ -129,7 +131,7 @@ load database (destructuring-bind (sqlite-uri pg-db-uri &key - gucs casts before after options + gucs casts before after after-schema options alter-table alter-schema including excluding) source @@ -140,6 +142,7 @@ load database :gucs gucs :casts casts :before before + :after-schema after-schema :after after :options options :alter-table alter-table