PHP code example of vgarvardt / zf-simple-migrations
1. Go to this page and download the library: Download vgarvardt/zf-simple-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/ */
vgarvardt / zf-simple-migrations example snippets
namespace ZfSimpleMigrations\Migrations;
use ZfSimpleMigrations\Library\AbstractMigration;
use Zend\Db\Metadata\MetadataInterface;
class Version20130403165433 extends AbstractMigration
{
public static $description = "Migration description";
public function up(MetadataInterface $schema)
{
//$this->addSql(/*Sql instruction*/);
}
public function down(MetadataInterface $schema)
{
//$this->addSql(/*Sql instruction*/);
}
}
namespace ZfSimpleMigrations\Migrations;
use ZfSimpleMigrations\Library\AbstractMigration;
use Zend\Db\Metadata\MetadataInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
class Version20130403165433 extends AbstractMigration
implements ServiceLocatorAwareInterface
{
use ServiceLocatorAwareTrait;
public static $description = "Migration description";
public function up(MetadataInterface $schema)
{
//$this->getServiceLocator()->get(/*Get service by alias*/);
//$this->addSql(/*Sql instruction*/);
}
public function down(MetadataInterface $schema)
{
//$this->getServiceLocator()->get(/*Get service by alias*/);
//$this->addSql(/*Sql instruction*/);
}
}
namespace ZfSimpleMigrations\Migrations;
use Zend\Db\Adapter\AdapterAwareInterface;
use Zend\Db\Adapter\AdapterAwareTrait;
use Zend\Db\Sql\Ddl\Column\Integer;
use Zend\Db\Sql\Ddl\Column\Varchar;
use Zend\Db\Sql\Ddl\Constraint\PrimaryKey;
use Zend\Db\Sql\Ddl\CreateTable;
use Zend\Db\Sql\Ddl\DropTable;
use ZfSimpleMigrations\Library\AbstractMigration;
use Zend\Db\Metadata\MetadataInterface;
class Version20150524162247 extends AbstractMigration implements AdapterAwareInterface
{
use AdapterAwareTrait;
public static $description = "Migration description";
public function up(MetadataInterface $schema)
{
$table = new CreateTable('my_table');
$table->addColumn(new Integer('id', false));
$table->addConstraint(new PrimaryKey('id'));
$table->addColumn(new Varchar('my_column', 64));
$this->addSql($table->getSqlString($this->adapter->getPlatform()));
}
public function down(MetadataInterface $schema)
{
$drop = new DropTable('my_table');
$this->addSql($drop->getSqlString($this->adapter->getPlatform()));
}
}