From 50e8fca96ba7f67983e0ea7795850e07a67939b8 Mon Sep 17 00:00:00 2001 From: Gleb Golubitsky Date: Wed, 18 Dec 2013 02:00:40 +0200 Subject: [PATCH] Fixing "quote identifiers" option for MySQL conversions Signed-off-by: Gleb Golubitsky --- src/sources/mysql-schema.lisp | 9 ++++++--- src/sources/mysql.lisp | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sources/mysql-schema.lisp b/src/sources/mysql-schema.lisp index 0eb8c02..626d05d 100644 --- a/src/sources/mysql-schema.lisp +++ b/src/sources/mysql-schema.lisp @@ -194,16 +194,19 @@ GROUP BY table_name, index_name;" dbname)) for (name . indexes) in schema collect (cons name (reverse indexes)))))))) -(defun set-table-oids (all-indexes) +(defun set-table-oids (all-indexes &key identifier-case) "MySQL allows using the same index name against separate tables, which PostgreSQL forbids. To get unicity in index names without running out of characters (we are allowed only 63), we use the table OID instead. This function grabs the table OIDs in the PostgreSQL database and update the definitions with them." - (let* ((table-names (mapcar #'car all-indexes)) + (let* ((table-names (mapcar #'(lambda (table-name) + (apply-identifier-case table-name identifier-case)) + (mapcar #'car all-indexes))) (table-oids (pgloader.pgsql:list-table-oids table-names))) - (loop for (table-name . indexes) in all-indexes + (loop for (table-name-raw . indexes) in all-indexes + for table-name = (apply-identifier-case table-name-raw identifier-case) for table-oid = (cdr (assoc table-name table-oids :test #'string=)) unless table-oid do (error "OID not found for ~s." table-name) do (loop for index in indexes diff --git a/src/sources/mysql.lisp b/src/sources/mysql.lisp index 64a3373..6184937 100644 --- a/src/sources/mysql.lisp +++ b/src/sources/mysql.lisp @@ -212,7 +212,8 @@ ;; MySQL allows the same index name being used against several ;; tables, so we add the PostgreSQL table OID in the index name, ;; to differenciate. Set the table oids now. - (set-table-oids all-indexes) + (set-table-oids all-indexes + :identifier-case identifier-case) ;; If asked to materialize views, now is the time to create ;; the target tables for them