HEX
Server: LiteSpeed
System: Linux premium260.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: aliazzsr (627)
PHP: 7.4.33
Disabled: NONE
Upload Files
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());
    }
}