Download the PHP package kalel1500/laravel-db-sync without Composer

On this page you can find all versions of the php package kalel1500/laravel-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-db-sync

Database Sync for Laravel

Total Downloads Latest Stable Version License

A Laravel package to safely synchronize tables and data from external databases into your application database.

This package is designed to pull data from other machines or systems (MySQL, PostgreSQL, Oracle, etc.) into a Laravel application in a controlled, traceable, and production-ready way, without forcing your final domain schema to match the source.

It focuses on data ingestion, not on how that data is later processed inside your application.


What this package does (and when to use it)

This package is useful when you need to:

It does not replace migrations or ORMs. It solves a very specific problem: bringing external data into your Laravel database safely and observably.


Installation

Install the package via Composer:

Publish and run the migrations:


Example usage

1. Define an external connection

In config/database.php:


2. Fill package tables

dbsync_connections

id source_connection target_connection
1 legacy_mysql mysql

dbsync_tables

id source_table target_table min_records active source_query use_temporal_table batch_size copy_strategy has_large_text_values_in_oracle primary_key unique_keys indexes connection_id
1 users users 300 true null true 1000 null false null null null 1
2 roles roles 100 true null false 500 null false null null null 1
2 types types 1 true null false 500 null false null null [["name", "slug"]] 1

Note on Composite Keys: The unique_keys and indexes fields must follow an "array of arrays" format: [["col1"], ["col2", "col3"]].


dbsync_columns

Example columns for users table:

id method parameters modifiers
1 id null null
2 string ["name"] ["nullable"]
3 string ["email", 50] ["nullable", "unique"]
4 boolean ["is_active"] [{"method": "default", "parameters": [true]}]
5 foreignId ["type_id"] [{"method": "constrained", "parameters": ["user_types"]}]

Note on modifiers: These can be arrays of strings or objects with the fields method and params if you need to pass parameters to the modifier. For example, passing the table name in the constrained modifier.

dbsync_column_table

Example users columns:

id table_id column_id order
1 1 1 1
2 1 2 2
2 1 3 3
2 1 4 4

3. Run the sync

Run all tables:

Run a specific connection:

Run a specific table:

Priority order when filtering:

  1. table
  2. connection

Synchronization strategies

Each table defines how it should be synchronized.

Drop & Recreate

Drops the destination table and recreates it. Downtime occurs during the data insertion phase.

Pros

Cons

Used when: dbsync_tables.use_temporal_table = false


Temporal Table (recommended for large tables)

Oracle Compatibility: This package automatically generates short, unique names (max 12 chars) for all indexes and constraints (e.g., unq_a1b2c3d4). This prevents naming collisions and "Identifier too long" errors during the rename process in Oracle.

Pros

Cons

Used when: dbsync_tables.use_temporal_table = true


Memory & Performance Optimization (copy Strategy)

The package uses streaming and chunk-based data processing instead of loading entire collections into memory. This allows synchronizing very large tables even in memory-constrained environments (e.g., Docker containers).

Depending on the table structure and configuration, the package automatically selects the most efficient strategy to read data from the source.

⚠️ If, when populating the package's databases, you find large tables without primary keys or auto-incrementing values, you should consider filling the dbsync_tables.copy_strategy field to improve loading performance.

Copy Execution Strategy

Data extraction is driven by a strategy system, which determines how rows are read from the source database.

The strategy is defined in the dbsync_tables.copy_strategy column as a JSON object:

Key Type Description
type string Execution strategy: chunkById, chunk, or cursor.
column string Column used for ordering/chunking (only required for chunk-based strategies)

Available Strategies

1. chunkById (Recommended)

2. chunk

3. cursor

Strategy Resolution (Default Behavior)

The copy_strategy field is fully optional and flexible. Both type and column can be omitted, partially defined, or fully specified.

Depending on what is provided, the package resolves the execution strategy using the following rules:

1. Explicit Strategy

If type is explicitly set to cursor, it is always used:

2. Fully Defined Chunk Strategy

If both type and column are provided, the package uses them directly:

⚠️ No validation is performed here — ensure the column is compatible with the selected strategy.

3. Automatic Resolution

If the configuration is partial or not defined, the package applies automatic resolution.

3.1 No configuration (null)

