mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-07 23:07:00 +02:00
The new ALTER TABLE facility allows to act on tables found in the MySQL database before the migration happens. In this patch the only provided actions are RENAME TO and SET SCHEMA, which fixes #224. In order to be able to provide the same option for MS SQL users, we will have to make it work at the SCHEMA level (ALTER SCHEMA ... RENAME TO ...) and modify the internal schema-struct so that the schema slot of our table instances are a schema instance rather than its name. Lacking MS SQL test database and instance, the facility is not yet provided for that source type.
59 lines
2.1 KiB
Common Lisp
59 lines
2.1 KiB
Common Lisp
|
||
;;;
|
||
;;; ALTER TABLE allows to change some of their properties while migrating
|
||
;;; from a source to PostgreSQL, currently only takes care of the schema.
|
||
;;;
|
||
(in-package #:pgloader.parser)
|
||
|
||
(defrule match-rule-target-regex quoted-regex)
|
||
(defrule match-rule-target-string quoted-namestring
|
||
(:lambda (x) (list :string x)))
|
||
|
||
(defrule match-rule-target (or match-rule-target-string
|
||
match-rule-target-regex))
|
||
|
||
(defrule another-match-rule-target (and comma match-rule-target)
|
||
(:lambda (x)
|
||
(bind (((_ target) x)) target)))
|
||
|
||
(defrule filter-list-matching
|
||
(and match-rule-target (* another-match-rule-target))
|
||
(:lambda (source)
|
||
(destructuring-bind (filter1 filters) source
|
||
(list* filter1 filters))))
|
||
|
||
(defrule alter-table-names-matching (and kw-alter kw-table kw-names kw-matching
|
||
filter-list-matching)
|
||
(:lambda (alter-table)
|
||
(bind (((_ _ _ _ match-rule-target-list) alter-table))
|
||
match-rule-target-list)))
|
||
|
||
(defrule rename-to (and kw-rename kw-to quoted-namestring)
|
||
(:lambda (stmt)
|
||
(bind (((_ _ new-name) stmt))
|
||
(list #'pgloader.schema::alter-table-rename new-name))))
|
||
|
||
(defrule set-schema (and kw-set kw-schema quoted-namestring)
|
||
(:lambda (stmt)
|
||
(bind (((_ _ schema) stmt))
|
||
(list #'pgloader.schema::alter-table-set-schema schema))))
|
||
|
||
(defrule alter-table-action (or rename-to
|
||
set-schema))
|
||
|
||
(defrule alter-table-command (and alter-table-names-matching alter-table-action)
|
||
(:lambda (alter-table-command)
|
||
(destructuring-bind (match-rule-target-list action) alter-table-command
|
||
(loop :for match-rule-target :in match-rule-target-list
|
||
:collect (pgloader.schema::make-match-rule
|
||
:type (first match-rule-target)
|
||
:target (second match-rule-target)
|
||
:action (first action)
|
||
:args (rest action))))))
|
||
|
||
(defrule alter-table (+ (and alter-table-command ignore-whitespace))
|
||
(:lambda (alter-table-command-list)
|
||
(cons :alter-table
|
||
(loop :for (command ws) :in alter-table-command-list
|
||
:collect command))))
|