PHP code example of nish / db-migration

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

    

nish / db-migration example snippets



class Foo implements DbMigration
{
    public function up(PDO $pdo)
    {
        $pdo->exec('
create table foo(
  foo_id serial primary key,
  name text not null,
  body text
)
');
    }

    public function down(PDO $pdo)
    {
        $pdo->exec('drop table foo');
    }
}



class Foo implements DbMigration
{
    public function up(PDO $pdo)
    {
        $pdo->exec('
create table foo(
  foo_id serial primary key,
  name text not null,
  body text,
  created_at timestamp not null default CURRENT_TIMESTAMP
)
');
    }

    public function down(PDO $pdo)
    {

        $pdo->exec('drop table foo');
    }
}

export PDO_DSN='pgsql:host=localhost;dbname=mydb;user=myuser;password=secret'
bash
vendor/bin/db-migration.php --down
Donwgrade:
 3b1243                    001_Foo.php                  Foo  2018-10-25 18:33:56
upgrade:
 9e4e3b                    001_Foo.php                  Foo                     

Migrate? [y/n]: y
down: 3b1243736a19b730845aaf8521336e3bbce12122 .ok
up  : 9e4e3bb05f5e7de76f9971b1cc6afaa4b5ca6687 .ok
Success!!

db-migration/
├── 001-Initialize
│   ├── Account.php
│   └── Item.php
├── 002-Setup
│   ├── AccountSetup.php
│   └── FooSetup.php
└── 010-AddFeature1
    ├── AccountFeature1.php
    └── ItemFeature1.php