File: /home/aliazzsr/api.crm.vqode.com/migrations/m180503_210956_264MultipleNotes.php
<?php
use yii\db\Migration;
use app\models\core\Note;
use app\models\enums\NoteTypeEnum;
use app\components\BaseModel;
use yii\helpers\ArrayHelper;
/**
* Class m180503_210956_264MultipleNotes
*/
class m180503_210956_264MultipleNotes extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$columns = [
'id' => $this->primaryKey(),
'reltype_id' => $this->integer()->notNull()->comment('relation bonded to (Company, Project, etc)'),
'rel_id' => $this->integer()->notNull()->comment('FK relation.id'),
'type_id' => $this->integer()->notNull()->defaultValue(NoteTypeEnum::DEFAULT_NOTE)->comment('note type'),
'dt' => $this->timestamp()->defaultValue(null),
'content' => $this->text(),
];
$this->createTable(Note::tableName(), $this->addModifiers($columns));
}
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->dropTable(Note::tableName());
}
}