diff --git a/src/parser.lisp b/src/parser.lisp index 46dd2ba..2e0fae3 100644 --- a/src/parser.lisp +++ b/src/parser.lisp @@ -121,6 +121,8 @@ (def-keyword-rule "tables") (def-keyword-rule "indexes") (def-keyword-rule "sequences") + (def-keyword-rule "foreign") + (def-keyword-rule "keys") (def-keyword-rule "downcase") (def-keyword-rule "quote") (def-keyword-rule "identifiers") @@ -442,6 +444,9 @@ (defrule option-reset-sequences (and kw-reset kw-sequences) (: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) (:lambda (id-case) (destructuring-bind (action id) id-case @@ -455,6 +460,7 @@ option-create-tables option-create-indexes option-reset-sequences + option-foreign-keys option-identifiers-case)) (defrule another-mysql-option (and #\, ignore-whitespace mysql-option) diff --git a/src/sources/mysql.lisp b/src/sources/mysql.lisp index ae11da2..bf231f0 100644 --- a/src/sources/mysql.lisp +++ b/src/sources/mysql.lisp @@ -195,6 +195,7 @@ include-drop create-indexes reset-sequences + foreign-keys (identifier-case :downcase) ; or :quote only-tables including @@ -212,9 +213,9 @@ :including including :excluding excluding)) (all-fkeys (filter-column-list (list-all-fkeys dbname) - :only-tables only-tables - :including including - :excluding excluding)) + :only-tables only-tables + :including including + :excluding excluding)) (all-indexes (filter-column-list (list-all-indexes dbname) :only-tables only-tables :including including @@ -233,16 +234,17 @@ (with-stats-collection (pg-dbname "create, drop" :use-result-as-rows t :state state-before) - (with-pgsql-transaction (pg-dbname) - ;; we need to first drop the Foreign Key Constraints, so that we - ;; can DROP TABLE when asked - (when include-drop - (drop-fkeys all-fkeys :identifier-case identifier-case)) + (with-pgsql-transaction (pg-dbname) + ;; we need to first drop the Foreign Key Constraints, so that we + ;; can DROP TABLE when asked + (when (and foreign-keys include-drop) + (drop-fkeys all-fkeys + :identifier-case identifier-case)) - ;; now drop then create tables and types, etc - (create-tables all-columns - :identifier-case identifier-case - :include-drop include-drop)))) + ;; now drop then create tables and types, etc + (create-tables all-columns + :identifier-case identifier-case + :include-drop include-drop)))) (loop 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 ;; and indexes are imported before doing that. ;; - (create-fkeys all-fkeys - :dbname pg-dbname - :state state-after - :identifier-case identifier-case) + (when foreign-keys + (create-fkeys all-fkeys + :dbname pg-dbname + :state state-after + :identifier-case identifier-case)) ;; and report the total time spent on the operation (when summary - (report-full-summary "Total streaming time" *state* - :before state-before - :finally state-after - :parallel idx-state)))) + (report-full-summary "Total streaming time" *state* + :before state-before + :finally state-after + :parallel idx-state)))) ;;; diff --git a/test/sakila.load b/test/sakila.load index 7db4bc7..304384b 100644 --- a/test/sakila.load +++ b/test/sakila.load @@ -2,7 +2,7 @@ load database from mysql://root@localhost/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'