17. The miraj-migrate migration tool
miraj-migrate copies an existing SQL database (schema, views and rows) to a running MIRAJ server. It reads the source in read-only mode over the network protocol: the source is neither stopped nor modified, so the tool can be rerun as many times as needed before the cutover.
17.1 General syntax#
miraj-migrate inspect --source-db <database> [source options]
miraj-migrate run --source-db <database> [source and target options]
[--drop-existing] [--skip-data] [--batch-rows <n>] [--only t1,t2]
miraj-migrate --helpExit codes:
| Code | Meaning |
|---|---|
0 | Success: everything is migrated and verified |
1 | Error (invalid option, connection impossible, unknown source database) or at least one object failed |
17.2 Commands#
| Command | Effect |
|---|---|
inspect | Lists the tables of the source database with their row counts, the views, then the objects that will not be migrated (triggers, routines, events). Writes nothing. Run it first to assess the scope of the work. |
run | Creates the target database if it does not exist, recreates the tables then the views in it, copies the rows and verifies each table. |
17.3 Options#
Source
| Option | Description | Default |
|---|---|---|
--source-db <database> | Database to migrate (required). | — |
--source-host <host> | Source server host. | 127.0.0.1 |
--source-port <port> | Source server port. | 3306 |
--source-user <account> | Read account. | root |
--source-password <password> | Account password. May also come from the MIRAJ_SOURCE_PASSWORD environment variable. | none |
Target (MIRAJ server)
| Option | Description | Default |
|---|---|---|
--host <host> | MIRAJ server host. | 127.0.0.1 |
--port <port> | MIRAJ server port. | 7007 |
--user <account> | Account to use (rights to create databases and tables). | root |
--password <password> | Password. May also come from MIRAJ_PASSWORD. | none |
--db <database> | Database created on the MIRAJ server. | name of the source database |
Behavior of run
| Option | Description |
|---|---|
--drop-existing | First drops the tables and views of the same name on the target. Without this option, a table that already exists is a failure (error 1050) and is left untouched. |
--skip-data | Recreates only the schema, without copying rows. |
--only t1,t2 | Migrates only the named tables and views (comma-separated names, case ignored). |
--batch-rows <n> | Maximum number of rows per INSERT (default 500; an INSERT is also cut at 1 MiB of SQL). |
On the command line, a password is visible in the process list: prefer environment variables for production use.
17.4 How a migration proceeds#
- Connection to the source and to the target (both in full UTF-8, emoji included); creation of the target database if necessary.
- For each table: reading of its definition on the source, creation on the target (with
--drop-existing, prior deletion), then copy of the rows by multi-rowINSERT. - Verification: the source row count, the count of rows read and the target row count must be identical.
- For each view: creation on the target, then a check read (
SELECT … LIMIT 1). The sourceDEFINERaccount is removed, as it generally does not exist on the target. - Summary: number of tables migrated, list of failures, list of objects to be handled by hand.
Tables are processed one after another; a failure on one table does not stop the following ones. Foreign key constraints are recreated with the table; the copy is done without checking the order between tables, since the source has already guaranteed consistency.
Example:
> miraj-migrate inspect --source-db gestion --source-host 10.0.0.5 --source-user lecture
Base source « gestion » ([email protected]:3306) : 2 table(s), 1 vue(s)
table clients 3001 ligne(s)
table lignes 15005 ligne(s)
vue v_soldes
Total : 18006 ligne(s)
> miraj-migrate run --source-db gestion --source-host 10.0.0.5 --source-user lecture --drop-existing
Migration de « gestion » ([email protected]:3306) vers « gestion » ([email protected]:7007)
table clients 3001 ligne(s) copiée(s), vérifiée(s)
table lignes 15005 ligne(s) copiée(s), vérifiée(s)
vue v_soldes créée
Bilan : 2 table(s) migrée(s), 0 échec(s)17.5 What is not migrated#
- Triggers, stored routines and events: they are only listed (« À reprendre manuellement », i.e. "to be redone manually"). Their body depends on the source dialect and must be reviewed, then recreated with MIRAJ SQL (chapters 5 and 6).
- Accounts and privileges: to be recreated with
CREATE USERandGRANT(chapter 10). - Concurrent writes: the copy is not a snapshot. For a database still in use, suspend writes during
run, or rerunrun --drop-existingjust before the cutover. - Content: verification compares row counts, not values. For a stronger check, compare aggregates or a per-table fingerprint on both servers.
Table definitions are replayed as the source provides them: a clause that MIRAJ rejects appears as a failure for that table, with the error message of the MIRAJ server (chapter 15).
17.6 Common error messages#
| Message | Cause |
|---|---|
--source-db est obligatoire | Source database not specified. |
connexion source (…) impossible / connexion cible (…) impossible | Incorrect host, port or account, or server stopped. |
base source « x » : erreur SQL 1049 | The source database does not exist. |
création : erreur SQL 1050 | The table already exists on the target: add --drop-existing. |
nombre de lignes : source …, lues …, cible … | Mismatches after copy: check the server log (--log) and rerun. |
vue créée mais illisible | The view references an object missing from the target (failed table, function not ported). |