From 9d33ce375db33d987f39444291a30eb70e5b818f Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Wed, 23 Mar 2016 23:23:47 +0200 Subject: [PATCH] New product migration --- console/migrations/m160304_065108_product.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/console/migrations/m160304_065108_product.php b/console/migrations/m160304_065108_product.php index 7925483..bdbdf39 100644 --- a/console/migrations/m160304_065108_product.php +++ b/console/migrations/m160304_065108_product.php @@ -16,25 +16,96 @@ class m160304_065108_product extends Migration // Only for PostgreSQL // @todo use intarray field for tax_options } - $this->createTable('{{%product}}', [ - 'product_id' => $this->primaryKey(), - 'name' => $this->string(255)->notNull(), + + $this->createTable('{{%category_name}}', [ + 'category_name_id' => $this->primaryKey(), + 'category_id' => $this->integer()->notNull(), + 'value' => $this->string(250), + ], $tableOptions); + + $this->createTable('{{%category}}', [ + 'category_id' => $this->primaryKey(), + 'parent_id' => $this->integer()->notNull()->defaultValue(0), + 'path' => 'INT[]', + 'depth' => $this->integer()->notNull()->defaultValue(0), + 'alias' => $this->string(250), + 'image' => $this->string(255), + 'meta_title' => $this->string(255), + 'meta_desc' => $this->text(), + 'meta_robots' => $this->string(50), + 'seo_text' => $this->text(), + 'category_name_id' => $this->integer(), + 'product_unit_id' => $this->integer() ], $tableOptions); + $this->addForeignKey('category_name_fkey', 'category', 'category_name_id', 'category_name', 'category_name_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('category_name_category_fkey', 'category_name', 'category_id', 'category', 'category_id', 'NO ACTION', 'NO ACTION'); + $this->createTable('{{%product_category}}', [ 'product_id' => $this->integer()->notNull(), 'category_id' => $this->integer()->notNull(), ], $tableOptions); + + $this->createTable('{{%brand_name}}', [ + 'brand_name_id' => $this->primaryKey(), + 'brand_id' => $this->integer()->notNull(), + 'value' => $this->string(250), + ], $tableOptions); + + $this->createTable('{{%brand}}', [ + 'brand_id' => $this->primaryKey(), + 'brand_name_id' => $this->integer(), + 'alias' => $this->string(250), + 'image' => $this->string(255), + 'meta_title' => $this->string(255), + 'meta_desc' => $this->text(), + 'meta_robots' => $this->string(50), + 'seo_text' => $this->text(), + ], $tableOptions); + + $this->addForeignKey('brand_name_fkey', 'brand', 'brand_name_id', 'brand_name', 'brand_name_id', 'CASCADE', 'CASCADE'); + $this->addForeignKey('brand_name_brand_fkey', 'brand_name', 'brand_id', 'brand', 'brand_id', 'NO ACTION', 'NO ACTION'); + + $this->createTable('{{%product}}', [ + 'product_id' => $this->primaryKey(), + 'name' => $this->string(255)->notNull(), + 'brand_id' => $this->integer(), + ], $tableOptions); + $this->addForeignKey('fki_product_id', 'product_category', 'product_id', 'product', 'product_id', 'NO ACTION', 'NO ACTION'); - $this->addForeignKey('fki_category_id', 'product_category', 'category_id', 'tax_option', 'tax_option_id', 'NO ACTION', 'NO ACTION'); + $this->addForeignKey('fki_category_id', 'product_category', 'category_id', 'category', 'category_id', 'NO ACTION', 'NO ACTION'); + $this->addForeignKey('fki_brand_id', 'product', 'brand_id', 'brand', 'brand_id', 'NO ACTION', 'CASCADE'); + + $this->createTable('{{%product_variant}}', [ + 'product_variant_id' => $this->primaryKey(), + 'product_id' => $this->integer()->notNull(), + 'name' => $this->string(255)->notNull(), + 'sku' => $this->string(255)->notNull(), + 'price' => $this->float(), + 'price_old' => $this->float(), + 'stock' => $this->float(), + 'product_unit_id' => $this->integer()->notNull(), + ], $tableOptions); + + $this->createTable('{{%product_unit}}', [ + 'product_unit_id' => $this->primaryKey(), + 'name' => $this->string(255)->notNull(), + 'code' => $this->string(50)->notNull(), + 'is_default' => $this->boolean() + ], $tableOptions); + + $this->addForeignKey('product_variant_product_unit_fkey', 'product_variant', 'product_unit_id', 'product_unit', 'product_unit_id', 'CASCADE', 'NO ACTION'); + $this->addForeignKey('category_product_unit_fkey', 'category', 'product_unit_id', 'product_unit', 'product_unit_id', 'NO ACTION', 'NO ACTION'); } public function down() { - $this->dropTable('{{%product}}'); + $this->dropTable('{{%category}}'); + $this->dropTable('{{%category_name}}'); $this->dropTable('{{%product_category}}'); - - return false; + $this->dropTable('{{%product}}'); + $this->dropTable('{{%product_variant}}'); + $this->dropTable('{{%product_unit}}'); } /* -- libgit2 0.21.4