If copy_strategy is null, the system uses full auto-detection:

  1. Primary / Auto-increment / Unique keychunkById
  2. Fallbackcursor
3.2 Only type is defined
3.2.1 type = chunkById

The package attempts to resolve the best column using:

  1. Primary / auto-increment column
  2. Unique non-null column
  3. If none is found, it falls back to cursor
3.2.2 type = chunk

The package resolves a column using:

  1. Timestamp columns (e.g., created_at)
  2. First column of a composite primary key (if defined)
  3. First column in the table definition
3.2 Only column is defined

The package evaluates the column and determines the best strategy:

  • If the column is unique and non-nullchunkById
  • Otherwise → cursor
Summary
Configuration Result
{ "type": "cursor" } Always uses cursor
{ "type": "...", "column": "..." } Fully manual
null Auto (chunkByIdcursor)
{ "type": "chunkById" } Auto column for chunkById or fallback cursor
{ "type": "chunk" } Auto column for chunk
{ "column": "..." } Auto strategy based on column

Recommendation

When to Configure the Strategy Manually

In most cases, the automatic resolution works well. However, manual configuration is recommended in the following scenarios:


Column Sources & Virtual Columns (Advanced)

Each column can define where its value comes from using the source and source_config fields.

This allows you to mix:

source column

Defines the origin of the column value:

Value Description
table Value is read from the source database (default behavior)
virtual Value is generated during the sync process and not selected from the source

source_config column

Optional JSON field used when source = virtual.

Currently supported:

