personal_area_php/console/migrations/m240110_153348_create_addresses_table.php

53 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2024-04-24 18:02:58 +03:00
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%addresses}}`.
*/
class m240110_153348_create_addresses_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%addresses}}', [
'id' => $this->primaryKey(),
'address' => $this->string(255)->notNull(),
'company_id' => $this->integer(11)->notNull(),
'name' => $this->string(255),
]);
$this->createIndex('idx-addresses-company_id', 'addresses', 'company_id');
$this->addForeignKey(
'fk-addresses-company_id',
'addresses',
'company_id',
'company',
'id',
'CASCADE'
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey(
'fk-addresses-company_id',
'addresses'
);
// drops index for column `author_id`
$this->dropIndex(
'idx-addresses-company_id',
'addresses'
);
$this->dropTable('{{%addresses}}');
}
}