m160208_094102_add_project_specialization.php 2.15 KB
<?php

use yii\db\Migration;

class m160208_094102_add_project_specialization extends Migration
{
    public function up ()
    {
        $this->createTable (
            '{{%project_specialization}}', [
                'project_specialization_id' => $this->primaryKey (), 'project_id' => $this->integer (), 'specialization_id' => $this->integer (),
            ]
        );
        $this->addForeignKey ('project_specialization_index', '{{%project_specialization}}', 'specialization_id', '{{%specialization}}', 'specialization_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey ('specialization_project_index', '{{%project_specialization}}', 'project_id', '{{%project}}', 'project_id', 'CASCADE', 'CASCADE');

        $this->createTable (
            '{{%project_payment}}', [
                'project_payment_id' => $this->primaryKey (), 'project_id' => $this->integer (), 'payment_id' => $this->integer (),
            ]
        );
        $this->addForeignKey ('project_payment_index', '{{%project_payment}}', 'payment_id', '{{%payment}}', 'payment_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey ('payment_project_index', '{{%project_payment}}', 'project_id', '{{%project}}', 'project_id', 'CASCADE', 'CASCADE');

        $this->createTable (
            '{{%employment}}', [
                'employment_id' => $this->primaryKey (), 'name' => $this->string(),
            ]
        );
        $this->createTable (
            '{{%vacancy_employment}}', [
                'vacancy_employment' => $this->primaryKey (), 'vacancy_id' => $this->integer (), 'employment_id' => $this->integer (),
            ]
        );
        $this->addForeignKey ('vacancy_employment_index', '{{%vacancy_employment}}', 'employment_id', '{{%employment}}', 'employment_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey ('employment_vacancy_index', '{{%vacancy_employment}}', 'vacancy_id', '{{%vacancy}}', 'vacancy_id', 'CASCADE', 'CASCADE');

    }

    public function down ()
    {
        $this->dropTable('{{%project_specialization}}');
        $this->dropTable('{{%project_payment}}');
        $this->dropTable('{{%vacancy_employment}}');
        $this->dropTable('{{%employment}}');

    }

}