Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Phinx\Migration\AbstractMigration;
- use Phinx\Db\Adapter\MysqlAdapter;
- class AreasMigration extends AbstractMigration
- {
- public function up()
- {
- $area = $this->table(
- 'location_area',
- [
- 'engine' => 'InnoDB'
- ]
- );
- $city = $this->table('location_city');
- $apartment = $this->table('apartment');
- $area->addColumn(
- 'country_id',
- 'integer',
- [
- 'signed' => false,
- 'null' => true,
- ]
- );
- $area->addColumn(
- 'region_id',
- 'integer',
- [
- 'signed' => false,
- 'null' => true,
- ]
- );
- $langs = ['ru', 'en', 'de', 'es', 'ar'];
- foreach ($langs as $lang) {
- $area->addColumn(
- 'name_'.$lang,
- 'string',
- [
- 'limit' => 128,
- 'null' => false,
- 'default' => ''
- ]
- );
- }
- $area->save();
- $city->addColumn(
- 'area_id',
- 'integer',
- [
- 'null' => true,
- 'after' => 'region_id',
- 'signed' => false,
- ]
- );
- $city->changeColumn(
- 'region_id',
- 'integer',
- [
- 'signed' => false,
- 'null' => true,
- ]
- );
- $city->save();
- $apartment->addColumn(
- 'loc_area',
- 'integer',
- [
- 'null' => true,
- 'after' => 'loc_region',
- 'signed' => false,
- ]
- );
- $apartment->save();
- }
- public function down()
- {
- $this->table('location_area')->drop()->save();
- $this->table('location_city')->removeColumn('area_id')->save();
- $this->table('apartment')->removeColumn('loc_area')->save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement