mirror of
https://github.com/dimitri/pgloader.git
synced 2026-02-14 10:51:03 +01:00
Allow the MySQL command parser to process clauses in any order, fix #56.
Only the MySQL command is addressed in this patch, because the code level approach is not safisfying me completely. It might be easier to just bite the bullet and review all the optional clauses return values rather than add a layer as this patch does. The feature still is available for MySQL given this patch, so let's push it, get feedback, then see about how to make the approach scale and revise all the other commands.
This commit is contained in:
parent
ff8489e656
commit
7db001a7c3
@ -966,23 +966,51 @@
|
||||
|
||||
(defrule decoding-tables-as (* decoding-table-as))
|
||||
|
||||
|
||||
;;;
|
||||
;;; Allow clauses to appear in any order
|
||||
;;;
|
||||
(defrule mysql-options-clause mysql-options
|
||||
(:lambda (opts) `(:mysql-options ,@opts)))
|
||||
|
||||
(defrule gucs-clause gucs (:lambda (gucs) `(:gucs ,@gucs)))
|
||||
(defrule casts-clause casts (:lambda (casts) `(:casts ,@casts)))
|
||||
(defrule mview-clause materialize-views (:lambda (mv) `(:views ,@mv)))
|
||||
(defrule including-clause including (:lambda (inc) `(:including ,@inc)))
|
||||
(defrule excluding-clause excluding (:lambda (exc) `(:excluding ,@exc)))
|
||||
(defrule decoding-clause decoding-table-as (:lambda (dec) `(:decoding ,dec)))
|
||||
(defrule before-clause before-load (:lambda (b) `(:before ,@b)))
|
||||
(defrule after-clause after-load (:lambda (a) `(:after ,@a)))
|
||||
|
||||
(defrule load-mysql-optional-clauses (+ (or mysql-options-clause
|
||||
gucs-clause
|
||||
casts-clause
|
||||
mview-clause
|
||||
including-clause
|
||||
excluding-clause
|
||||
decoding-clause
|
||||
before-clause
|
||||
after-clause))
|
||||
(:lambda (clauses-list)
|
||||
(alexandria:alist-plist clauses-list)))
|
||||
|
||||
(defrule load-mysql-command (and database-source target
|
||||
load-mysql-optional-clauses)
|
||||
(:lambda (command)
|
||||
(destructuring-bind (source target clauses) command
|
||||
`(,source ,target ,@clauses))))
|
||||
|
||||
|
||||
;;; LOAD DATABASE FROM mysql://
|
||||
(defrule load-mysql-database (and database-source target
|
||||
(? mysql-options)
|
||||
(? gucs)
|
||||
(? casts)
|
||||
(? materialize-views)
|
||||
(? including)
|
||||
(? excluding)
|
||||
(? decoding-tables-as)
|
||||
(? before-load)
|
||||
(? after-load))
|
||||
(defrule load-mysql-database load-mysql-command
|
||||
(:lambda (source)
|
||||
(destructuring-bind (my-db-uri pg-db-uri options
|
||||
gucs casts views
|
||||
incl excl decoding-as
|
||||
before after)
|
||||
(destructuring-bind (my-db-uri pg-db-uri
|
||||
&key
|
||||
gucs casts views before after
|
||||
((:mysql-options options))
|
||||
((:including incl))
|
||||
((:excuding excl))
|
||||
((:decoding decoding-as)))
|
||||
source
|
||||
(destructuring-bind (&key ((:dbname mydb)) table-name
|
||||
&allow-other-keys)
|
||||
|
||||
@ -2,7 +2,9 @@ LOAD DATABASE
|
||||
FROM mysql://root@unix:/tmp/mysql.sock:/goeuro
|
||||
INTO postgresql://dim@unix:/tmp:/godollar
|
||||
|
||||
WITH include drop, create tables, create indexes, reset sequences
|
||||
INCLUDING ONLY TABLE NAMES MATCHING ~/encoding/
|
||||
|
||||
DECODING TABLE NAMES MATCHING ~/messed/, ~/encoding/ AS utf-8
|
||||
|
||||
CAST type datetime to timestamptz drop default drop not null using zero-dates-to-null,
|
||||
type date drop not null drop default using zero-dates-to-null,
|
||||
@ -24,7 +26,7 @@ LOAD DATABASE
|
||||
group by cast(d as date);
|
||||
$$
|
||||
|
||||
-- INCLUDING ONLY TABLE NAMES MATCHING ~/encoding/
|
||||
WITH include drop, create tables, create indexes, reset sequences
|
||||
|
||||
DECODING TABLE NAMES MATCHING ~/messed/, ~/encoding/ AS utf-8;
|
||||
;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user