PHP code example of enlivenapp / migrations

1. Go to this page and download the library: Download enlivenapp/migrations 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/ */

    

enlivenapp / migrations example snippets


    'vendor/*/*/Database/Migrations',
    'vendor/*/*/src/Database/Migrations',

    'vendor/*/*/Database/Seeds',
    'vendor/*/*/src/Database/Seeds',

// app/config/migrations.php
return [
    // database connection
    'host'     => 'localhost',
    'dbname'   => 'myapp',
    'user'     => 'root',
    'password' => '',
    // below is optional
    'port'     => 3306,
    'charset'  => 'utf8mb4',
    // the key we look for to override default settings
    'migrations' => [
        // How 'paths' and 'seeds.paths' below combine with the defaults.
        //   'replace' -> replace the entire list, no positional merge
        //   'keys'    -> legacy positional merge (default, deprecated)
        //   'add'     -> append to the defaults (deduped)
        // Applies to both paths and seeds.
        'path_mode' => 'add',
        // set folders to look in (recursive)
        'paths' => [
            'app/Database/Migrations',
        ],
        // if you place a seed file in a different location
        // you can add it to the override. File must be 'Seed.php'
        'seeds' => [
            // set folders to look in (recursive)
            'paths'  => [
                'app/Database/Seeds',
            ],
        ],
    ],
];

return [
    'migrations' => [
        // Existing paths / seeds keys omitted for brevity.

        // Version for each module name, taking precedence over
        // composer/installed.json. Decides which seeds run.
        'versions' => [
            'pubvana/pubvana' => '3.0.0',
            'app/blog'        => '1.0.0',
        ],

        // Give a migration path pattern a real package identity.
        'module_names' => [
            'app/Database/Migrations' => 'pubvana/pubvana',
        ],
    ],
];

// Uses the resolved database connection and the default config
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup();

// Add extra paths/seeds at runtime. This array is additive: its 'paths' and
// 'seeds.paths' are appended to the resolved config (deduped), regardless of
// 'path_mode'. Other keys merge recursively.
$config = [
    'migrations' => [
        'paths' => [
            'app/Database/Migrations',
        ],
        'seeds' => [
            'paths' => [
                'app/Database/Seeds',
            ],
        ],
    ],
];

$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup($config);

// php8+ named argument form
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup(config: $config);

// vendor/acme/blog/src/Database/Migrations/2026-01-15-143022_CreatePostsTable.php


declare(strict_types=1);

namespace Acme\Blog\Database\Migrations;

use Enlivenapp\Migrations\Services\Migration;

class CreatePostsTable extends Migration
{
    public function up(): void
    {
        $this->table('posts')
            ->addColumn('id', 'primary')
            ->addColumn('title', 'string', ['length' => 200])
            ->addColumn('body', 'text', ['nullable' => true])
            ->addColumn('published', 'boolean', ['default' => false])
            ->addColumn('created_at', 'datetime')
            ->addIndex(['title'])
            ->create();
    }

    public function down(): void
    {
        $this->table('posts')->drop();
    }
}

class CreatePostsTable extends Migration
{
    public function change(): void
    {
        $this->table('posts')
            ->addColumn('id', 'primary')
            ->addColumn('title', 'string', ['length' => 200])
            ->create();
    }
}

/*  File Locations default:  vendor/{vendor}/{package}/Database/Seeds/Seed.php
                               vendor/{vendor}/{package}/src/Database/Seeds/Seed.php

// seeds on update of version 1.1.0.  Multiple versions since install: Seeds from last version (installed or updated) 
// seeded through to the current version are ran. in the instance below. if installed at 0.8.5,  there were versions 
// 0.9.0 and 0.9.5 and 1.1.0 that had not been seeded, all of these seeds would be  [
            ['table' => 'posts',
                'rows'  => [
                    ['title' => 'Welcome', 'body' => 'post-body', 'published' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')],
                    ['title' => 'Welcome 2', 'body' => 'post-body-2', 'published' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')],
                ],
            ],
        ],
    ],
];

// Any file in your application that wants to run Mirgraions

// Install/Update all packages
$migrate->runMigrate();

// Install/Update a single package
$migrate->runMigrate('vendor/package');

bash
php runway migrate:single acme/blog
bash
php runway migrate:all