20120101000020_create_network.rb 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. class CreateNetwork < ActiveRecord::Migration
  2. def up
  3. create_table :networks do |t|
  4. t.column :name, :string, :limit => 100, :null => false
  5. t.column :note, :string, :limit => 250, :null => true
  6. t.column :active, :boolean, :null => false, :default => true
  7. t.column :updated_by_id, :integer, :null => false
  8. t.column :created_by_id, :integer, :null => false
  9. t.timestamps
  10. end
  11. add_index :networks, [:name], :unique => true
  12. create_table :network_category_types do |t|
  13. t.column :name, :string, :limit => 100, :null => false
  14. t.column :note, :string, :limit => 250, :null => true
  15. t.column :active, :boolean, :null => false, :default => true
  16. t.column :updated_by_id, :integer, :null => false
  17. t.column :created_by_id, :integer, :null => false
  18. t.timestamps
  19. end
  20. add_index :network_category_types, [:name], :unique => true
  21. create_table :network_privacies do |t|
  22. t.column :name, :string, :limit => 100, :null => false
  23. t.column :key, :string, :limit => 250, :null => false
  24. t.column :updated_by_id, :integer, :null => false
  25. t.column :created_by_id, :integer, :null => false
  26. t.timestamps
  27. end
  28. add_index :network_privacies, [:name], :unique => true
  29. create_table :network_categories do |t|
  30. t.references :network_category_type, :null => false
  31. t.references :network_privacy, :null => false
  32. t.references :network, :null => false
  33. t.column :name, :string, :limit => 200, :null => false
  34. t.column :note, :string, :limit => 250, :null => true
  35. t.column :allow_comments, :boolean, :null => false, :default => true
  36. t.column :active, :boolean, :null => false, :default => true
  37. t.column :updated_by_id, :integer, :null => false
  38. t.column :created_by_id, :integer, :null => false
  39. t.timestamps
  40. end
  41. add_index :network_categories, [:network_id]
  42. create_table :network_categories_moderator_users, :id => false do |t|
  43. t.integer :user_id
  44. t.integer :network_category_id
  45. end
  46. create_table :network_items do |t|
  47. t.references :network_category, :null => false
  48. t.column :title, :string, :limit => 200, :null => false
  49. t.column :body, :string, :limit => 20000, :null => false
  50. t.column :updated_by_id, :integer, :null => false
  51. t.column :created_by_id, :integer, :null => false
  52. t.timestamps
  53. end
  54. add_index :network_items, [:network_category_id]
  55. create_table :network_item_comments do |t|
  56. t.references :network_item, :null => false
  57. t.column :body, :string, :limit => 20000, :null => false
  58. t.column :updated_by_id, :integer, :null => false
  59. t.column :created_by_id, :integer, :null => false
  60. t.timestamps
  61. end
  62. add_index :network_item_comments, [:network_item_id]
  63. create_table :network_item_plus do |t|
  64. t.references :network_item, :null => false
  65. t.column :updated_by_id, :integer, :null => false
  66. t.column :created_by_id, :integer, :null => false
  67. t.timestamps
  68. end
  69. add_index :network_item_plus, [:network_item_id, :created_by_id], :unique => true
  70. create_table :network_category_subscriptions do |t|
  71. t.references :network_categories, :null => false
  72. t.column :updated_by_id, :integer, :null => false
  73. t.column :created_by_id, :integer, :null => false
  74. t.timestamps
  75. end
  76. add_index :network_category_subscriptions, [:network_categories_id, :created_by_id], :unique => true, :name => 'index_network_category_subscriptions_on_network_c_i_and_c'
  77. create_table :network_item_subscriptions do |t|
  78. t.references :network_item, :null => false
  79. t.column :updated_by_id, :integer, :null => false
  80. t.column :created_by_id, :integer, :null => false
  81. t.timestamps
  82. end
  83. add_index :network_item_subscriptions, [:network_item_id, :created_by_id], :unique => true, :name => 'index_network_item_subscriptions_on_item_id_and_created_by_id'
  84. end
  85. def down
  86. drop_table :network_item_subscriptions
  87. drop_table :network_category_subscriptions
  88. drop_table :network_categories_moderator_users
  89. drop_table :network_item_plus
  90. drop_table :network_item_comments
  91. drop_table :network_items
  92. drop_table :network_categories
  93. drop_table :network_privacies
  94. drop_table :network_category_types
  95. drop_table :networks
  96. end
  97. end