Commit 9d33ce375db33d987f39444291a30eb70e5b818f
1 parent
415bd38a
New product migration
Showing
1 changed file
with
78 additions
and
7 deletions
Show diff stats
console/migrations/m160304_065108_product.php
... | ... | @@ -16,25 +16,96 @@ class m160304_065108_product extends Migration |
16 | 16 | // Only for PostgreSQL |
17 | 17 | // @todo use intarray field for tax_options |
18 | 18 | } |
19 | - $this->createTable('{{%product}}', [ | |
20 | - 'product_id' => $this->primaryKey(), | |
21 | - 'name' => $this->string(255)->notNull(), | |
19 | + | |
20 | + $this->createTable('{{%category_name}}', [ | |
21 | + 'category_name_id' => $this->primaryKey(), | |
22 | + 'category_id' => $this->integer()->notNull(), | |
23 | + 'value' => $this->string(250), | |
24 | + ], $tableOptions); | |
25 | + | |
26 | + $this->createTable('{{%category}}', [ | |
27 | + 'category_id' => $this->primaryKey(), | |
28 | + 'parent_id' => $this->integer()->notNull()->defaultValue(0), | |
29 | + 'path' => 'INT[]', | |
30 | + 'depth' => $this->integer()->notNull()->defaultValue(0), | |
31 | + 'alias' => $this->string(250), | |
32 | + 'image' => $this->string(255), | |
33 | + 'meta_title' => $this->string(255), | |
34 | + 'meta_desc' => $this->text(), | |
35 | + 'meta_robots' => $this->string(50), | |
36 | + 'seo_text' => $this->text(), | |
37 | + 'category_name_id' => $this->integer(), | |
38 | + 'product_unit_id' => $this->integer() | |
22 | 39 | ], $tableOptions); |
23 | 40 | |
41 | + $this->addForeignKey('category_name_fkey', 'category', 'category_name_id', 'category_name', 'category_name_id', 'CASCADE', 'CASCADE'); | |
42 | + $this->addForeignKey('category_name_category_fkey', 'category_name', 'category_id', 'category', 'category_id', 'NO ACTION', 'NO ACTION'); | |
43 | + | |
24 | 44 | $this->createTable('{{%product_category}}', [ |
25 | 45 | 'product_id' => $this->integer()->notNull(), |
26 | 46 | 'category_id' => $this->integer()->notNull(), |
27 | 47 | ], $tableOptions); |
48 | + | |
49 | + $this->createTable('{{%brand_name}}', [ | |
50 | + 'brand_name_id' => $this->primaryKey(), | |
51 | + 'brand_id' => $this->integer()->notNull(), | |
52 | + 'value' => $this->string(250), | |
53 | + ], $tableOptions); | |
54 | + | |
55 | + $this->createTable('{{%brand}}', [ | |
56 | + 'brand_id' => $this->primaryKey(), | |
57 | + 'brand_name_id' => $this->integer(), | |
58 | + 'alias' => $this->string(250), | |
59 | + 'image' => $this->string(255), | |
60 | + 'meta_title' => $this->string(255), | |
61 | + 'meta_desc' => $this->text(), | |
62 | + 'meta_robots' => $this->string(50), | |
63 | + 'seo_text' => $this->text(), | |
64 | + ], $tableOptions); | |
65 | + | |
66 | + $this->addForeignKey('brand_name_fkey', 'brand', 'brand_name_id', 'brand_name', 'brand_name_id', 'CASCADE', 'CASCADE'); | |
67 | + $this->addForeignKey('brand_name_brand_fkey', 'brand_name', 'brand_id', 'brand', 'brand_id', 'NO ACTION', 'NO ACTION'); | |
68 | + | |
69 | + $this->createTable('{{%product}}', [ | |
70 | + 'product_id' => $this->primaryKey(), | |
71 | + 'name' => $this->string(255)->notNull(), | |
72 | + 'brand_id' => $this->integer(), | |
73 | + ], $tableOptions); | |
74 | + | |
28 | 75 | $this->addForeignKey('fki_product_id', 'product_category', 'product_id', 'product', 'product_id', 'NO ACTION', 'NO ACTION'); |
29 | - $this->addForeignKey('fki_category_id', 'product_category', 'category_id', 'tax_option', 'tax_option_id', 'NO ACTION', 'NO ACTION'); | |
76 | + $this->addForeignKey('fki_category_id', 'product_category', 'category_id', 'category', 'category_id', 'NO ACTION', 'NO ACTION'); | |
77 | + $this->addForeignKey('fki_brand_id', 'product', 'brand_id', 'brand', 'brand_id', 'NO ACTION', 'CASCADE'); | |
78 | + | |
79 | + $this->createTable('{{%product_variant}}', [ | |
80 | + 'product_variant_id' => $this->primaryKey(), | |
81 | + 'product_id' => $this->integer()->notNull(), | |
82 | + 'name' => $this->string(255)->notNull(), | |
83 | + 'sku' => $this->string(255)->notNull(), | |
84 | + 'price' => $this->float(), | |
85 | + 'price_old' => $this->float(), | |
86 | + 'stock' => $this->float(), | |
87 | + 'product_unit_id' => $this->integer()->notNull(), | |
88 | + ], $tableOptions); | |
89 | + | |
90 | + $this->createTable('{{%product_unit}}', [ | |
91 | + 'product_unit_id' => $this->primaryKey(), | |
92 | + 'name' => $this->string(255)->notNull(), | |
93 | + 'code' => $this->string(50)->notNull(), | |
94 | + 'is_default' => $this->boolean() | |
95 | + ], $tableOptions); | |
96 | + | |
97 | + $this->addForeignKey('product_variant_product_unit_fkey', 'product_variant', 'product_unit_id', 'product_unit', 'product_unit_id', 'CASCADE', 'NO ACTION'); | |
98 | + $this->addForeignKey('category_product_unit_fkey', 'category', 'product_unit_id', 'product_unit', 'product_unit_id', 'NO ACTION', 'NO ACTION'); | |
30 | 99 | } |
31 | 100 | |
32 | 101 | public function down() |
33 | 102 | { |
34 | - $this->dropTable('{{%product}}'); | |
103 | + $this->dropTable('{{%category}}'); | |
104 | + $this->dropTable('{{%category_name}}'); | |
35 | 105 | $this->dropTable('{{%product_category}}'); |
36 | - | |
37 | - return false; | |
106 | + $this->dropTable('{{%product}}'); | |
107 | + $this->dropTable('{{%product_variant}}'); | |
108 | + $this->dropTable('{{%product_unit}}'); | |
38 | 109 | } |
39 | 110 | |
40 | 111 | /* | ... | ... |