Answer the question
In order to leave comments, you need to log in
How can you check the existence of tables and indexes in migration before creating them?
For example, up is creating several tables with indexes. The part fulfills, and then falls out by mistake. Down not done, because the migration did not complete completely and was not included in the table. You have to climb into the database and roll back everything manually.
Is it possible to make checks to skip on up what has already been created?
Answer the question
In order to leave comments, you need to log in
Why don't you want to wrap everything in a transaction?
Existence checks can be done like this
const DB_TABLE = '{{%product}}';
public function up()
{
if (Yii::$app->db->schema->getTableSchema(self::DB_TABLE, true) === null) {
$this->createTable(self::DB_TABLE, [
'id' => 'int(11) NOT NULL AUTO_INCREMENT COMMENT "Идентификатор"',
.............................
'PRIMARY KEY (id)',
], 'ENGINE=InnoDB DEFAULT CHARSET=utf8');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question