20200808124641_create_product_attrs.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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
  38. add_column :products, :color_id, :integer
  39. add_column :products, :relate_product_id, :integer
  40. add_column :products, :show_flag, :boolean
  41. add_column :order_details, :size_name, :string
  42. add_column :order_details, :color_name, :string
  43. end
  44. def down
  45. drop_table :product_attr_keys
  46. drop_table :product_attrs
  47. drop_table :product_attr_configs
  48. remove_column :products, :size_id
  49. remove_column :products, :color_id
  50. remove_column :products, :relate_product_id
  51. remove_column :products, :show_flag
  52. remove_column :order_details, :size_name
  53. remove_column :order_details, :color_name
  54. end
  55. end