Skip to content

MigrationBackup ​

Facade: Unusualify\Modularous\Facades\MigrationBackup
Accessor: migration.backup
Underlying: Unusualify\Modularous\Services\MigrationBackupService

Temporarily backs up and restores table data around destructive migration operations (e.g. dropping and recreating a table). Stores the backup in the cache to survive the migration run.

Methods ​

MethodSignatureDescription
backup(string $table, ?array $columns = null): voidReads the table rows (optionally filtered to $columns) and saves them to cache
restore(): boolInserts the backed-up rows back into the table; returns true on success
getBackup(): array|nullReturns the raw backed-up data, or null if no backup exists
clearBackup(): voidRemoves the backup from cache
getBackupKey(): stringReturns the cache key used to store the backup

Usage ​

php
use Unusualify\Modularous\Facades\MigrationBackup;

// In a migration
public function up()
{
    MigrationBackup::backup('settings');

    Schema::drop('settings');
    Schema::create('settings', function (Blueprint $table) {
        // new schema
    });

    MigrationBackup::restore();
}

Notes ​

  • Intended for migrations that must drop and recreate a table while preserving existing data.
  • The backup TTL is long enough to survive a typical migration run but does not persist permanently — call clearBackup() if the restore is not needed.