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\.
.
.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
.
.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
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*
When this option is listed, pgloader gets the definitions of all the

View File

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

View File

@ -137,6 +137,9 @@
(make-option-rule reset-sequences (and kw-reset (? kw-no) kw-sequences))
(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)
(:constant (cons :reindex t)))

View File

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