20200808124641_create_product_attrs.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # encoding:utf-8
  2. class CreateProductAttrs < ActiveRecord::Migration
  3. def up
  4. #规格定义表
  5. create_table :product_attr_keys do |t|
  6. # 产品名称
  7. t.column :name, :string,:limit => 128
  8. # 是否发布
  9. t.column :status, :boolean, :default=>1
  10. t.timestamps
  11. end
  12. #规格明细表
  13. create_table :product_attrs do |t|
  14. # 规格ID
  15. t.column :attr_key_id, :integer, :limit => 8, :default => 0
  16. # 规格名称
  17. t.column :name, :string,:limit => 500
  18. # 排序
  19. t.column :recommend, :integer, :limit => 8, :default => 0
  20. # 状态
  21. t.column :status, :boolean, :default=>1
  22. t.timestamps
  23. end
  24. add_index :product_attrs, :attr_key_id
  25. #主商品规格配置表
  26. create_table :product_attr_configs do |t|
  27. # 主商品ID
  28. t.column :product_id, :integer, :limit => 8, :default => 0
  29. # 规格ID
  30. t.column :attr_key_id, :integer, :limit => 8, :default => 0
  31. # 类型
  32. t.column :size_type, :string, :limit => 64
  33. t.timestamps
  34. end
  35. add_index :product_attr_configs, :product_id
  36. add_index :product_attr_configs, :attr_key_id
  37. add_column :products, :size_id, :integer,:default => 0,:limit => 8
  38. add_column :products, :color_id, :integer,:default => 0,:limit => 8
  39. add_column :products, :relate_product_id, :integer
  40. add_column :products, :show_flag, :boolean,:limit => 8
  41. add_column :order_details, :size_name,:string,:limit => 128
  42. add_column :order_details, :color_name,:string,:limit => 128
  43. add_index :products, :size_id
  44. add_index :products, :color_id
  45. end
  46. def down
  47. drop_table :product_attr_keys
  48. drop_table :product_attrs
  49. drop_table :product_attr_configs
  50. remove_column :products, :size_id
  51. remove_column :products, :color_id
  52. remove_column :products, :relate_product_id
  53. remove_column :products, :show_flag
  54. remove_column :order_details, :size_name
  55. remove_column :order_details, :color_name
  56. end
  57. end