20200808124641_create_product_attrs.rb 1.5 KB

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