From 5e7e5391ef009662a333a227c8fc4d3e7908e87a Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 26 Jul 2015 15:38:15 +0200 Subject: [PATCH] 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. --- src/pgsql/queries.lisp | 4 ++-- src/pgsql/schema.lisp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/pgsql/queries.lisp b/src/pgsql/queries.lisp index 593a36a..d2ede5d 100644 --- a/src/pgsql/queries.lisp +++ b/src/pgsql/queries.lisp @@ -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." diff --git a/src/pgsql/schema.lisp b/src/pgsql/schema.lisp index 3668c3c..2d5c368 100644 --- a/src/pgsql/schema.lisp +++ b/src/pgsql/schema.lisp @@ -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))))