From cb633aa092e83aa95b1e0483d6d6ce731bf6bdfe Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 20 Aug 2018 11:52:59 +0200 Subject: [PATCH] Refrain from some introspections on non-PGDG PostgreSQL variants. When dealing with PostgreSQL protocol compatible databases, often enough they don't support the same catalogs as PostgreSQL itself. Redshift for instance lacks foreign key support. --- src/load/load-file.lisp | 4 +++- src/pgsql/pgsql-schema.lisp | 30 ++++++++++++++++++------------ src/sources/pgsql/pgsql.lisp | 34 ++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/load/load-file.lisp b/src/load/load-file.lisp index 19819e5..7d36d12 100644 --- a/src/load/load-file.lisp +++ b/src/load/load-file.lisp @@ -42,7 +42,9 @@ (handler-case (with-pgsql-connection (pgconn) (setf pgsql-catalog - (fetch-pgsql-catalog (db-name pgconn) :table (target copy))) + (fetch-pgsql-catalog (db-name pgconn) + :table (target copy) + :variant (pgconn-variant pgconn))) ;; if the user didn't tell us the column list of the table, now is ;; a proper time to set it in the copy object diff --git a/src/pgsql/pgsql-schema.lisp b/src/pgsql/pgsql-schema.lisp index b47c4e5..9ea3d59 100644 --- a/src/pgsql/pgsql-schema.lisp +++ b/src/pgsql/pgsql-schema.lisp @@ -5,7 +5,12 @@ (in-package :pgloader.pgsql) (defun fetch-pgsql-catalog (dbname - &key table source-catalog including excluding) + &key + table + source-catalog + including + excluding + (variant :pgdg)) "Fetch PostgreSQL catalogs for the target database. A PostgreSQL connection must be opened." (let* ((*identifier-case* :quote) @@ -18,10 +23,10 @@ (t including)))) - - (list-all-sqltypes catalog - :including including - :excluding excluding) + (when (eq :pgdg variant) + (list-all-sqltypes catalog + :including including + :excluding excluding)) (list-all-columns catalog :table-type :table @@ -32,14 +37,15 @@ :including including :excluding excluding) - (list-all-fkeys catalog - :including including - :excluding excluding) + (when (eq :pgdg variant) + (list-all-fkeys catalog + :including including + :excluding excluding) - ;; fetch fkey we depend on with UNIQUE indexes but that have been - ;; excluded from the target list, we still need to take care of them to - ;; be able to DROP then CREATE those indexes again - (list-missing-fk-deps catalog) + ;; fetch fkey we depend on with UNIQUE indexes but that have been + ;; excluded from the target list, we still need to take care of them to + ;; be able to DROP then CREATE those indexes again + (list-missing-fk-deps catalog)) (log-message :debug "fetch-pgsql-catalog: ~d tables, ~d indexes, ~d+~d fkeys" (count-tables catalog) diff --git a/src/sources/pgsql/pgsql.lisp b/src/sources/pgsql/pgsql.lisp index e8cab7b..8a45a58 100644 --- a/src/sources/pgsql/pgsql.lisp +++ b/src/sources/pgsql/pgsql.lisp @@ -64,27 +64,29 @@ :use-result-as-read t :section :pre) (with-pgsql-transaction (:pgconn (source-db pgsql)) - (list-all-sqltypes catalog + (let ((variant (pgconn-variant (source-db pgsql)))) + (when (eq :pgdg variant) + (list-all-sqltypes catalog + :including including + :excluding excluding)) + + (list-all-columns catalog :including including :excluding excluding) - (list-all-columns catalog - :including including - :excluding excluding) + (when create-indexes + (list-all-indexes catalog + :including including + :excluding excluding)) - (when create-indexes - (list-all-indexes catalog - :including including - :excluding excluding)) + (when (and (eq :pgdg variant) foreign-keys) + (list-all-fkeys catalog + :including including + :excluding excluding)) - (when foreign-keys - (list-all-fkeys catalog - :including including - :excluding excluding)) - - ;; return how many objects we're going to deal with in total - ;; for stats collection - (+ (count-tables catalog) (count-indexes catalog)))) + ;; return how many objects we're going to deal with in total + ;; for stats collection + (+ (count-tables catalog) (count-indexes catalog))))) ;; be sure to return the catalog itself catalog)