PHP code example of adhuham / pretty-phinx
1. Go to this page and download the library: Download adhuham/pretty-phinx 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/ */
adhuham / pretty-phinx example snippets
use PrettyPhinx\Migration\AbstractMigration;
class MyNewMigration extends AbstractMigration
{
public function change()
{
}
}
$post = $this->table('post');
$post->bigIncrements('id')->add();
$post->string('slug')->unique()->add();
$post->string('title')->length(255)->add();
$post->text('content')->nullable()->add();
$post->create();
$post = $this->table('post');
$post->bigIncrements('id')->change();
$post->string('slug')->unique()->change();
$post->string('title')->length(255)->nullable()->change();
$post->text('content')->nullable()->change();
$post->string('sub_title')->after('title');
$post->update();
$tag = $this->table('tag');
$tag->bigIncrements()->add();
$tag->string('slug')->unique()->add();
$tag->string('name')->add();
$tag->create();
$post = $this->table('post');
$post->unsignedBigInteger('tag_id');
$post->foreign('tag_id')->references('id')->on('tag')
->onUpdate('cascade')
->onDelete('cascade')
->add();
$post->update();
$table->unsignedBigInteger();
$table->unsignedMediumInteger();
$table->unsignedSmallInteger();
$table->unsignedTinyInteger();
$table->unsignedInteger();
$table->bigInteger();
$table->mediumInteger();
$table->smallInteger();
$table->tinyInteger();
$table->integer();
$table->text();
$table->longText();
$table->mediumText();
$table->tinyText();
$table->decimal($precision = 8, $scale = 2);
$table->boolean();
$table->dateTime();
$table->date();
$table->time();
// these methods will create an auto-incrementing column
$table->bigIncrements();
$table->mediumIncrements();
$table->smallIncrements();
$table->tinyIncrements();
$table->increments();
// ->length()
$table->string('title')->length(100)->add();
// ->default()
$table->string('title')->default('untitled')->add();
// ->nullable()
$table->string('title')->nullable()->add();
$table->string('title')->nullable(false)->add(); // disable null (NOT NULL)
// ->unique()
$table->string('title')->unique()->add();
// ->index()
$table->string('title')->index()->add();
// ->after()
$table->string('title')->after('another_column')->add();
// ->charset()
$table->string('title')->charset('utf8')->add();
// ->collation()
$table->string('title')->collation('utf8_general_ci')->add();
$table = $this->table('post');
// this changes the collation of "post" table
$table->collation('utf8_general_ci');
// ...
// ...
$table->update();