20200808124641_create_product_attrs.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. t.timestamps
  21. end
  22. add_index :product_attrs, :attr_key_id
  23. #主商品规格配置表
  24. create_table :product_attr_configs do |t|
  25. # 主商品ID
  26. t.column :product_id, :integer, :limit => 8, :default => 0
  27. # 规格ID
  28. t.column :attr_key_id, :integer, :limit => 8, :default => 0
  29. # 类型
  30. t.column :size_type, :string, :limit => 64
  31. t.timestamps
  32. end
  33. add_index :product_attr_configs, :product_id
  34. add_index :product_attr_configs, :attr_key_id
  35. add_column :products, :size_id, :integer
  36. add_column :products, :color_id, :integer
  37. add_column :products, :relate_product_id, :integer
  38. add_column :products, :show_flag, :boolean
  39. end
  40. def down
  41. drop_table :product_attr_keys
  42. drop_table :product_attrs
  43. drop_table :product_attr_configs
  44. remove_column :products, :size_id
  45. remove_column :products, :color_id
  46. remove_column :products, :relate_product_id
  47. remove_column :products, :show_flag
  48. end
  49. end