PHP code example of kerroldj / laravel-migrate-fresh-table

1. Go to this page and download the library: Download kerroldj/laravel-migrate-fresh-table library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kerroldj / laravel-migrate-fresh-table example snippets


// config/migrate-fresh-table.php
'overrides' => [
    'users' => [
        'database/migrations/2014_10_12_000000_create_users_table.php',
    ],
],

use Illuminate\Database\Schema\Blueprint;

// config/migrate-fresh-table.php
'schema' => [
    'sessions' => function (Blueprint $table) {
        $table->string('id')->primary();
        $table->foreignId('user_id')->nullable()->index();
        $table->string('ip_address', 45)->nullable();
        $table->text('payload');
        $table->integer('last_activity')->index();
    },
],

'table_strategies' => [
    'sessions' => 'schema',
],

use Kerroldj\MigrateFreshTable\Contracts\FreshStrategy;
use Kerroldj\MigrateFreshTable\Support\FreshContext;

class ParquetImportStrategy implements FreshStrategy
{
    public function name(): string
    {
        return 'parquet';
    }

    public function recreate(FreshContext $context): void
    {
        // $context->table, $context->connection, $context->schema,
        // $context->schemaBuilder, $context->pretend, $context->options
        $context->schemaBuilder->create($context->table, function ($table) {
            // ...
        });
    }
}

// config/migrate-fresh-table.php
'strategies' => [
    'migration' => \Kerroldj\MigrateFreshTable\Strategies\MigrationStrategy::class,
    'schema'    => \Kerroldj\MigrateFreshTable\Strategies\SchemaStrategy::class,
    'parquet'   => \App\Fresh\ParquetImportStrategy::class,
],

// config/migrate-fresh-table.php
'connections' => ['tenant_one', 'tenant_two'],

'tenant_resolver' => fn () => \App\Models\Tenant::query()->pluck('connection')->all(),

use Kerroldj\MigrateFreshTable\Events\TableFreshed;

Event::listen(TableFreshed::class, function (TableFreshed $event) {
    logger()->info("Freshed {$event->table} on {$event->connection}");
});

// config/migrate-fresh-table.php
'hooks' => [
    'before' => function (string $connection, array $tables) { /* ... */ },
    'after'  => function (string $connection, array $tables) { /* ... */ },
],

  // Which APP_ENV values ' => ['production'],
  
bash
php artisan migrate:fresh-table sessions --strategy=schema
bash
php artisan migrate:fresh-table events --strategy=parquet