1. Go to this page and download the library: Download peehaa/migres 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/ */
peehaa / migres example snippets
declare(strict_types=1);
namespace Vendor\Migrations;
use PeeHaa\Migres\DataType\BigSerial;
use PeeHaa\Migres\DataType\Boolean;
use PeeHaa\Migres\DataType\CharacterVarying;
use PeeHaa\Migres\MigrationSpecification;
use PeeHaa\Migres\Specification\Table;
class CreateTable extends MigrationSpecification
{
public function change(): void
{
$this->createTable('users', function (Table $table) {
$table->addColumn('id', new BigSerial());
$table->addColumn('is_admin', new Boolean())->notNull()->default(false);
$table->addColumn('name', new CharacterVarying(128))->notNull();
$table->addColumn('email_address', new CharacterVarying(255))->notNull();
$table->primaryKey('id');
$table->addIndex('users_name', 'name');
$table->addUniqueConstraint('email_address_unq', 'email_address');
});
}
}
declare(strict_types=1);
namespace Vendor\Migrations;
use PeeHaa\Migres\MigrationSpecification;
class RenameTable extends MigrationSpecification
{
public function change(): void
{
$this->renameTable('users', 'members');
}
}
declare(strict_types=1);
namespace Vendor\Migrations;
use PeeHaa\Migres\MigrationSpecification;
class RenameTable extends MigrationSpecification
{
public function change(): void
{
$this->dropTable('members');
}
}
$table->addColumn('column_name', new Integer());
$table->addColumn('column_name', new Integer())->notNull;
$table->addColumn('column_name', new Integer())->default(12);
$table->dropColumn('column_name');
$table->renameColumn('old_name', 'new_name');
$table->changeColumn('column_name', new IntegerType());
$table->changeColumn('column_name', new IntegerType())->notNull();
$table->changeColumn('column_name', new IntegerType())->default(12);