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
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "PGLOADER" "1" "July 2015" "ff" ""
.TH "PGLOADER" "1" "August 2015" "ff" ""
.
.SH "NAME"
\fBpgloader\fR \- PostgreSQL data loader
@ -2516,7 +2516,22 @@ Connection string to an existing MS SQL database server that listens and welcome
\fIWITH\fR
.
.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
\fICAST\fR

View File

@ -2054,7 +2054,19 @@ The `mssql` command accepts the following clauses and options:
- *WITH*
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*

View File

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

View File

@ -12,6 +12,36 @@
;;;
;;; 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 "'")) "'")
(:lambda (le)
(bind (((_ like _) le)) (text like))))
@ -53,7 +83,7 @@
;;;
;;; Allow clauses to appear in any order
;;;
(defrule load-mssql-optional-clauses (* (or mysql-options
(defrule load-mssql-optional-clauses (* (or mssql-options
gucs
casts
before-load
@ -156,7 +186,7 @@
(bind (((ms-db-uri pg-db-uri
&key
gucs casts before after including excluding
((:mysql-options options)))
((:mssql-options options)))
source))
(lisp-code-for-loading-from-mssql ms-db-uri pg-db-uri
:gucs gucs

View File

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