Merge pull request #18 from Sectoid/fix-mysql-quoting

Fixing "quote identifiers" option for MySQL conversions
This commit is contained in:
Dimitri Fontaine 2013-12-18 06:01:08 -08:00
commit bcb058d9ba
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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