Implement a separate switch to drop the schemas.

The with option “include drop” used to also apply to schemas, which is not
that useful and problematic when trying to DROP SCHEMA public, because you
might not connect as the owner of that schema.

Even if we don't target the public schema by default, users can choose to do
so thanks to our ALTER SCHEMA ... RENAME TO ... command.

Fixes #594.
This commit is contained in:
Dimitri Fontaine 2017-07-18 13:13:36 +02:00
parent ae0c6ed119
commit b1fa3aec3c
5 changed files with 21 additions and 1 deletions

View File

@ -1949,6 +1949,12 @@ The default is to \fIuniquify index names\fR\.
Even when using the option \fIpreserve index names\fR, MySQL primary key indexes named "PRIMARY" will get their names uniquified\. Failing to do so would prevent the primary keys to be created again in PostgreSQL where the index names must be unique per schema\. Even when using the option \fIpreserve index names\fR, MySQL primary key indexes named "PRIMARY" will get their names uniquified\. Failing to do so would prevent the primary keys to be created again in PostgreSQL where the index names must be unique per schema\.
. .
.IP "\(bu" 4 .IP "\(bu" 4
\fIdrop schema\fR
.
.IP
When this option is listed, pgloader drops the target schema in the target PostgreSQL database before creating it again and all the objects it contains\. The default behavior doesn\'t drop the target schemas\.
.
.IP "\(bu" 4
\fIforeign keys\fR \fIforeign keys\fR
. .
.IP .IP

View File

@ -1685,6 +1685,13 @@ The `database` command accepts the following clauses and options:
do so would prevent the primary keys to be created again in do so would prevent the primary keys to be created again in
PostgreSQL where the index names must be unique per schema. PostgreSQL where the index names must be unique per schema.
- *drop schema*
When this option is listed, pgloader drops the target schema in the
target PostgreSQL database before creating it again and all the
objects it contains. The default behavior doesn't drop the target
schemas.
- *foreign keys* - *foreign keys*
When this option is listed, pgloader gets the definitions of all the When this option is listed, pgloader gets the definitions of all the

View File

@ -23,6 +23,7 @@
option-data-only option-data-only
option-schema-only option-schema-only
option-include-drop option-include-drop
option-drop-schema
option-create-tables option-create-tables
option-create-indexes option-create-indexes
option-index-names option-index-names

View File

@ -137,6 +137,9 @@
(make-option-rule reset-sequences (and kw-reset (? kw-no) kw-sequences)) (make-option-rule reset-sequences (and kw-reset (? kw-no) kw-sequences))
(make-option-rule foreign-keys (and (? kw-no) kw-foreign kw-keys)) (make-option-rule foreign-keys (and (? kw-no) kw-foreign kw-keys))
(defrule option-drop-schema (and kw-drop kw-schema)
(:constant (cons :drop-schema t)))
(defrule option-reindex (and kw-drop kw-indexes) (defrule option-reindex (and kw-drop kw-indexes)
(:constant (cons :reindex t))) (:constant (cons :reindex t)))

View File

@ -14,6 +14,7 @@
truncate truncate
create-tables create-tables
create-schemas create-schemas
drop-schema
drop-indexes drop-indexes
set-table-oids set-table-oids
materialize-views materialize-views
@ -37,7 +38,7 @@
:use-result-as-read t :use-result-as-read t
:use-result-as-rows t) :use-result-as-rows t)
(create-schemas catalog (create-schemas catalog
:include-drop include-drop :include-drop drop-schema
:client-min-messages :error))) :client-min-messages :error)))
;; create new SQL types (ENUMs, SETs) if needed and before we ;; create new SQL types (ENUMs, SETs) if needed and before we
@ -248,6 +249,7 @@
(create-schemas t) (create-schemas t)
(create-tables t) (create-tables t)
(include-drop t) (include-drop t)
(drop-schema nil)
(create-indexes t) (create-indexes t)
(index-names :uniquify) (index-names :uniquify)
(reset-sequences t) (reset-sequences t)
@ -320,6 +322,7 @@
:create-tables create-tables :create-tables create-tables
:create-schemas create-schemas :create-schemas create-schemas
:drop-indexes drop-indexes :drop-indexes drop-indexes
:drop-schema drop-schema
:include-drop include-drop :include-drop include-drop
:foreign-keys foreign-keys :foreign-keys foreign-keys
:set-table-oids set-table-oids :set-table-oids set-table-oids