`

Example

method parameters source source_config
id null table null
string ["name"] table null
uuid ["virtual_id"] virtual null
uuid ["virtual_uuid"] virtual {"type": "uuid"}

Behavior

Important Notes

When to use this

Use virtual columns when:


Data Insertion Mode

By default, the package uses bulk inserts for maximum performance. This is the fastest and recommended approach in virtually all cases.

However, when synchronizing to Oracle, you might encounter specific errors if very large text values are present in text, mediumText, or longText columns.

To handle those edge cases, you can enable row-by-row insertion for a specific table using the has_large_text_values_in_oracle field in dbsync_tables.

Value Behavior
false (default) Uses bulk inserts (fastest option).
true Forces row-by-row insertion inside a transaction (safer but slower).

⚠️ This option should only be enabled if you experience Oracle errors during data insertion.

It is not recommended for normal usage because it reduces insertion performance.


Important Constraints

1. Self-Referencing Foreign Keys

The temporal_table strategy is not available if a table has self-referential foreign keys. For example, if the comments table has the foreign key comment_id.

2. Forbidden Methods in Columns

In dbsync_columns, the method field must only contain data types (string, integer, etc.).

3. Oracle Data Types and ORA-01790

When synchronizing to Oracle, you might encounter the following error during the data copy phase:

This happens when Laravel generates a bulk insert and Oracle internally interprets some values as CLOB while others are treated as VARCHAR2, typically when very large text values are involved.

If you are certain that:

Then you can enable row-by-row insertion for that specific table:

This forces each record to be inserted individually inside a transaction, ensuring proper bind variable handling and avoiding Oracle type mismatch issues.

⚠️ This setting should only be used when necessary, as it reduces insertion performance compared to bulk inserts.


Package tables and their meaning

dbsync_connections

Defines source and target Laravel connections.

Field Description Type Example
source_connection Connection name for the origin (string) oracle
target_connection Connection name for the destination (string) mysql
active Enables or disables this connection (bool) true

dbsync_tables

Defines what to sync and how.

Field Description Type Example
source_table Source table name (string) user
target_table Destination table name (string) user
min_records Minimum number of records required for the sync to be considered successful (int) 1
active Enables or disables synchronization for this table (bool) true
source_query Optional custom SELECT (string) select...
use_temporal_table Enables temporal strategy (bool) true
batch_size Insert chunk size (int) 500
copy_strategy Optional JSON to force a specific copy strategy. (int) {"type": "chunkById", "column": "id_user"}
has_large_text_values_in_oracle Forces row-by-row insertion instead of bulk (use only if needed, mainly for Oracle edge cases) (bool) false
primary_key * Primary key definition (array) ["user_id", "rol_id"]
unique_keys * Unique constraints (array) [["name", "type"]]
indexes * Index definitions (array) [["name", "description"]]
connection_id Reference to the connection used by this table (int) 1

The primary_key, unique_keys, and indexes fields are only required when using composite keys. Otherwise, they must be defined in the modifiers field of the dbsync_columns table.

IMPORTANT: The format of these fields (unique_keys, and indexes) is an "array of arrays". Otherwise, the execution will throw an error.


dbsync_columns

Defines table structure using Laravel schema semantics.

Field Description Type Example
method Blueprint method (string) string, integer, decimal, foreignId, etc.
parameters Method parameters (array) ["name", 100] || ["user_id"], etc.
modifiers Column modifiers (array) ["nullable", "unique"] || [{"method": "constrained", "parameters": ["user_id"]}], etc.
source Defines where the column value comes from (table or virtual) (string) table / virtual
source_config Optional JSON configuration for virtual columns (e.g. { "type": "uuid" }) (json) {"type":"uuid"}
self_referencing Indicates whether the foreign key references the table itself. For example, comment_id in comments. (bool) true
case_transform Optional transformation applied to the column value during sync. Accepts upper, lower, or any helper provided by the package. (string) upper | lower | _null_ifempty
code This column does nothing during synchronization. It's only there to help populate the dbsync_column_table table with IDs more easily. (string) user1

Available values for case_transform:

Value Behavior
upper Converts the value to uppercase using mb_strtoupper()
lower Converts the value to lowercase using mb_strtolower()
null_if_empty Converts empty strings to null (provided by this package's helper)

Any unrecognized value leaves the original data unchanged.


dbsync_column_table

Defines the relationship and ordering between tables and their columns.

This pivot table determines which columns belong to each synchronized table and in what order they are created.

Field Description
table_id Reference to the synchronized table (dbsync_tables)
column_id Reference to the column definition (dbsync_columns)
order Position of the column within the table schema definition

Logs and failure handling

dbsync_table_runs

Every execution is logged. You can monitor:

Key behaviors:

This makes the process safe for long-running and large imports.


Schema Utilities

This package provides a DbsyncSchema facade, allowing you to perform structural operations safely across different database engines by automatically handling foreign key constraints and driver-specific behaviors.

Basic Usage

Working with Connections

If you are working with multiple databases, you can switch the connection fluently:

Important Note on Truncate & Foreign Keys

When truncating tables with active relationships, you must include all related tables in the same array.

The truncate method disables foreign key constraints before the process and re-enables them after all specified tables have been cleared. If you truncate a child table but leave data in the parent table (or vice-versa), the database will throw an error when re-enabling constraints due to referential integrity violations.

Supported Methods

Method Description
forceDrop(string $table) Drops the table ignoring integrity constraints. It uses CASCADE CONSTRAINTS in Oracle, CASCADE in PostgreSQL, and manual foreign key cleanup in SQL Server.
truncate(array $tables) Vacuums the specified tables and resets identity counters. It manages the disabling/enabling of constraints globally for the provided set of tables.
connection(string\|Connection $connection) Sets the database connection for the subsequent operations.

Driver Compatibility

The package is currently in Beta. While the logic is implemented for all major drivers, the level of testing varies:

Driver Status Notes
MySQL / MariaDB ✅ Tested Fully functional.
SQLite ✅ Tested Fully functional.
Oracle (12c+) ✅ Tested Verified using Identity Columns (standard since 12c).
PostgreSQL ⚠️ Beta Logic implemented but pending full integration tests.
SQL Server ⚠️ Beta Logic implemented but pending full integration tests.

Beta Disclaimer: While the core logic is implemented for all drivers, please proceed with caution when using this package in production environments with Postgres or SQL Server, as they are still undergoing full verification. We highly encourage testing in these environments! If you encounter any issues or wish to contribute, please open an issue or submit a PR.


License

laravel-db-sync is an open-sourced software licensed under the MPL-2.0.


All versions of laravel-db-sync with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
ext-pdo Version *
php Version ^8.2
laravel/framework Version ^11.0|^12.0
kalel1500/kalion Version >=v0.55.0-beta.1
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 kalel1500/laravel-db-sync contains the following files

Loading the files please wait ...