diff --git a/docs/ref/mssql.rst b/docs/ref/mssql.rst index 7797abf..ed024c2 100644 --- a/docs/ref/mssql.rst +++ b/docs/ref/mssql.rst @@ -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. diff --git a/docs/ref/mysql.rst b/docs/ref/mysql.rst index 5b83759..e54b42b 100644 --- a/docs/ref/mysql.rst +++ b/docs/ref/mysql.rst @@ -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 ---------------------------- diff --git a/docs/ref/pgsql.rst b/docs/ref/pgsql.rst index 53e9dcb..06dd406 100644 --- a/docs/ref/pgsql.rst +++ b/docs/ref/pgsql.rst @@ -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 --------------------------------- diff --git a/src/package.lisp b/src/package.lisp index c6eda82..0de7e96 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -94,6 +94,7 @@ #:table-oid #:table-comment #:table-storage-parameter-list + #:table-tablespace #:table-field-list #:table-column-list #:table-index-list diff --git a/src/parsers/command-alter-table.lisp b/src/parsers/command-alter-table.lisp index 3e11c7a..b10479b 100644 --- a/src/parsers/command-alter-table.lisp +++ b/src/parsers/command-alter-table.lisp @@ -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) diff --git a/src/parsers/command-keywords.lisp b/src/parsers/command-keywords.lisp index 9a4dcea..84d8bb3 100644 --- a/src/parsers/command-keywords.lisp +++ b/src/parsers/command-keywords.lisp @@ -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") diff --git a/src/pgsql/pgsql-ddl.lisp b/src/pgsql/pgsql-ddl.lisp index 662bc95..03e8962 100644 --- a/src/pgsql/pgsql-ddl.lisp +++ b/src/pgsql/pgsql-ddl.lisp @@ -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)) diff --git a/src/utils/alter-table.lisp b/src/utils/alter-table.lisp index 56536e4..c5da02b 100644 --- a/src/utils/alter-table.lisp +++ b/src/utils/alter-table.lisp @@ -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. diff --git a/src/utils/catalog.lisp b/src/utils/catalog.lisp index 6c3ca3a..8489394 100644 --- a/src/utils/catalog.lisp +++ b/src/utils/catalog.lisp @@ -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 diff --git a/test/mysql/my.load b/test/mysql/my.load index 3ac8806..158ed95 100644 --- a/test/mysql/my.load +++ b/test/mysql/my.load @@ -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,