mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-04 18:36:12 +02:00
Allow ALTER SCHEMA command for MySQL.
This pgloader command allows to migrate tables while changing the schema they are found into in between their MySQL source database and their PostgreSQL target database. This changes the default behavior of pgloader with MySQL from always targetting the 'public' schema to targetting by default a schema named the same as the MySQL database. You can revert to the old behavior by adding a rule: ALTER SCHEMA 'dbname' RENAME TO 'public We might want to add a patch to re-install the default behavior later. Also see #489 where it used not to be possible to rename the schema at migration time, causing strange errors (you need to spot NIL as the schema name in the "failed to find target table" messages.
This commit is contained in:
parent
bdaacae3e7
commit
4931604361
@ -68,6 +68,7 @@
|
||||
gucs
|
||||
casts
|
||||
alter-table
|
||||
alter-schema
|
||||
materialize-views
|
||||
including-matching
|
||||
excluding-matching
|
||||
@ -139,7 +140,7 @@
|
||||
(defun lisp-code-for-loading-from-mysql (my-db-conn pg-db-conn
|
||||
&key
|
||||
gucs casts views before after options
|
||||
alter-table
|
||||
alter-table alter-schema
|
||||
((:including incl))
|
||||
((:excluding excl))
|
||||
((:decoding decoding-as)))
|
||||
@ -162,6 +163,7 @@
|
||||
:excluding ',excl
|
||||
:materialize-views ',views
|
||||
:alter-table ',alter-table
|
||||
:alter-schema ',alter-schema
|
||||
:set-table-oids t
|
||||
,@(remove-batch-control-option options))
|
||||
|
||||
@ -172,8 +174,9 @@
|
||||
(destructuring-bind (my-db-uri
|
||||
pg-db-uri
|
||||
&key
|
||||
gucs casts views before after
|
||||
options alter-table including excluding decoding)
|
||||
gucs casts views before after options
|
||||
alter-table alter-schema
|
||||
including excluding decoding)
|
||||
source
|
||||
(cond (*dry-run*
|
||||
(lisp-code-for-mysql-dry-run my-db-uri pg-db-uri))
|
||||
@ -186,6 +189,7 @@
|
||||
:after after
|
||||
:options options
|
||||
:alter-table alter-table
|
||||
:alter-schema alter-schema
|
||||
:including including
|
||||
:excluding excluding
|
||||
:decoding decoding))))))
|
||||
|
||||
@ -82,7 +82,7 @@
|
||||
including
|
||||
excluding)
|
||||
"MySQL introspection to prepare the migration."
|
||||
(let ((schema (add-schema catalog nil))
|
||||
(let ((schema (add-schema catalog (catalog-name catalog)))
|
||||
(view-names (unless (eq :all materialize-views)
|
||||
(mapcar #'car materialize-views))))
|
||||
(with-stats-collection ("fetch meta data"
|
||||
|
||||
@ -34,11 +34,14 @@ load database
|
||||
ALTER TABLE NAMES MATCHING 'sales_by_store' RENAME TO 'sales_by_store_list'
|
||||
ALTER TABLE NAMES MATCHING 'film' RENAME TO 'films'
|
||||
|
||||
ALTER SCHEMA 'sakila' RENAME TO 'pagila'
|
||||
|
||||
-- INCLUDING ONLY TABLE NAMES MATCHING ~/film/, 'actor'
|
||||
EXCLUDING TABLE NAMES MATCHING ~<ory>
|
||||
EXCLUDING TABLE NAMES MATCHING ~<ory> ;
|
||||
|
||||
BEFORE LOAD DO
|
||||
$$ create schema if not exists sakila; $$,
|
||||
$$ create schema if not exists mv; $$,
|
||||
$$ alter database sakila set search_path to sakila, mv, public; $$;
|
||||
|
||||
-- BEFORE LOAD DO
|
||||
-- $$ create schema if not exists sakila; $$,
|
||||
-- $$ create schema if not exists mv; $$,
|
||||
-- $$ alter database sakila set search_path to sakila, mv, public; $$
|
||||
|
||||
|
||||
@ -8,7 +8,8 @@ load database
|
||||
-- WITH batch rows = 10000
|
||||
|
||||
WITH concurrency = 1, workers = 6,
|
||||
max parallel create index = 4
|
||||
max parallel create index = 4-- ,
|
||||
-- quote identifiers
|
||||
|
||||
SET maintenance_work_mem to '128MB',
|
||||
work_mem to '12MB',
|
||||
@ -29,11 +30,13 @@ load database
|
||||
ALTER TABLE NAMES MATCHING 'sales_by_store' RENAME TO 'sales_by_store_list'
|
||||
ALTER TABLE NAMES MATCHING 'film' RENAME TO 'films'
|
||||
|
||||
ALTER SCHEMA 'sakila' RENAME TO 'pagila'
|
||||
|
||||
-- INCLUDING ONLY TABLE NAMES MATCHING ~/film/, 'actor'
|
||||
-- EXCLUDING TABLE NAMES MATCHING ~<ory>
|
||||
|
||||
BEFORE LOAD DO
|
||||
$$ create schema if not exists sakila; $$,
|
||||
$$ create schema if not exists pagila; $$,
|
||||
$$ create schema if not exists mv; $$,
|
||||
$$ alter database sakila set search_path to sakila, mv, public; $$;
|
||||
$$ alter database sakila set search_path to pagila, mv, public; $$;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user