PHPackages                             mb4it/laravel-dbtodb-migration - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mb4it/laravel-dbtodb-migration

ActiveLibrary[Database &amp; ORM](/categories/database)

mb4it/laravel-dbtodb-migration
==============================

Laravel artisan command to migrate data between database connections (1 source → N targets) with configurable table/column mapping, chunking, and optional profiling logs.

1.0.0(1mo ago)011↑990.9%[1 PRs](https://github.com/Dictator90/laravel-dbtodb-migration/pulls)MITPHPPHP ^8.2

Since Apr 7Pushed 3d agoCompare

[ Source](https://github.com/Dictator90/laravel-dbtodb-migration)[ Packagist](https://packagist.org/packages/mb4it/laravel-dbtodb-migration)[ RSS](/packages/mb4it-laravel-dbtodb-migration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (2)Used By (0)

mb4it/laravel-dbtodb-migration
==============================

[](#mb4itlaravel-dbtodb-migration)

English | [Русский](README.ru.md)

Laravel 12 package: an Artisan command that copies rows from one configured database connection to one or more target tables on another connection. Runs are driven by named migrations in `config/dbtodb_mapping.php`, with chunked reads, optional keyset pagination, per-target column maps and transforms, filters, upsert vs insert, strict validation, JSON reports, and optional profiling logs.

Requirements
------------

[](#requirements)

- PHP `^8.2`
- Laravel `^12.0`

Installation
------------

[](#installation)

```
composer require mb4it/laravel-dbtodb-migration
php artisan vendor:publish --tag=dbtodb-migration-config
```

Define the database connections referenced by your migrations in `config/database.php`.

Supported target drivers
------------------------

[](#supported-target-drivers)

Target-table metadata resolution, required-column validation, and automatic primary-key detection are supported for these Laravel target connection drivers:

- `sqlite`
- `pgsql`
- `mysql`
- `mariadb`
- `sqlsrv`

Table prefixes configured on the target connection are honored when reading target metadata.

Quick start
-----------

[](#quick-start)

Use this path when you only need to copy a few columns from one source table into one target table. The command uses `migrations.default` when `--migration` is omitted, so a simple run does not need `--source` or `--target` once the migration defines them.

1. Install and publish the package config:

    ```
    composer require mb4it/laravel-dbtodb-migration
    php artisan vendor:publish --tag=dbtodb-migration-config
    ```
2. Add the source and target Laravel database connections in `config/database.php` (for example `legacy_mysql` and `pgsql_app`).
3. Edit `config/dbtodb_mapping.php` and replace the published example with a `default` migration:

    ```
    return [
        'migrations' => [
            'default' => [
                'source' => 'legacy_mysql',
                'target' => 'pgsql_app',

                'tables' => [
                    // source table => target table => source column => target column
                    'legacy_users' => [
                        'users' => [
                            'id' => 'id',
                            'email' => 'email',
                        ],
                    ],
                ],
            ],
        ],
    ];
    ```
4. Run a safe validation pass first. `--dry-run` reads data, applies filters/transforms, validates target columns in strict mode, and writes only the JSON report:

    ```
    php artisan db:to-db --dry-run
    ```
5. If the report looks correct, run the migration for real:

    ```
    php artisan db:to-db
    ```
6. For production-sized data, prefer adding `keyset_column` and an explicit `chunk` size in the full table syntax below.

Documentation coverage and safety notes
---------------------------------------

[](#documentation-coverage-and-safety-notes)

This README documents the public configuration surface for the current migration-centric format: installation, supported drivers, quick start, named migrations, ordered steps, CLI options, runtime/memory settings, automatic target-type transforms, profile logging, sequence synchronization, filters, column transforms, fan-out/fan-in routing, and edge-case behavior. Before running against production data, review the target schema, run `--dry-run`, keep `strict` enabled unless you intentionally want looser validation, and store the generated JSON report for audit/debugging.

The package no longer accepts the older top-level `tables` / `columns` / `filters` config shape; use `migrations.` for every run.

Complete complex config example
-------------------------------

[](#complete-complex-config-example)

The example below shows a production-oriented `config/dbtodb_mapping.php` with global runtime defaults, auto transforms, ordered steps, source SQL filters, target routing filters, transforms, deduplication, mixed write operations, and sequence synchronization. It assumes that the Laravel connections `legacy_mysql` and `pgsql_app` already exist in `config/database.php`, and that target tables/columns match the mapped payloads.

```
