Download the PHP package artemyurov/laravel-incremental-db-sync without Composer

On this page you can find all versions of the php package artemyurov/laravel-incremental-db-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-incremental-db-sync

Laravel Incremental DB Sync

Laravel package for incremental PostgreSQL database synchronization from remote servers via SSH tunnel.

Supports incremental sync, full refresh (DROP + CREATE), automatic backups, foreign key dependency resolution, and self-referencing table handling.

Requirements

Installation

Publish the configuration file:

Configuration

The configuration file config/db-sync.php defines sync connections:

Each connection defines:

Key Description
tunnel SSH tunnel name from config/tunnel.php (laravel-autossh-tunnel)
source Remote database credentials (driver, database, username, password)
target Local database connection name from config/database.php
excluded_tables Tables to skip during synchronization

You can define multiple connections (e.g. production, staging) and switch between them using the --sync-connection option.

Commands

db-sync:pull — Incremental Synchronization

Analyzes differences between remote and local databases, then applies only the changes (DELETE + UPSERT).

Features:

Index/constraint reconciliation. pull's structure detection compares columns only, so index/constraint changes (including renames) would otherwise be invisible. Each run performs a dedicated reconciliation pass: it compares indexes and constraints of every table (by name) between remote and local and brings local in line — constraint-aware (PRIMARY KEY / UNIQUE / EXCLUSION via ALTER TABLE, plain indexes via CREATE/DROP INDEX), applying all drops before all creates so renamed objects don't collide. Excluded tables are skipped. Removed objects are reported afterwards. Note: pull never drops local-only tables (it preserves work in progress), but it does drop indexes/constraints that exist locally and not on remote — including a locally-added index from a not-yet-pushed migration. DDL is owned by migrations; this pass only keeps index/constraint metadata in sync.

Options:

Option Description
--sync-connection= Connection name from config (default: production)
--tables= Sync only specified tables (comma-separated)
--exclude= Exclude specified tables (comma-separated)
--views= Sync only specified views (comma-separated)
--include-excluded Include normally excluded tables
--analyze-only Only show analysis, don't sync
--dry-run Show plan without executing
--skip-backup Skip automatic backup
--skip-sequences Skip sequence reset
--batch-size= Records per batch (overrides config db-sync.batch_size / DB_SYNC_BATCH_SIZE, default 10000)
--memory-limit=-1 Memory limit in MB
--force Skip confirmation prompt

db-sync:clone — Full Clone

Drops all tables and recreates them from the remote server. Use this for a clean start.

Local-only tables. clone mirrors the remote schema, so tables that exist locally but not on remote (e.g. leftovers from an interrupted run, or a renamed table whose old index name lingers) must be removed first — otherwise their index and constraint names collide with recreated tables (SQLSTATE[42P07] ... already exists). Such local-only tables are listed in the plan (with row counts) alongside the tables to refresh, and are dropped as part of the single confirmation prompt (no separate question). Pass --keep-local-tables to keep them (only safe when their names don't clash with remote objects).

Options:

Option Description
--sync-connection= Connection name from config
--tables= Refresh only specified tables (comma-separated)
--exclude= Exclude specified tables (comma-separated)
--views= Refresh only specified views (comma-separated)
--include-excluded Include normally excluded tables
--dry-run Show plan without executing
--skip-views Skip view synchronization
--skip-backup Skip automatic backup
--skip-sync-data Refresh structure only, no data
--keep-local-tables Do not drop local-only tables (tables not present on remote)
--batch-size= Records per batch (overrides config db-sync.batch_size / DB_SYNC_BATCH_SIZE, default 10000)
--memory-limit=-1 Memory limit in MB
--force Skip confirmation prompt (and drop local-only tables without asking)

db-sync:restore — Restore from Backup

Restore local database from a previously created backup.

Options:

Option Description
--sync-connection= Connection name from config
--list Only show available backups
--force Skip confirmation prompt

How It Works

Incremental Sync (db-sync:pull)

  1. Opens SSH tunnel to the remote server
  2. Creates a local backup
  3. Analyzes each table: compares row counts, max IDs, and updated_at timestamps
  4. Detects tables with changed structure (columns added/removed/modified)
  5. Rebuilds changed tables (DROP + CREATE + import data)
  6. Reconciles indexes/constraints to match remote (constraint-aware; all drops then all creates)
  7. For unchanged structure: runs DELETE phase (removes records missing from remote), then UPSERT phase (inserts new / updates modified records)
  8. CASCADE RECHECK: if parent table had deletions, re-checks child tables
  9. Syncs views and resets auto-increment sequences

Full Clone (db-sync:clone)

  1. Opens SSH tunnel to the remote server
  2. Shows the refresh plan, including local-only tables (not on remote) to be dropped, and asks for a single confirmation
  3. Creates a local backup
  4. Drops local-only tables (skipped with --keep-local-tables)
  5. Dumps schema from remote using pg_dump
  6. Drops all local tables and recreates from dump
  7. Copies data from remote with keyset pagination (by primary key) + bulk INSERT; a failed batch falls back to row-by-row inserts. Tables without a primary key are skipped (they cannot be paginated or de-duplicated reliably) and reported at the end.
  8. Resets sequences

Foreign Key Handling

The package builds a dependency graph from foreign key constraints and uses topological sorting to determine the correct order for:

Self-referencing tables (e.g. categories with parent_id) are handled via recursive CTEs.

Architecture

The package uses an adapter pattern for database operations:

Key services:

Service Responsibility
DependencyGraph FK dependency analysis, topological sorting
DataSyncer Batch INSERT/UPSERT/DELETE operations
SchemaManager Schema dump/restore, structure comparison
BackupManager Backup creation, restore, cleanup

Docker & DDEV

This package requires SSH tunnels to work. For Docker and DDEV setup (SSH agent forwarding, autossh installation), see the Docker & DDEV section in laravel-autossh-tunnel documentation.

Add postgresql-client to your Dockerfile for schema operations (pg_dump, psql).

Important: The pg_dump version must be >= the PostgreSQL server version. Debian base images ship with older versions (e.g. Bookworm includes PG 15), so you may need the official PostgreSQL APT repository:

Adding Database Drivers

To support a new database (e.g. MySQL), implement DatabaseAdapterInterface and register it in BaseDbSyncCommand::resolveAdapter().

License

MIT


All versions of laravel-incremental-db-sync with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/config Version ^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
artemyurov/laravel-autossh-tunnel Version ^0.5.0|^0.6.0
symfony/process Version ^6.0|^7.0|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package artemyurov/laravel-incremental-db-sync contains the following files

Loading the files please wait ...