Просмотр исходного кода

增加多商品数据表定义

abiao лет назад: 5
Родитель
Сommit
2083344861
1 измененных файлов с 52 добавлено и 0 удалено
  1. 52 0
      db/migrate/20200808124641_create_product_attrs.rb

+ 52 - 0
db/migrate/20200808124641_create_product_attrs.rb

@@ -0,0 +1,52 @@
+# encoding:utf-8
+class CreateProductAttrs < ActiveRecord::Migration
+  def up
+    #规格定义表
+    create_table :product_attr_keys do |t|
+      # 产品名称
+      t.column :name, :string,:limit => 128
+      # 是否发布
+      t.column :status, :boolean, :default=>1
+      t.timestamps
+    end
+
+    #规格明细表
+    create_table :product_attrs do |t|
+      # 规格ID
+      t.column :attr_key_id, :integer, :limit => 8, :default => 0
+      # 规格名称
+      t.column :name, :string,:limit => 500
+      t.timestamps
+    end
+    add_index :product_attrs, :attr_key_id
+
+
+    #主商品规格配置表
+    create_table :product_attr_configs do |t|
+      # 主商品ID
+      t.column :product_id, :integer, :limit => 8, :default => 0
+      # 规格ID
+      t.column :attr_key_id, :integer, :limit => 8, :default => 0
+      # 类型
+      t.column :type, :integer, :limit => 8, :default => 0
+      t.timestamps
+    end
+
+    add_index :product_attr_configs, :product_id
+    add_index :product_attr_configs, :attr_key_id
+    add_column :products, :size_id, :integer
+    add_column :products, :color_id, :integer
+    add_column :products, :relate_product_id, :integer
+    add_column :products, :show_flag, :boolean
+  end
+
+  def down
+  	drop_table :product_attr_keys
+    drop_table :product_attrs
+    drop_table :product_attr_configs
+    remove_column :products, :size_id
+    remove_column :products, :color_id
+    remove_column :products, :relate_product_id
+    remove_column :products, :show_flag
+  end
+end