Assorted bug fixes in the context of Redshift support as a source.

The catalog queries used in pgloader have to be adjusted for Redshift
because this thing forked PostgreSQL 8.0, which is a long time ago now.
Also, we had a couple bugs here and there that were not really related to
Redshift support but were shown in that context.

Fixes #813.
This commit is contained in:
Dimitri Fontaine 2018-09-04 11:49:21 +02:00
parent 0f58a3c84d
commit 5119d864f4
5 changed files with 36 additions and 12 deletions

View File

@ -45,7 +45,8 @@
(cons schema filter-list))))
(defrule including-matching-in-schema
(and including-in-schema (* including-in-schema))
(and including-matching-in-schema-filter
(* including-matching-in-schema-filter))
(:lambda (source)
(destructuring-bind (inc1 incs) source
(cons :including (list* inc1 incs)))))
@ -58,7 +59,8 @@
(cons schema filter-list))))
(defrule excluding-matching-in-schema
(and excluding-in-schema (* excluding-in-schema))
(and excluding-matching-in-schema-filter
(* excluding-matching-in-schema-filter))
(:lambda (source)
(destructuring-bind (excl1 excls) source
(cons :excluding (list* excl1 excls)))))

View File

@ -11,9 +11,9 @@ with seqattr as
case when adsrc ~~ 'nextval'
then substring(pg_get_expr(d.adbin, d.adrelid)
from '''([^'']+)'''
)::regclass::oid
else null::oid
end as seqoid
)
else null
end as seqname
from pg_attrdef d
)
select nspname, relname, c.oid, attname,
@ -24,7 +24,7 @@ with seqattr as
end as typmod,
attnotnull,
case when atthasdef then def.adsrc end as default,
case when s.seqoid is not null then 'auto_increment' end as extra
case when s.seqname is not null then 'auto_increment' end as extra
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
left join pg_attribute a on c.oid = a.attrelid

View File

@ -17,10 +17,11 @@
join pg_class r ON r.oid = x.indrelid
join pg_namespace n ON n.oid = i.relnamespace
join pg_namespace rn ON rn.oid = r.relnamespace
left join pg_constraint c ON c.conindid = i.oid
and c.conrelid = r.oid
-- filter out self-fkeys
and c.confrelid <> r.oid
left join pg_depend d on d.classid = 'pg_class'::regclass
and d.objid = i.oid
and d.refclassid = 'pg_constraint'::regclass
and d.deptype = 'i'
left join pg_constraint c ON c.oid = d.refobjid
where n.nspname !~~ '^pg_' and n.nspname <> 'information_schema'
~:[~*~;and (~{~a~^~&~10t or ~})~]
~:[~*~;and (~{~a~^~&~10t and ~})~]

View File

@ -9,7 +9,10 @@
:target (:type "serial" :drop-default t))
(:source (:type "bigint" :auto-increment t)
:target (:type "bigserial" :drop-default t)))
:target (:type "bigserial" :drop-default t))
(:source (:type "character varying")
:target (:type "text" :drop-typemod t)))
"Data Type Casting to migrate from PostgtreSQL to PostgreSQL")
(defmethod pgsql-column-ctype ((column column))
@ -45,4 +48,22 @@
(setf (column-transform-default pgcol)
(column-transform-default field))
;; Redshift may be using DEFAULT getdate() instead of now()
(let ((default (column-default pgcol)))
(setf (column-default pgcol)
(cond
((and (stringp default) (string= "NULL" default))
:null)
((and (stringp default)
(or (string= "getdate()" default)))
:current-timestamp)
(t (column-default pgcol))))
;; we usually trust defaults that come from PostgreSQL... but we
;; also have support for Redshift.
(when (member (column-default pgcol) '(:null :current-timestamp))
(setf (column-transform-default pgcol) t)))
pgcol)))

View File

@ -53,7 +53,7 @@
(string= "set" data-type))
(let ((start-1 (position #\( column-type)) ; just before start position
(end (position #\) column-type))) ; just before end position
(when start-1
(when (and start-1 (< (+ 1 start-1) end))
(destructuring-bind (a &optional b)
(mapcar #'parse-integer
(sq:split-sequence #\, column-type