Implement MS SQL option to skip creating schemas, fix #263.

Allow the user to control whether pgloader should create the same set of
schema as found on the MS SQL database.
This commit is contained in:
Dimitri Fontaine 2015-08-15 16:10:15 +02:00
parent 3e3ebf2333
commit 6fc40c4844
5 changed files with 68 additions and 8 deletions

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "PGLOADER" "1" "July 2015" "ff" "" .TH "PGLOADER" "1" "August 2015" "ff" ""
. .
.SH "NAME" .SH "NAME"
\fBpgloader\fR \- PostgreSQL data loader \fBpgloader\fR \- PostgreSQL data loader
@ -2516,7 +2516,22 @@ Connection string to an existing MS SQL database server that listens and welcome
\fIWITH\fR \fIWITH\fR
. .
.IP .IP
When loading from a \fBMS SQL\fR database, the same options as when loading a \fBMySQL\fR database are supported\. Please refer to the MySQL section\. When loading from a \fBMS SQL\fR database, the same options as when loading a \fBMySQL\fR database are supported\. Please refer to the MySQL section\. The following options are added:
.
.IP "\(bu" 4
\fIcreate schemas\fR
.
.IP
When this option is listed, pgloader creates the same schemas as found on the MS SQL instance\. This is the default\.
.
.IP "\(bu" 4
\fIcreate no schemas\fR
.
.IP
When this option is listed, pgloader refrains from creating any schemas at all, you must then ensure that the target schema do exist\.
.
.IP "" 0
. .
.IP "\(bu" 4 .IP "\(bu" 4
\fICAST\fR \fICAST\fR

View File

@ -2054,7 +2054,19 @@ The `mssql` command accepts the following clauses and options:
- *WITH* - *WITH*
When loading from a `MS SQL` database, the same options as when loading When loading from a `MS SQL` database, the same options as when loading
a `MySQL` database are supported. Please refer to the MySQL section. a `MySQL` database are supported. Please refer to the MySQL section. The
following options are added:
- *create schemas*
When this option is listed, pgloader creates the same schemas as
found on the MS SQL instance. This is the default.
- *create no schemas*
When this option is listed, pgloader refrains from creating any
schemas at all, you must then ensure that the target schema do
exist.
- *CAST* - *CAST*

View File

@ -96,6 +96,7 @@
(def-keyword-rule "delimiter") (def-keyword-rule "delimiter")
;; option for MySQL imports ;; option for MySQL imports
(def-keyword-rule "schema") (def-keyword-rule "schema")
(def-keyword-rule "schemas")
(def-keyword-rule "only") (def-keyword-rule "only")
(def-keyword-rule "drop") (def-keyword-rule "drop")
(def-keyword-rule "create") (def-keyword-rule "create")

View File

@ -12,6 +12,36 @@
;;; ;;;
;;; http://msdn.microsoft.com/en-us/library/ms187489(SQL.90).aspx ;;; http://msdn.microsoft.com/en-us/library/ms187489(SQL.90).aspx
;;; ;;;
(make-option-rule create-tables (and kw-create (? kw-no) kw-schemas))
(defrule mssql-option (or option-batch-rows
option-batch-size
option-batch-concurrency
option-truncate
option-disable-triggers
option-data-only
option-schema-only
option-include-drop
option-create-tables
option-create-schemas
option-create-indexes
option-reset-sequences
option-encoding))
(defrule another-mssql-option (and comma mssql-option)
(:lambda (source)
(bind (((_ option) source)) option)))
(defrule mssql-option-list (and mssql-option (* another-mssql-option))
(:lambda (source)
(destructuring-bind (opt1 opts) source
(alexandria:alist-plist (list* opt1 opts)))))
(defrule mssql-options (and kw-with mssql-option-list)
(:lambda (source)
(bind (((_ opts) source))
(cons :mssql-options opts))))
(defrule like-expression (and "'" (+ (not "'")) "'") (defrule like-expression (and "'" (+ (not "'")) "'")
(:lambda (le) (:lambda (le)
(bind (((_ like _) le)) (text like)))) (bind (((_ like _) le)) (text like))))
@ -53,7 +83,7 @@
;;; ;;;
;;; Allow clauses to appear in any order ;;; Allow clauses to appear in any order
;;; ;;;
(defrule load-mssql-optional-clauses (* (or mysql-options (defrule load-mssql-optional-clauses (* (or mssql-options
gucs gucs
casts casts
before-load before-load
@ -156,7 +186,7 @@
(bind (((ms-db-uri pg-db-uri (bind (((ms-db-uri pg-db-uri
&key &key
gucs casts before after including excluding gucs casts before after including excluding
((:mysql-options options))) ((:mssql-options options)))
source)) source))
(lisp-code-for-loading-from-mssql ms-db-uri pg-db-uri (lisp-code-for-loading-from-mssql ms-db-uri pg-db-uri
:gucs gucs :gucs gucs

View File

@ -180,6 +180,7 @@
(data-only nil) (data-only nil)
(schema-only nil) (schema-only nil)
(create-tables t) (create-tables t)
(create-schemas t)
(include-drop t) (include-drop t)
(create-indexes t) (create-indexes t)
(reset-sequences t) (reset-sequences t)
@ -226,9 +227,10 @@
(loop :for (schema . tables) :in all-columns (loop :for (schema . tables) :in all-columns
:do (let ((schema (apply-identifier-case schema))) :do (let ((schema (apply-identifier-case schema)))
;; create schema ;; create schema
(let ((sql (format nil "CREATE SCHEMA ~a;" schema))) (when create-schemas
(log-message :notice "~a" sql) (let ((sql (format nil "CREATE SCHEMA ~a;" schema)))
(pgsql-execute sql)) (log-message :notice "~a" sql)
(pgsql-execute sql)))
;; set search_path to only that schema ;; set search_path to only that schema
(pgsql-execute (pgsql-execute