diff --git a/pgloader.1 b/pgloader.1 index f779f0f..d8e4ce5 100644 --- a/pgloader.1 +++ b/pgloader.1 @@ -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 diff --git a/pgloader.1.md b/pgloader.1.md index fff8cac..2bcd823 100644 --- a/pgloader.1.md +++ b/pgloader.1.md @@ -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 diff --git a/src/parsers/command-mysql.lisp b/src/parsers/command-mysql.lisp index 7e14200..12baa9b 100644 --- a/src/parsers/command-mysql.lisp +++ b/src/parsers/command-mysql.lisp @@ -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 diff --git a/src/parsers/command-options.lisp b/src/parsers/command-options.lisp index 76ca0f7..4842144 100644 --- a/src/parsers/command-options.lisp +++ b/src/parsers/command-options.lisp @@ -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))) diff --git a/src/sources/common/db-methods.lisp b/src/sources/common/db-methods.lisp index 29fb797..0524a82 100644 --- a/src/sources/common/db-methods.lisp +++ b/src/sources/common/db-methods.lisp @@ -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