mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-08 07:16:58 +02:00
Add a "with foreign keys" option to the MySQL Command.
This commit is contained in:
parent
911c40dc2d
commit
450c06b6fb
@ -121,6 +121,8 @@
|
|||||||
(def-keyword-rule "tables")
|
(def-keyword-rule "tables")
|
||||||
(def-keyword-rule "indexes")
|
(def-keyword-rule "indexes")
|
||||||
(def-keyword-rule "sequences")
|
(def-keyword-rule "sequences")
|
||||||
|
(def-keyword-rule "foreign")
|
||||||
|
(def-keyword-rule "keys")
|
||||||
(def-keyword-rule "downcase")
|
(def-keyword-rule "downcase")
|
||||||
(def-keyword-rule "quote")
|
(def-keyword-rule "quote")
|
||||||
(def-keyword-rule "identifiers")
|
(def-keyword-rule "identifiers")
|
||||||
@ -442,6 +444,9 @@
|
|||||||
(defrule option-reset-sequences (and kw-reset kw-sequences)
|
(defrule option-reset-sequences (and kw-reset kw-sequences)
|
||||||
(:constant (cons :reset-sequences t)))
|
(:constant (cons :reset-sequences t)))
|
||||||
|
|
||||||
|
(defrule option-foreign-keys (and kw-foreign kw-keys)
|
||||||
|
(:constant (cons :foreign-keys t)))
|
||||||
|
|
||||||
(defrule option-identifiers-case (and (or kw-downcase kw-quote) kw-identifiers)
|
(defrule option-identifiers-case (and (or kw-downcase kw-quote) kw-identifiers)
|
||||||
(:lambda (id-case)
|
(:lambda (id-case)
|
||||||
(destructuring-bind (action id) id-case
|
(destructuring-bind (action id) id-case
|
||||||
@ -455,6 +460,7 @@
|
|||||||
option-create-tables
|
option-create-tables
|
||||||
option-create-indexes
|
option-create-indexes
|
||||||
option-reset-sequences
|
option-reset-sequences
|
||||||
|
option-foreign-keys
|
||||||
option-identifiers-case))
|
option-identifiers-case))
|
||||||
|
|
||||||
(defrule another-mysql-option (and #\, ignore-whitespace mysql-option)
|
(defrule another-mysql-option (and #\, ignore-whitespace mysql-option)
|
||||||
|
@ -195,6 +195,7 @@
|
|||||||
include-drop
|
include-drop
|
||||||
create-indexes
|
create-indexes
|
||||||
reset-sequences
|
reset-sequences
|
||||||
|
foreign-keys
|
||||||
(identifier-case :downcase) ; or :quote
|
(identifier-case :downcase) ; or :quote
|
||||||
only-tables
|
only-tables
|
||||||
including
|
including
|
||||||
@ -212,9 +213,9 @@
|
|||||||
:including including
|
:including including
|
||||||
:excluding excluding))
|
:excluding excluding))
|
||||||
(all-fkeys (filter-column-list (list-all-fkeys dbname)
|
(all-fkeys (filter-column-list (list-all-fkeys dbname)
|
||||||
:only-tables only-tables
|
:only-tables only-tables
|
||||||
:including including
|
:including including
|
||||||
:excluding excluding))
|
:excluding excluding))
|
||||||
(all-indexes (filter-column-list (list-all-indexes dbname)
|
(all-indexes (filter-column-list (list-all-indexes dbname)
|
||||||
:only-tables only-tables
|
:only-tables only-tables
|
||||||
:including including
|
:including including
|
||||||
@ -233,16 +234,17 @@
|
|||||||
(with-stats-collection (pg-dbname "create, drop"
|
(with-stats-collection (pg-dbname "create, drop"
|
||||||
:use-result-as-rows t
|
:use-result-as-rows t
|
||||||
:state state-before)
|
:state state-before)
|
||||||
(with-pgsql-transaction (pg-dbname)
|
(with-pgsql-transaction (pg-dbname)
|
||||||
;; we need to first drop the Foreign Key Constraints, so that we
|
;; we need to first drop the Foreign Key Constraints, so that we
|
||||||
;; can DROP TABLE when asked
|
;; can DROP TABLE when asked
|
||||||
(when include-drop
|
(when (and foreign-keys include-drop)
|
||||||
(drop-fkeys all-fkeys :identifier-case identifier-case))
|
(drop-fkeys all-fkeys
|
||||||
|
:identifier-case identifier-case))
|
||||||
|
|
||||||
;; now drop then create tables and types, etc
|
;; now drop then create tables and types, etc
|
||||||
(create-tables all-columns
|
(create-tables all-columns
|
||||||
:identifier-case identifier-case
|
:identifier-case identifier-case
|
||||||
:include-drop include-drop))))
|
:include-drop include-drop))))
|
||||||
|
|
||||||
(loop
|
(loop
|
||||||
for (table-name . columns) in all-columns
|
for (table-name . columns) in all-columns
|
||||||
@ -299,17 +301,18 @@
|
|||||||
;; tables to be able to build the foreign keys, so wait until all tables
|
;; tables to be able to build the foreign keys, so wait until all tables
|
||||||
;; and indexes are imported before doing that.
|
;; and indexes are imported before doing that.
|
||||||
;;
|
;;
|
||||||
(create-fkeys all-fkeys
|
(when foreign-keys
|
||||||
:dbname pg-dbname
|
(create-fkeys all-fkeys
|
||||||
:state state-after
|
:dbname pg-dbname
|
||||||
:identifier-case identifier-case)
|
:state state-after
|
||||||
|
:identifier-case identifier-case))
|
||||||
|
|
||||||
;; and report the total time spent on the operation
|
;; and report the total time spent on the operation
|
||||||
(when summary
|
(when summary
|
||||||
(report-full-summary "Total streaming time" *state*
|
(report-full-summary "Total streaming time" *state*
|
||||||
:before state-before
|
:before state-before
|
||||||
:finally state-after
|
:finally state-after
|
||||||
:parallel idx-state))))
|
:parallel idx-state))))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
|
@ -2,7 +2,7 @@ load database
|
|||||||
from mysql://root@localhost/sakila
|
from mysql://root@localhost/sakila
|
||||||
into postgresql://localhost:54393/sakila
|
into postgresql://localhost:54393/sakila
|
||||||
|
|
||||||
WITH drop tables, create tables, create indexes, reset sequences
|
WITH drop tables, create tables, create indexes, reset sequences, foreign keys
|
||||||
|
|
||||||
SET maintenance_work_mem to '128MB', work_mem to '12MB', search_path to 'sakila'
|
SET maintenance_work_mem to '128MB', work_mem to '12MB', search_path to 'sakila'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user