mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-10 00:07:00 +02:00
Refrain from loading incomplete foreign key references in SQLite.
Given INCLUDING and EXCLUDING support it might be possible that we migrate a table from SQLite without having selecting tables pointed to by foreign keys. In that case, pgloader should still be able to load the data definition and content fine, just skipping the incomplete fkey definitions. That's implemented in this patch, which has been tested thanks to a reproducible data set being made available! Fixes #681.
This commit is contained in:
parent
62d776f5e8
commit
87f35e8852
@ -198,18 +198,33 @@
|
||||
|
||||
:do (let* ((ftable (find-table (table-schema table) ftable-name))
|
||||
(fkey (or (gethash id fkey-table)
|
||||
(let ((pg-fkey
|
||||
(make-fkey :table table
|
||||
:columns nil
|
||||
:foreign-table ftable
|
||||
:foreign-columns nil
|
||||
:update-rule on-update
|
||||
:delete-rule on-delete)))
|
||||
(setf (gethash id fkey-table) pg-fkey)
|
||||
(add-fkey table pg-fkey)
|
||||
pg-fkey))))
|
||||
(push-to-end from (fkey-columns fkey))
|
||||
(push-to-end to (fkey-foreign-columns fkey))))))
|
||||
(when ftable
|
||||
(let ((pg-fkey
|
||||
(make-fkey :table table
|
||||
:columns nil
|
||||
:foreign-table ftable
|
||||
:foreign-columns nil
|
||||
:update-rule on-update
|
||||
:delete-rule on-delete)))
|
||||
(setf (gethash id fkey-table) pg-fkey)
|
||||
(add-fkey table pg-fkey)
|
||||
pg-fkey)))))
|
||||
(if (and fkey from to)
|
||||
(progn
|
||||
(push-to-end from (fkey-columns fkey))
|
||||
(push-to-end to (fkey-foreign-columns fkey)))
|
||||
|
||||
;; it might be INCLUDING/EXCLUDING clauses that make it we
|
||||
;; don't have to care about the fkey definition, or it
|
||||
;; might be that the SQLite fkey definition is missing
|
||||
;; information, such as the `to` column, as seen in the
|
||||
;; field (bug report #681)
|
||||
(log-message :info
|
||||
"Incomplete Foreign Key definition on table ~a(~a) referencing table ~a(~a)"
|
||||
(when table (format-table-name table))
|
||||
from
|
||||
(when ftable (format-table-name ftable))
|
||||
to))))))
|
||||
|
||||
(defun list-all-fkeys (schema &key (db *sqlite-db*))
|
||||
"Get the list of SQLite foreign keys definitions per table."
|
||||
|
Loading…
Reference in New Issue
Block a user