mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-04 10:31:02 +02:00
Add the option to preserve MySQL index names, fix #187.
See test/parse/hans.goeuro.load for an example usage of the new option. In passing, any error when creating indexes is now properly reported and logged, which was missing previously. Oops.
This commit is contained in:
parent
d8510b031c
commit
7d2d09ce68
14
pgloader.1
14
pgloader.1
@ -1,7 +1,7 @@
|
||||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "PGLOADER" "1" "February 2015" "ff" ""
|
||||
.TH "PGLOADER" "1" "March 2015" "ff" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBpgloader\fR \- PostgreSQL data loader
|
||||
@ -1720,6 +1720,18 @@ When this option is listed, pgloader gets the definitions of all the indexes fou
|
||||
When this option is listed, pgloader skips the creating indexes\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
\fIuniquify index names\fR, \fIpreserve index names\fR
|
||||
.
|
||||
.IP
|
||||
MySQL index names are unique per\-table whereas in PostgreSQL index names have to be unique per\-schema\. The default for pgloader is to change the index name by prefixing it with \fBidx_OID\fR where \fBOID\fR is the internal numeric identifier of the table the index is built against\.
|
||||
.
|
||||
.IP
|
||||
In somes cases like when the DDL are entirely left to a framework it might be sensible for pgloader to refrain from handling index unique names, that is achieved by using the \fIpreserve index names\fR option\.
|
||||
.
|
||||
.IP
|
||||
The default is to \fIuniquify index names\fR\.
|
||||
.
|
||||
.IP "\(bu" 4
|
||||
\fIforeign keys\fR
|
||||
.
|
||||
.IP
|
||||
|
||||
@ -1456,6 +1456,20 @@ The `database` command accepts the following clauses and options:
|
||||
|
||||
When this option is listed, pgloader skips the creating indexes.
|
||||
|
||||
- *uniquify index names*, *preserve index names*
|
||||
|
||||
MySQL index names are unique per-table whereas in PostgreSQL index
|
||||
names have to be unique per-schema. The default for pgloader is to
|
||||
change the index name by prefixing it with `idx_OID` where `OID` is
|
||||
the internal numeric identifier of the table the index is built
|
||||
against.
|
||||
|
||||
In somes cases like when the DDL are entirely left to a framework it
|
||||
might be sensible for pgloader to refrain from handling index unique
|
||||
names, that is achieved by using the *preserve index names* option.
|
||||
|
||||
The default is to *uniquify index names*.
|
||||
|
||||
- *foreign keys*
|
||||
|
||||
When this option is listed, pgloader gets the definitions of all the
|
||||
|
||||
@ -103,7 +103,10 @@
|
||||
(def-keyword-rule "names")
|
||||
(def-keyword-rule "tables")
|
||||
(def-keyword-rule "views")
|
||||
(def-keyword-rule "index")
|
||||
(def-keyword-rule "indexes")
|
||||
(def-keyword-rule "preserve")
|
||||
(def-keyword-rule "uniquify")
|
||||
(def-keyword-rule "sequences")
|
||||
(def-keyword-rule "foreign")
|
||||
(def-keyword-rule "keys")
|
||||
|
||||
@ -123,6 +123,11 @@
|
||||
(bind (((action _) id-case))
|
||||
(cons :identifier-case action))))
|
||||
|
||||
(defrule option-index-names (and (or kw-preserve kw-uniquify) kw-index kw-names)
|
||||
(:lambda (preserve-or-uniquify)
|
||||
(bind (((action _ _) preserve-or-uniquify))
|
||||
(cons :index-names action))))
|
||||
|
||||
(defrule mysql-option (or option-workers
|
||||
option-batch-rows
|
||||
option-batch-size
|
||||
@ -134,6 +139,7 @@
|
||||
option-include-drop
|
||||
option-create-tables
|
||||
option-create-indexes
|
||||
option-index-names
|
||||
option-reset-sequences
|
||||
option-foreign-keys
|
||||
option-identifiers-case))
|
||||
|
||||
@ -116,7 +116,8 @@
|
||||
(multiple-value-bind (res secs)
|
||||
(timing
|
||||
(handler-case (pgsql-execute sql)
|
||||
(cl-postgres:database-error ()
|
||||
(cl-postgres:database-error (e)
|
||||
(log-message :error "~a" e)
|
||||
(pgstate-incf state label :errs 1 :rows (- count)))))
|
||||
(declare (ignore res))
|
||||
(pgstate-incf state label :read count :rows count :secs secs)))
|
||||
|
||||
@ -271,9 +271,12 @@
|
||||
|
||||
(defmethod format-pgsql-create-index ((index pgsql-index))
|
||||
"Generate the PostgreSQL statement list to rebuild a Foreign Key"
|
||||
(let* ((index-name (format nil "idx_~a_~a"
|
||||
(pgsql-index-table-oid index)
|
||||
(pgsql-index-name index)))
|
||||
(let* ((index-name (if (pgsql-index-table-oid index)
|
||||
(format nil "idx_~a_~a"
|
||||
(pgsql-index-table-oid index)
|
||||
(pgsql-index-name index))
|
||||
;; lacking the oid means we preserve the index name
|
||||
(pgsql-index-name index)))
|
||||
(table-name (apply-identifier-case (pgsql-index-table-name index)))
|
||||
(index-name (apply-identifier-case index-name))
|
||||
|
||||
|
||||
@ -152,7 +152,8 @@
|
||||
&key
|
||||
state
|
||||
foreign-keys
|
||||
include-drop)
|
||||
include-drop
|
||||
preserve-index-names)
|
||||
"Prepare the target PostgreSQL database: create tables casting datatypes
|
||||
from the MySQL definitions, prepare index definitions and create target
|
||||
tables for materialized views.
|
||||
@ -179,7 +180,8 @@
|
||||
;; MySQL allows the same index name being used against several
|
||||
;; tables, so we add the PostgreSQL table OID in the index name,
|
||||
;; to differenciate. Set the table oids now.
|
||||
(set-table-oids all-indexes)
|
||||
(unless preserve-index-names
|
||||
(set-table-oids all-indexes))
|
||||
|
||||
;; We might have to MATERIALIZE VIEWS
|
||||
(when materialize-views
|
||||
@ -356,6 +358,7 @@
|
||||
(create-tables t)
|
||||
(include-drop t)
|
||||
(create-indexes t)
|
||||
(index-names :uniquify)
|
||||
(reset-sequences t)
|
||||
(foreign-keys t)
|
||||
only-tables
|
||||
@ -406,7 +409,9 @@
|
||||
view-columns
|
||||
:state state-before
|
||||
:foreign-keys foreign-keys
|
||||
:include-drop include-drop))
|
||||
:include-drop include-drop
|
||||
:preserve-index-names (eq :preserve
|
||||
index-names)))
|
||||
(t
|
||||
(when truncate
|
||||
(truncate-tables (target-db mysql) (mapcar #'car all-columns)))))
|
||||
|
||||
@ -37,5 +37,6 @@ LOAD DATABASE
|
||||
WITH include drop,
|
||||
create tables,
|
||||
create indexes,
|
||||
preserve index names,
|
||||
reset sequences,
|
||||
disable triggers;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user