zubzizub
7/30/2017 - 9:40 AM

миграция phinx (poster)

миграция phinx (poster)

<?php

use Phinx\Migration\AbstractMigration;

class AddColumnToStoriesCitiesTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('oc_stores_cities');
        $table->addColumn('region_id', 'integer', ['after' => 'id'])
            ->addForeignKey(
                'region_id',
                'oc_stores_regions',
                'id',
                ['delete'=> 'CASCADE', 'update'=> 'RESTRICT']
            )
            ->addColumn('slug', 'string', ['after' => 'city_name'])
            ->addIndex(['slug'], ['unique' => true])
            ->addColumn('title', 'string')
            ->addColumn('description', 'string')
            ->save();

        $table->removeIndex(['city_name']);
    }

    public function down()
    {
        $table = $this->table('oc_stores_cities');

        $table->dropForeignKey('region_id');

        $table->removeColumn('region_id')
            ->removeColumn('slug')
            ->removeColumn('title')
            ->removeColumn('description')
            ->addIndex(['city_name'], ['unique' => true])
            ->save();
    }
}