Add a "with foreign keys" option to the MySQL Command.

This commit is contained in:
Dimitri Fontaine 2013-11-05 19:16:12 +01:00
parent 911c40dc2d
commit 450c06b6fb
3 changed files with 30 additions and 21 deletions

View File

@ -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)

View File

@ -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
@ -236,8 +237,9 @@
(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
@ -299,10 +301,11 @@
;; 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.
;; ;;
(when foreign-keys
(create-fkeys all-fkeys (create-fkeys all-fkeys
:dbname pg-dbname :dbname pg-dbname
:state state-after :state state-after
:identifier-case identifier-case) :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

View File

@ -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'