mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-04 10:31:02 +02:00
Implement ALTER TABLE ... SET TABLESPACE ... as a pgloader clause.
This allows creating tables in any target tablespace rather than the default one, and is supported for the various sources having support for the ALTER TABLE clause already.
This commit is contained in:
parent
f28f8e577d
commit
2147a1d07b
@ -139,6 +139,8 @@ actions are *SET SCHEMA*, *RENAME TO*, and *SET*::
|
||||
ALTER TABLE NAMES MATCHING 'film' IN SCHEMA 'dbo' RENAME TO 'films'
|
||||
|
||||
ALTER TABLE NAMES MATCHING ~/./ IN SCHEMA 'dbo' SET (fillfactor='40')
|
||||
|
||||
ALTER TABLE NAMES MATCHING ~/./ IN SCHEMA 'dbo' SET TABLESPACE 'tlbspc'
|
||||
|
||||
You can use as many such rules as you need. The list of tables to be
|
||||
migrated is searched in pgloader memory against the *ALTER TABLE* matching
|
||||
@ -153,6 +155,9 @@ schema. In case of a name change, the mapping is kept and reused in the
|
||||
The *SET ()* action takes effect as a *WITH* clause for the `CREATE TABLE`
|
||||
command that pgloader will run when it has to create a table.
|
||||
|
||||
The *SET TABLESPACE* action takes effect as a *TABLESPACE* clause for the
|
||||
`CREATE TABLE` command that pgloader will run when it has to create a table.
|
||||
|
||||
The matching is done in pgloader itself, with a Common Lisp regular
|
||||
expression lib, so doesn't depend on the *LIKE* implementation of MS SQL,
|
||||
nor on the lack of support for regular expressions in the engine.
|
||||
|
||||
@ -509,6 +509,8 @@ actions are *SET SCHEMA*, *RENAME TO*, and *SET*::
|
||||
|
||||
ALTER TABLE NAMES MATCHING ~/./ SET (fillfactor='40')
|
||||
|
||||
ALTER TABLE NAMES MATCHING ~/./ SET TABLESPACE 'pg_default'
|
||||
|
||||
You can use as many such rules as you need. The list of tables to be
|
||||
migrated is searched in pgloader memory against the *ALTER TABLE* matching
|
||||
rules, and for each command pgloader stops at the first matching criteria
|
||||
@ -522,6 +524,9 @@ schema. In case of a name change, the mapping is kept and reused in the
|
||||
The *SET ()* action takes effect as a *WITH* clause for the `CREATE TABLE`
|
||||
command that pgloader will run when it has to create a table.
|
||||
|
||||
The *SET TABLESPACE* action takes effect as a *TABLESPACE* clause for the
|
||||
`CREATE TABLE` command that pgloader will run when it has to create a table.
|
||||
|
||||
MySQL Migration: limitations
|
||||
----------------------------
|
||||
|
||||
|
||||
@ -346,16 +346,18 @@ ALTER TABLE NAMES MATCHING
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Introduce a comma separated list of table names or *regular expressions*
|
||||
that you want to target in the pgloader *ALTER TABLE* command. The only two
|
||||
available actions are *SET SCHEMA* and *RENAME TO*, both take a quoted
|
||||
string as parameter::
|
||||
that you want to target in the pgloader *ALTER TABLE* command. Available
|
||||
actions are *SET SCHEMA*, *RENAME TO*, and *SET*::
|
||||
|
||||
ALTER TABLE NAMES MATCHING ~/_list$/, 'sales_by_store', ~/sales_by/
|
||||
IN SCHEMA 'public'
|
||||
SET SCHEMA 'mv'
|
||||
|
||||
ALTER TABLE NAMES MATCHING 'film' RENAME TO 'films'
|
||||
ALTER TABLE NAMES MATCHING 'film' IN SCHEMA 'public' RENAME TO 'films'
|
||||
|
||||
ALTER TABLE NAMES MATCHING ~/./ SET (fillfactor='40')
|
||||
ALTER TABLE NAMES MATCHING ~/./ IN SCHEMA 'public' SET (fillfactor='40')
|
||||
|
||||
ALTER TABLE NAMES MATCHING ~/./ IN SCHEMA 'public' SET TABLESPACE 'pg_default'
|
||||
|
||||
You can use as many such rules as you need. The list of tables to be
|
||||
migrated is searched in pgloader memory against the *ALTER TABLE* matching
|
||||
@ -370,6 +372,9 @@ schema. In case of a name change, the mapping is kept and reused in the
|
||||
The *SET ()* action takes effect as a *WITH* clause for the `CREATE TABLE`
|
||||
command that pgloader will run when it has to create a table.
|
||||
|
||||
The *SET TABLESPACE* action takes effect as a *TABLESPACE* clause for the
|
||||
`CREATE TABLE` command that pgloader will run when it has to create a table.
|
||||
|
||||
PostgreSQL Migration: limitations
|
||||
---------------------------------
|
||||
|
||||
|
||||
@ -94,6 +94,7 @@
|
||||
#:table-oid
|
||||
#:table-comment
|
||||
#:table-storage-parameter-list
|
||||
#:table-tablespace
|
||||
#:table-field-list
|
||||
#:table-column-list
|
||||
#:table-index-list
|
||||
|
||||
@ -47,9 +47,14 @@
|
||||
(bind (((_ _ parameters _) stmt))
|
||||
(list #'pgloader.catalog::alter-table-set-storage-parameters parameters))))
|
||||
|
||||
(defrule set-tablespace (and kw-set kw-tablespace quoted-namestring)
|
||||
(:lambda (stmt)
|
||||
(list #'pgloader.catalog::alter-table-set-tablespace (third stmt))))
|
||||
|
||||
(defrule alter-table-action (or rename-to
|
||||
set-schema
|
||||
set-storage-parameters))
|
||||
set-storage-parameters
|
||||
set-tablespace))
|
||||
|
||||
(defrule alter-table-command (and alter-table-names-matching
|
||||
(? in-schema)
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
(def-keyword-rule "with")
|
||||
(def-keyword-rule "when")
|
||||
(def-keyword-rule "set")
|
||||
(def-keyword-rule "tablespace")
|
||||
(def-keyword-rule "database")
|
||||
(def-keyword-rule "messages")
|
||||
(def-keyword-rule "matches")
|
||||
|
||||
@ -92,6 +92,9 @@
|
||||
(alexandria:alist-plist
|
||||
(table-storage-parameter-list table))))
|
||||
|
||||
(when (table-tablespace table)
|
||||
(format s "~%TABLESPACE ~a" (table-tablespace table)))
|
||||
|
||||
(format s ";~%"))))
|
||||
|
||||
(defmethod format-drop-sql ((table table) &key (stream nil) cascade (if-exists t))
|
||||
|
||||
@ -75,6 +75,10 @@
|
||||
"Alter the storage parameters of TABLE."
|
||||
(setf (table-storage-parameter-list table) parameters))
|
||||
|
||||
(defun alter-table-set-tablespace (table tablespace)
|
||||
"Alter the tablespace slot of TABLE"
|
||||
(setf (table-tablespace table) tablespace))
|
||||
|
||||
|
||||
;;;
|
||||
;;; Apply the match rules as given by the parser to a table name.
|
||||
|
||||
@ -47,7 +47,8 @@
|
||||
(defstruct schema source-name name catalog in-search-path
|
||||
table-list view-list extension-list sqltype-list)
|
||||
|
||||
(defstruct table source-name name schema oid comment storage-parameter-list
|
||||
(defstruct table source-name name schema oid comment
|
||||
storage-parameter-list tablespace
|
||||
;; field is for SOURCE
|
||||
;; column is for TARGET
|
||||
;; citus is an extra slot for citus support
|
||||
|
||||
@ -9,6 +9,7 @@ load database
|
||||
quote identifiers
|
||||
|
||||
ALTER SCHEMA 'pgloader' RENAME TO 'mysql'
|
||||
ALTER TABLE NAMES MATCHING ~/./ SET TABLESPACE 'pg_default'
|
||||
|
||||
CAST column utilisateurs__Yvelines2013-06-28.sexe
|
||||
to text drop not null using empty-string-to-null,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user