mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-07 23:07:00 +02:00
Fix Postgres to Postgres migrations with schema name change.
When migrating from PostgreSQL, pgloader takes the index and foreign key definitions from the server directly, using pg_get_indexdef() and other catalog functions. That's very useful in that it embeds all the necessary quoting of the objects, and schema-qualify them. Of course we can't use the SQL definition as on the source system when we target a schema name that is different from the source system, which the code didn't realize before this patch. Here we simply invalidate the pre-computed SQL statement and resort to using the classic machinery to build the statement from pieces again. Fixes #903.
This commit is contained in:
parent
213edbe930
commit
0caa9c30ce
@ -65,7 +65,10 @@
|
||||
"Alter the schema of TABLE, set SCHEMA-NAME instead."
|
||||
(let* ((catalog (schema-catalog (table-schema table)))
|
||||
(schema (maybe-add-schema catalog schema-name)))
|
||||
(setf (table-schema table) schema)))
|
||||
(setf (table-schema table) schema)
|
||||
|
||||
;; this voids any index definition extracted from the source database...
|
||||
(reset-sql-definitions table)))
|
||||
|
||||
(defun alter-table-rename (table new-name)
|
||||
"Alter the name of TABLE to NEW-NAME."
|
||||
@ -130,4 +133,26 @@
|
||||
|
||||
(defun alter-schema-rename (schema new-name)
|
||||
"Alter the name fo the given schema to new-name."
|
||||
(setf (schema-name schema) new-name))
|
||||
(setf (schema-name schema) new-name)
|
||||
|
||||
;; this voids any index definition extracted from the source database...
|
||||
(loop :for table :in (schema-table-list schema)
|
||||
:do (reset-sql-definitions table)))
|
||||
|
||||
|
||||
|
||||
;;;
|
||||
;;; When a table targets a new schema, we need to refrain from using its
|
||||
;;; index SQL definition when we got it from the source system, such as with
|
||||
;;; pg_get_indexdef() on PostgreSQL.
|
||||
;;;
|
||||
(defun reset-sql-definitions (table)
|
||||
"Reset source database given wholesale SQL definition for table's indexes
|
||||
and foreign keys."
|
||||
(loop :for index :in (table-index-list table)
|
||||
:do (when (index-sql index)
|
||||
(setf (index-sql index) nil)))
|
||||
|
||||
(loop :for fkey :in (table-fkey-list table)
|
||||
:do (when (fkey-condef fkey)
|
||||
(setf (fkey-condef fkey) nil))))
|
||||
|
Loading…
Reference in New Issue
Block a user