PHPackages                             merakilab/meraki-data-safety - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. merakilab/meraki-data-safety

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

merakilab/meraki-data-safety
============================

Data backup &amp; restore safety layer for Laravel migrations

v1.0.2(6mo ago)00MITPHPPHP ^8.2

Since Jan 4Pushed 6mo agoCompare

[ Source](https://github.com/meraki-labs/meraki-data-safety)[ Packagist](https://packagist.org/packages/merakilab/meraki-data-safety)[ RSS](/packages/merakilab-meraki-data-safety/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (4)Used By (0)

Meraki Data Safety
------------------

[](#meraki-data-safety)

### Purpose

[](#purpose)

Meraki Data Safety helps you safely manage data across Laravel migrations by providing backup, restore, and cleanup operations.

### Installation

[](#installation)

```
composer require merakilab/meraki-data-safety

```

### Configuration

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --tag=meraki-data-safety-config

```

Environment variables:

```
MERAKI_DATA_SAFETY_ENABLED=true
MERAKI_DATA_SAFETY_DISK=local
MERAKI_DATA_SAFETY_PATH=meraki/data-safety
MERAKI_DATA_SAFETY_BACKUP_CHUNK=1000
MERAKI_DATA_SAFETY_RESTORE_CHUNK=500
```

### Backup / restore a full table before migration down

[](#backup--restore-a-full-table-before-migration-down)

```
use Meraki\Packages\DataSafety\Traits\MigrationDataSafety;

return new class extends Migration {
    use MigrationDataSafety;

    const BACKUP_VERSION = '2026_01_03';

    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('table_name', function (Blueprint $table) {
            $table->id();
            $table->string('col1');
            $table->timestamps();
        });

        // Sync data backup to the table (if exists)
        $this->restoreTable('table_name', ['id'], self::BACKUP_VERSION);

        // Clean up backup file after successful restore
        $this->cleanupTable('table_name', self::BACKUP_VERSION);

        // With pgsql you need to update the index for autoincrement column
        DB::statement("SELECT setval('table_name_id_seq', (SELECT MAX(id) FROM table_name))");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Backup before drop table
        $this->backupTable('table_name', ['id'], self::BACKUP_VERSION);

        Schema::dropIfExists('table_name');
    }
};
```

### Backup / restore data from specific columns

[](#backup--restore-data-from-specific-columns)

```
use Meraki\Packages\DataSafety\Traits\MigrationDataSafety;

return new class extends Migration {
    use MigrationDataSafety;

    const BACKUP_VERSION = '2026_01_04_1754';

    /**
     * Run the migrations.
     */
    public function up(): void
    {
        DB::transaction(function () {
            if (!Schema::hasColumns('table_name', ['col2', 'col3'])) {
                Schema::table('table_name', function (Blueprint $table) {
                    $table->enum('col2', ['val1', 'val2'])->default("val1");
                    $table->string('col3')->nullable();
                });
                $this->restoreColumns('table_name', ['col2', 'col3'], ['id'], self::BACKUP_VERSION);
                $this->cleanupColumns('table_name', ['col2', 'col3'], self::BACKUP_VERSION);
            }

            if (!Schema::hasColumns('table_name', ['col1'])) {
                $this->backupColumns('table_name', ['col1'], ['id'], self::BACKUP_VERSION);
                Schema::table('table_name', function (Blueprint $table) {
                    $table->dropColumn('col1');
                });
            }
        }, attempts: 5);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        if (Schema::hasColumns('table_name', ['col2', 'col3'])) {
            $this->backupColumns('table_name', ['col2', 'col3'], ['id'], self::BACKUP_VERSION);
            Schema::table('table_name', function (Blueprint $table) {
                $table->dropColumn(['col2', 'col3']);
            });
        }

        if (!Schema::hasColumns('table_name', ['col1'])) {
            Schema::table('table_name', function (Blueprint $table) {
                $table->date('col1');
            });
            $this->restoreColumns('table_name', ['col1'], ['id'], self::BACKUP_VERSION);
            $this->cleanupColumns('table_name', ['col1'], self::BACKUP_VERSION);
        }
    }
};
```

### Using the Facade

[](#using-the-facade)

You can use the `DataSafety` facade outside of a migration context:

```
use Meraki\Packages\DataSafety\Facades\DataSafety;

// Backup a full table
DataSafety::backupTable('users', ['id'], '2026_06_18');

// Backup specific columns
DataSafety::backupColumns('users', ['email', 'name'], ['id'], '2026_06_18');

// Restore a full table
DataSafety::restoreTable('users', ['id'], '2026_06_18');

// Restore specific columns
DataSafety::restoreColumns('users', ['email', 'name'], ['id'], '2026_06_18');

// Cleanup after restore
DataSafety::cleanupTable('users', '2026_06_18');
DataSafety::cleanupColumns('users', ['email', 'name'], '2026_06_18');

// List all backup files
$backups = DataSafety::listBackups();
// Returns: [['file' => '...', 'size' => 1234, 'created_at' => '2026-06-18 10:00:00'], ...]
```

### Artisan Commands

[](#artisan-commands)

#### List backup files

[](#list-backup-files)

```
php artisan meraki:data-safety:list

```

#### Clean up old backup files

[](#clean-up-old-backup-files)

```
# Dry run — list files older than 30 days without deleting
php artisan meraki:data-safety:cleanup --dry-run

# Delete files older than 7 days (with confirmation)
php artisan meraki:data-safety:cleanup --older-than=7

# Delete all files without confirmation prompt
php artisan meraki:data-safety:cleanup --older-than=0 --force

```

### Disabling the module

[](#disabling-the-module)

When `MERAKI_DATA_SAFETY_ENABLED=false`, the package binds a `NullDataSafetyService` that performs no operations and creates no files. Migrations using the trait will run without errors.

### Running Tests

[](#running-tests)

```
composer test

```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance69

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

182d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5545183?v=4)[MerakiLabs](/maintainers/MerakiLabs)[@merakilabs](https://github.com/merakilabs)

---

Top Contributors

[![DouDangt](https://avatars.githubusercontent.com/u/5416883?v=4)](https://github.com/DouDangt "DouDangt (3 commits)")

### Embed Badge

![Health badge](/badges/merakilab-meraki-data-safety/health.svg)

```
[![Health](https://phpackages.com/badges/merakilab-meraki-data-safety/health.svg)](https://phpackages.com/packages/merakilab-meraki-data-safety)
```

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.7k2](/packages/crumbls-layup)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
