From 981b801ce7cd5f1a7c83ef885856a69cc43da92d Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Thu, 10 Aug 2017 18:01:17 +0200 Subject: [PATCH] Fix user defined rules to cast ENUM to Text. The MySQL enum are casted to PostgreSQL enum types just fine, but sometimes that's not what the user wants. In case when we have a CAST rule for an ENUM column, recognize the fact and respect user choice. Fixes #608. --- src/sources/mysql/mysql-cast-rules.lisp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/sources/mysql/mysql-cast-rules.lisp b/src/sources/mysql/mysql-cast-rules.lisp index c9766c6..beb017e 100644 --- a/src/sources/mysql/mysql-cast-rules.lisp +++ b/src/sources/mysql/mysql-cast-rules.lisp @@ -190,12 +190,22 @@ dtype ctype nil))) - (setf (column-type-name pgcol) - (make-sqltype :name sqltype-name - :type (intern (string-upcase dtype) - (find-package "KEYWORD")) - :source-def ctype - :extra (explode-mysql-enum ctype))))) + ;; + ;; We might have user-defined cast rules e.g. converting an ENUM + ;; to text, in which case we have nothing to do here. We set a + ;; PostgreSQL enum only when the casting rules already generated + ;; the target type name. + ;; + ;; FIXME: why call enum-or-set-name twice, once from + ;; *mysql-default-cast-rules* and once here explicitely? + ;; + (when (string= sqltype-name (column-type-name pgcol)) + (setf (column-type-name pgcol) + (make-sqltype :name sqltype-name + :type (intern (string-upcase dtype) + (find-package "KEYWORD")) + :source-def ctype + :extra (explode-mysql-enum ctype)))))) ;; extra triggers ;;