mrbohem/larasync

Laravel Database Sync with UI dashboard

Fund package maintenance!
MrBohem

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/mrbohem/larasync

v1.4.0 2026-02-22 06:35 UTC

This package is auto-updated.

Last update: 2026-02-22 06:37:30 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Larasync is a Laravel package that lets you compare and sync data between two databases through a beautiful Livewire-powered web dashboard. Connect any combination of SQLite, MySQL, or PostgreSQL databases, see a side-by-side row-count comparison for every table, and sync individual tables or all tables at once โ€” right from your browser.

โœจ Features

  • ๐Ÿ”Œ Connect any two databases โ€” SQLite, MySQL, or PostgreSQL
  • ๐Ÿ“Š Side-by-side table comparison โ€” row counts, diff, and sync status at a glance
  • ๐Ÿ”„ One-click sync โ€” sync a single table or all tables sequentially
  • โ†”๏ธ Bi-directional sync โ€” choose DB1 โ†’ DB2 or DB2 โ†’ DB1
  • ๐Ÿท๏ธ Auto-labeling โ€” databases are auto-detected as Local or Cloud
  • ๐Ÿšซ Ignored tables โ€” exclude tables (e.g. sessions, telescope_*) from comparison & sync
  • ๐Ÿ–ฅ๏ธ Beautiful Livewire dashboard โ€” real-time progress, logs, and status indicators
  • โš™๏ธ Zero config needed โ€” works out of the box with .env variables

๐Ÿ“‹ Requirements

  • PHP โ‰ฅ 8.3
  • Laravel 11.x or 12.x
  • Livewire 3.6+

๐Ÿš€ Installation

1. Install the package via Composer

composer require mrbohem/larasync --dev

2. (Optional) Publish the config file

php artisan vendor:publish --tag="larasync-config"

This creates config/larasync.php where you configure your two database connections and ignored tables.

3. (Optional) Publish the views

If you want to customize the dashboard UI:

php artisan vendor:publish --tag="larasync-views"

โš™๏ธ Configuration

After publishing, open config/larasync.php and configure your two databases. You can set values directly or use .env variables:

Config File

return [
    'db1' => [
        'driver'   => env('LARASYNC_DB1_DRIVER', 'sqlite'),
        'host'     => env('LARASYNC_DB1_HOST'),
        'port'     => env('LARASYNC_DB1_PORT', '3306'),
        'database' => env('LARASYNC_DB1_DATABASE'),
        'username' => env('LARASYNC_DB1_USERNAME'),
        'password' => env('LARASYNC_DB1_PASSWORD', ''),
    ],

    'db2' => [
        'driver'   => env('LARASYNC_DB2_DRIVER', 'mysql'),
        'host'     => env('LARASYNC_DB2_HOST'),
        'port'     => env('LARASYNC_DB2_PORT', '3306'),
        'database' => env('LARASYNC_DB2_DATABASE'),
        'username' => env('LARASYNC_DB2_USERNAME'),
        'password' => env('LARASYNC_DB2_PASSWORD', ''),
    ],

    'ignored_tables' => [
        'sessions',
        'telescope_entries_tags',
        'telescope_entries',
        'telescope_monitoring',
        'pulse_entries',
        'pulse_values',
        'pulse_aggregates',
    ],
];

.env Example

# โ”€โ”€ Database 1 (e.g. local SQLite) โ”€โ”€
LARASYNC_DB1_DRIVER=sqlite
LARASYNC_DB1_DATABASE=database.sqlite

# โ”€โ”€ Database 2 (e.g. remote MySQL) โ”€โ”€
LARASYNC_DB2_DRIVER=mysql
LARASYNC_DB2_HOST=your-cloud-db-host.com
LARASYNC_DB2_PORT=3306
LARASYNC_DB2_DATABASE=your_database
LARASYNC_DB2_USERNAME=your_username
LARASYNC_DB2_PASSWORD=your_password

Note: For SQLite, the database value is resolved relative to Laravel's database_path() (i.e. the database/ directory).

๐Ÿ–ฅ๏ธ Usage

Access the Dashboard

Once installed, visit the sync dashboard in your browser:

https://your-app.test/sync-db

The route is automatically registered by the package at /sync-db.

Dashboard Workflow

  1. Configure connections โ€” Enter or verify the credentials for DB1 and DB2 (pre-filled from config)
  2. Test connections โ€” Click the test button for each database to verify connectivity
  3. Compare โ€” Hit "Compare" to see a table-by-table row-count comparison
  4. Choose sync direction โ€” Select DB1 โ†’ DB2 or DB2 โ†’ DB1
  5. Sync โ€” Sync individual tables with one click, or use "Sync All" to sync every table sequentially

Supported Drivers

Driver Value Notes
SQLite sqlite Always treated as Local
MySQL mysql Local or Cloud auto-detected
PostgreSQL pgsql Local or Cloud auto-detected

Ignoring Tables

Add table names to the ignored_tables array in config/larasync.php to exclude them from comparison and sync:

'ignored_tables' => [
    'sessions',
    'telescope_entries',
    'jobs',
    'failed_jobs',
    // add your tables here...
],

โš ๏ธ Important Notes

  • Sync is destructive โ€” Syncing a table will truncate the target table and replace all its data with the source table's data. Always back up your databases before syncing.
  • Foreign key constraints are temporarily disabled during sync to avoid constraint violations.
  • Large tables are synced in chunks of 500 rows for efficiency.
  • The dashboard route (/sync-db) uses the web middleware by default. You may want to add authentication middleware in production โ€” see Protecting the Dashboard.

๐Ÿ”’ Protecting the Dashboard

The /sync-db route uses only the web middleware by default. In production, you should protect it with authentication. You can do this by adding middleware in your app's route service provider or by overriding the package route:

// In routes/web.php
use MrBohem\Larasync\Http\Livewire\SyncDashboard;

Route::get('sync-db', SyncDashboard::class)
    ->middleware(['web', 'auth', 'admin'])  // add your middleware
    ->name('larasync.dashboard');

๐Ÿงช Testing

composer test

๐Ÿ‘ค Credits

๐Ÿ“„ License

The MIT License (MIT). Please see License File for more information.