PHP code example of veejay / migration

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

    

veejay / migration example snippets




use Veejay\Migration\Repository\SqlRepository;

return [
    'path' => __DIR__ . '/migration',
    'repository' => new SqlRepository(
        'mysql:host=localhost;dbname=database',
        'root',
        'password',
        null,
        SqlRepository::MIGRATION_TABLE,
    ),
];


declare(strict_types=1);

use Veejay\Migration\Unit\Migration;

final class m_000000_000000_my_1st_migration extends Migration
{
    public function up(): bool
    {
        $repository = $this->getRepository(); /* @var SqlRepository $repository */
        $sql = 'CREATE TABLE `test` (`id` INT AUTO_INCREMENT, `name` TEXT, PRIMARY KEY (`id`) USING BTREE)';
        return $repository->getDb()->execute($sql);
    }

    public function down(): bool
    {
        $repository = $this->getRepository(); /* @var SqlRepository $repository */
        $sql = 'DROP TABLE `test`';
        return $repository->getDb()->execute($sql);
    }
}