Я имею две миграции:
(1):
<?php
use yii\db\Migration;
class m211025_183630_create_user_table extends Migration
{
public function safeUp()
{
$this->createTable('{{%user}}', [
'id' => $this->primaryKey(),
'email' => $this->string()->notNull()->unique(),
'password_hash' => $this->string()->notNull(),
'auth_key' => $this->string()->notNull(),
'created_by' => $this->integer()->null(),
'updated_by' => $this->integer()->null(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'updated_at' => $this->integer()->notNull(),
'created_at' => $this->integer()->notNull(),
], Yii::$app->params['tableOptions']);
$this->addForeignKey(
'fk-user-created_by',
'user',
'created_by',
'user',
'id',
'SET NULL',
'CASCADE'
);
$this->addForeignKey(
'fk-user-updated_by',
'user',
'updated_by',
'user',
'id',
'SET NULL',
'CASCADE'
);
}
public function safeDown()
{
$this->dropForeignKey('fk-user-created_by', 'user');
$this->dropForeignKey('fk-user-updated_by', 'user');
$this->dropTable('{{%user}}');
}
}
(2):
<?php
use yii\db\Migration;
class m211025_191412_create_post_table extends Migration
{
public function safeUp()
{
$this->createTable('{{%post}}', [
'id' => $this->primaryKey(),
'title' => $this->string()->notNull(),
'content' => $this->text()->null(),
'image' => $this->string()->null(),
'created_by' => $this->integer()->null(),
'updated_by' => $this->integer()->null(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'updated_at' => $this->integer()->notNull(),
'created_at' => $this->integer()->notNull(),
], Yii::$app->params['tableOptions']);
$this->addForeignKey(
'fk-post-created_by',
'post',
'created_by',
'user',
'id',
'SET NULL',
'CASCADE'
);
$this->addForeignKey(
'fk-post-updated_by',
'post',
'updated_by',
'user',
'id',
'SET NULL',
'CASCADE'
);
}
public function safeDown()
{
$this->dropForeignKey('fk-post-created_by', 'post');
$this->dropForeignKey('fk-post-updated_by', 'post');
$this->dropTable('{{%post}}');
}
}
Есть ли адекватный способ вынести столбцы "created_by", "updated_by", "status", "updated_at", "created_at", если они будут использоваться в каждой таблице?