Fix the drop indexes option again, fix #251.

The index and constraint names given by PostgreSQL catalogs should not
be second guessed, we need to just quote them. The identifier down
casing is interesting when we get identifiers from other system for a
migration, but are wrong when dropping existing indexes in PostgreSQL.

Also, the :null special value from Postmodern was routing the code
badly, just transform it manually to nil when fetching the index list,
manually.
This commit is contained in:
Dimitri Fontaine 2015-07-26 15:38:15 +02:00
parent 833b41c23b
commit 5e7e5391ef
2 changed files with 13 additions and 4 deletions

View File

@ -218,8 +218,8 @@ select i.relname,
:unique unique
:columns nil
:sql sql
:conname conname
:condef condef)))
:conname (unless (eq :null conname) conname)
:condef (unless (eq :null condef) condef))))
(defun list-reserved-keywords (pgconn)
"Connect to PostgreSQL DBNAME and fetch reserved keywords."

View File

@ -328,7 +328,10 @@
(let* ((table-name (apply-identifier-case (pgsql-index-table-name index)))
(index-name (apply-identifier-case (pgsql-index-name index))))
(cond ((pgsql-index-conname index)
(format nil "ALTER TABLE ~a DROP CONSTRAINT ~a;"
;; here always quote the constraint name, currently the name
;; comes from one source only, the PostgreSQL database catalogs,
;; so don't question it, quote it.
(format nil "ALTER TABLE ~a DROP CONSTRAINT ~s;"
table-name (pgsql-index-conname index)))
(t
@ -402,7 +405,10 @@
"Drop the indexes for TABLE-NAME on TARGET PostgreSQL connection, and
returns a list of indexes to create again."
(with-pgsql-connection (target)
(let ((indexes (list-indexes table-name)))
(let ((indexes (list-indexes table-name))
;; we get the list of indexes from PostgreSQL catalogs, so don't
;; question their spelling, just quote them.
(*identifier-case* :quote))
(cond ((and indexes (not drop-indexes))
(log-message :warning
"Target table ~s has ~d indexes defined against it."
@ -425,6 +431,9 @@
"Create the indexes that we dropped previously."
(when (and indexes drop-indexes)
(let* ((*preserve-index-names* t)
;; we get the list of indexes from PostgreSQL catalogs, so don't
;; question their spelling, just quote them.
(*identifier-case* :quote)
(idx-kernel (make-kernel (length indexes)))
(idx-channel (let ((lp:*kernel* idx-kernel))
(lp:make-channel))))