mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-05 02:46:10 +02:00
Handle MySQL FK column names idenfier case, fix #62.
The code forgot completely that MySQL column name references in foreign key definitions have to follow the identifier case rules, this patch fix that. To be able to do that, we need to parse the GROUP_CONCAT() result that lists the FK columns, as there's apparently no arrays in MySQL. The problem here is that about any character is allowed in column names when `quoted`, so using a comma here might reveal to be fragile later.
This commit is contained in:
parent
d14f9ce334
commit
b1ba09a21b
@ -75,15 +75,23 @@
|
||||
(apply-identifier-case (pgsql-fkey-name fk) identifier-case))
|
||||
(table-name
|
||||
(apply-identifier-case (pgsql-fkey-table-name fk) identifier-case))
|
||||
(fkey-columns
|
||||
(mapcar (lambda (column-name)
|
||||
(apply-identifier-case column-name identifier-case))
|
||||
(pgsql-fkey-columns fk)))
|
||||
(foreign-table
|
||||
(apply-identifier-case (pgsql-fkey-foreign-table fk) identifier-case)))
|
||||
(apply-identifier-case (pgsql-fkey-foreign-table fk) identifier-case))
|
||||
(foreign-columns
|
||||
(mapcar (lambda (column-name)
|
||||
(apply-identifier-case column-name identifier-case))
|
||||
(pgsql-fkey-foreign-columns fk))))
|
||||
(format nil
|
||||
"ALTER TABLE ~a ADD CONSTRAINT ~a FOREIGN KEY(~a) REFERENCES ~a(~a)"
|
||||
"ALTER TABLE ~a ADD CONSTRAINT ~a FOREIGN KEY(~{~a~^,~}) REFERENCES ~a(~{~a~^,~})"
|
||||
table-name
|
||||
constraint-name
|
||||
(pgsql-fkey-columns fk)
|
||||
fkey-columns
|
||||
foreign-table
|
||||
(pgsql-fkey-foreign-columns fk))))
|
||||
foreign-columns)))
|
||||
|
||||
(defmethod format-pgsql-drop-fkey ((fk pgsql-fkey)
|
||||
&key all-pgsql-fkeys identifier-case)
|
||||
|
||||
@ -261,11 +261,12 @@ GROUP BY table_name, index_name;" dbname))
|
||||
|
||||
GROUP BY table_name, constraint_name, ft;" dbname dbname))
|
||||
do (let ((entry (assoc table-name schema :test 'equal))
|
||||
(fk (make-pgsql-fkey :name name
|
||||
:table-name table-name
|
||||
:columns cols
|
||||
:foreign-table ftable
|
||||
:foreign-columns fcols)))
|
||||
(fk
|
||||
(make-pgsql-fkey :name name
|
||||
:table-name table-name
|
||||
:columns (sq:split-sequence #\, cols)
|
||||
:foreign-table ftable
|
||||
:foreign-columns (sq:split-sequence #\, fcols))))
|
||||
(if entry
|
||||
(push fk (cdr entry))
|
||||
(push (cons table-name (list fk)) schema)))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user