diff --git a/src/parsers/command-pgsql.lisp b/src/parsers/command-pgsql.lisp index 2a09fd7..3650534 100644 --- a/src/parsers/command-pgsql.lisp +++ b/src/parsers/command-pgsql.lisp @@ -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))))) diff --git a/src/pgsql/sql/list-all-columns.sql b/src/pgsql/sql/list-all-columns.sql index 11be443..75f8a52 100644 --- a/src/pgsql/sql/list-all-columns.sql +++ b/src/pgsql/sql/list-all-columns.sql @@ -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 diff --git a/src/pgsql/sql/list-all-indexes.sql b/src/pgsql/sql/list-all-indexes.sql index 320a6e0..bfffbf7 100644 --- a/src/pgsql/sql/list-all-indexes.sql +++ b/src/pgsql/sql/list-all-indexes.sql @@ -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 ~})~] diff --git a/src/sources/pgsql/pgsql-cast-rules.lisp b/src/sources/pgsql/pgsql-cast-rules.lisp index 2ef0373..6ac37ee 100644 --- a/src/sources/pgsql/pgsql-cast-rules.lisp +++ b/src/sources/pgsql/pgsql-cast-rules.lisp @@ -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))) diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index dbc39b9..4d77c71 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -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