OSDN Git Service

Настроен вывод списка моделей, отредактирована форма редактированиямодели.
[invent/invent.git] / migrations / m201103_133111_create_models_table.php
1 <?php
2
3 use yii\db\Migration;
4 use app\models\Types;
5
6 /**
7  * Handles the creation of table `{{%models}}`.
8  * Has foreign keys to the tables:
9  *
10  * - `{{%type}}`
11  */
12 class m201103_133111_create_models_table extends Migration
13 {
14     /**
15      * {@inheritdoc}
16      */
17     public function safeUp()
18     {
19         $table = '{{%models}}';
20         $this->createTable($table, [
21             'id'          => 'SERIAL',
22             'name'        => $this->string()->unique()->notNull()->comment('Наименование предмета/оборудования'),
23             'type_id'     => $this->integer()->notNull()->comment('Идентификатор типа'),
24             'modelnumber' => $this->string()->comment('Номер модели'),
25             'product'     => $this->string()->comment('Код оборудования'),
26         ]);
27
28         $this->addCommentOnTable($table, 'Список наименований предметов/оборудования');
29         $this->addPrimaryKey(
30             'pk-models-id',
31             $table,
32             'id'
33         );
34
35         // creates index for column `type_id`
36         $this->createIndex(
37             '{{%idx-models-type_id}}',
38             $table,
39             'type_id'
40         );
41
42         // add foreign key for table `{{%type}}`
43         $this->addForeignKey(
44             '{{%fk-models-type_id}}',
45             $table,
46             'type_id',
47             Types::tableName(),
48             'id',
49             'CASCADE'
50         );
51     }
52
53     /**
54      * {@inheritdoc}
55      */
56     public function safeDown()
57     {
58         $table = '{{%models}}';
59         // drops foreign key for table `{{%type}}`
60         $this->dropForeignKey(
61             '{{%fk-models-type_id}}',
62             $table
63         );
64
65         // drops index for column `type_id`
66         $this->dropIndex(
67             '{{%idx-models-type_id}}',
68             $table
69         );
70         $this->dropPrimaryKey(
71             'pk-models-id',
72             $table
73         );
74
75         $this->dropTable($table);
76     }
77 }