View file database/upgrades/20170904112945_change_relate_in_files.php

File size: 765B
<?php

use App\Models\Post;
use Phinx\Migration\AbstractMigration;

class ChangeRelateInFiles extends AbstractMigration
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('files');
        $table->changeColumn('relate_type', 'string', ['limit' => 50])
            ->save();

        $this->execute('UPDATE files SET relate_type="'.addslashes(Post::class).'" WHERE relate_type="Post";');
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('files');
        $table->changeColumn('relate_type', 'string', ['limit' => 20])
            ->save();

        $this->execute('UPDATE files SET relate_type="Post" WHERE relate_type="'.addslashes(Post::class).'";');
    }
}