20120101000050_create_history.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. class CreateHistory < ActiveRecord::Migration
  2. def up
  3. create_table :histories do |t|
  4. t.references :history_type, :null => false
  5. t.references :history_object, :null => false
  6. t.references :history_attribute, :null => true
  7. t.column :o_id, :integer, :null => false
  8. t.column :related_o_id, :integer, :null => true
  9. t.column :related_history_object_id, :integer, :null => true
  10. t.column :id_to, :integer, :null => true
  11. t.column :id_from, :integer, :null => true
  12. t.column :value_from, :string, :limit => 250, :null => true
  13. t.column :value_to, :string, :limit => 250, :null => true
  14. t.column :created_by_id, :integer, :null => false
  15. t.timestamps
  16. end
  17. add_index :histories, [:o_id]
  18. add_index :histories, [:created_by_id]
  19. add_index :histories, [:created_at]
  20. add_index :histories, [:history_object_id]
  21. add_index :histories, [:history_attribute_id]
  22. add_index :histories, [:history_type_id]
  23. add_index :histories, [:id_to]
  24. add_index :histories, [:id_from]
  25. add_index :histories, [:value_from]
  26. add_index :histories, [:value_to]
  27. create_table :history_types do |t|
  28. t.column :name, :string, :limit => 250, :null => false
  29. t.timestamps
  30. end
  31. add_index :history_types, [:name], :unique => true
  32. create_table :history_objects do |t|
  33. t.column :name, :string, :limit => 250, :null => false
  34. t.column :note, :string, :limit => 250, :null => true
  35. t.timestamps
  36. end
  37. add_index :history_objects, [:name], :unique => true
  38. create_table :history_attributes do |t|
  39. t.column :name, :string, :limit => 250, :null => false
  40. t.timestamps
  41. end
  42. add_index :history_attributes, [:name], :unique => true
  43. end
  44. def down
  45. drop_table :histories
  46. drop_table :history_attributes
  47. drop_table :history_objects
  48. drop_table :history_types
  49. end
  50. end