File: /home/aliazzsr/api.crm.vqode.com/migrations/m180413_234754_230ProjectContacts.php
<?php
use yii\db\Migration;
use app\models\core\ProjectContact;
use app\models\core\CompanyProject;
use app\components\BaseModel;
use yii\helpers\ArrayHelper;
/**
* Class m180413_234754_230ProjectContacts
*/
class m180413_234754_230ProjectContacts extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$columns = [
'id' => $this->primaryKey(),
'project_id' => $this->integer()->notNull(),
'contact_id' => $this->integer()->notNull(),
];
$this->createTable(ProjectContact::tableName(), $this->addModifiers($columns));
$this->createIndex('uniqProjectContact', ProjectContact::tableName(), ['project_id', 'contact_id'], true);
$this->createIndex('uniqCompanyProject', CompanyProject::tableName(), ['project_id', 'company_id'], true);
}
protected function addModifiers($columns)
{
$modifiers = [
BaseModel::CreatedAt_Attribute => $this->timestamp()->defaultValue(null)
->comment('timestamp record created'),
BaseModel::UpdatedAt_Attribute => $this->timestamp()->defaultValue(null)
->comment('timestamp record last time updated'),
BaseModel::CreatedId_Attribute => $this->integer()->defaultValue(null)
->defaultValue(0)->comment('user created the record'),
BaseModel::UpdatedId_Attribute => $this->integer()->defaultValue(null)
->defaultValue(0)->comment('user updated the record'),
];
return ArrayHelper::merge($columns, $modifiers);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropIndex('uniqCompanyProject', CompanyProject::tableName());
$this->dropIndex('uniqProjectContact', ProjectContact::tableName());
$this->dropTable(ProjectContact::tableName());
}
}