From 765bbb70aa48287769c675da77f1f1cfc196ed36 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 5 Feb 2016 21:26:31 +0100 Subject: [PATCH] Fix auto_increment support in cast rules. This fixes #141 again when users are forcing MySQL bigint(20) into PostgreSQL bigint types so that foreign keys can be installed. To this effect, as cast rule such as the following is needing: cast type bigint when (= 20 precision) to bigint drop typemod Before this patch, this user provided cast rule would also match against MySQL types "with extra auto_increment", and it should not. If you're having the problem that this patch fixes on an older pgloader that you can't or won't upgrade, consider the following user provided set of cast rules to achieve the same effect: cast type bigint with extra auto_increment to bigserial drop typemod, type bigint when (= 20 precision) to bigint drop typemod --- src/sources/common/casting-rules.lisp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sources/common/casting-rules.lisp b/src/sources/common/casting-rules.lisp index bbd239c..39f9b2c 100644 --- a/src/sources/common/casting-rules.lisp +++ b/src/sources/common/casting-rules.lisp @@ -47,7 +47,7 @@ ((:typemod typemod-expr) nil tm-s-p) ((:default rule-source-default) nil d-s-p) ((:not-null rule-source-not-null) nil n-s-p) - ((:auto-increment rule-source-auto-increment) nil ai-s-p) + ((:auto-increment rule-source-auto-increment)) &allow-other-keys) rule-source (destructuring-bind (&key table-name @@ -69,7 +69,11 @@ (or (null tm-s-p) (typemod-expr-matches-p typemod-expr typemod)) (or (null d-s-p) (string= default rule-source-default)) (or (null n-s-p) (eq not-null rule-source-not-null)) - (or (null ai-s-p) (eq auto-increment rule-source-auto-increment))) + + ;; current RULE only matches SOURCE when both have an + ;; auto_increment property, or none have it. + (or (and auto-increment rule-source-auto-increment) + (and (not auto-increment) (not rule-source-auto-increment)))) (list :using using :target rule-target)))))) (defun make-pgsql-type (source target using)