Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mgerasimchuk/19329f2c22db61c58d9dfbea631441b5 to your computer and use it in GitHub Desktop.
Save mgerasimchuk/19329f2c22db61c58d9dfbea631441b5 to your computer and use it in GitHub Desktop.
<?php
use yii\db\Migration;
class m160209_063654_group_student__create_table extends Migration
{
public function up()
{
$this->createTable('{{%group_student}}', [
'id' => $this->primaryKey(),
'groupId' => $this->integer()->notNull(),
'studentId' => $this->integer()->notNull(),
'createdAt' => $this->dateTime(),
'updatedAt' => $this->dateTime(),
]);
$this->addForeignKey('FK_group_student_groupId', '{{%group_student}}', 'groupId', '{{%group}}', 'id');
$this->addForeignKey('FK_group_student_studentId', '{{%group_student}}', 'studentId', '{{%user_account}}', 'id');
$this->createIndex('UK_group_student_groupId_studentId', '{{%group_student}}', ['groupId', 'studentId'], true);
}
public function down()
{
$this->dropIndex('UK_group_student_groupId_studentId', '{{%group_student}}');
$this->dropForeignKey('FK_group_student_studentId', '{{%group_student}}');
$this->dropForeignKey('FK_group_student_groupId', '{{%group_student}}');
$this->dropTable('{{%group_student}}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment