20120101000010_create_ticket.rb 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. class CreateTicket < ActiveRecord::Migration
  2. def up
  3. create_table :ticket_state_types do |t|
  4. t.column :name, :string, :limit => 250, :null => false
  5. t.column :note, :string, :limit => 250, :null => true
  6. t.column :updated_by_id, :integer, :null => false
  7. t.column :created_by_id, :integer, :null => false
  8. t.timestamps
  9. end
  10. add_index :ticket_state_types, [:name], :unique => true
  11. create_table :ticket_states do |t|
  12. t.references :ticket_state_type, :null => false
  13. t.column :name, :string, :limit => 250, :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 :ticket_states, [:name], :unique => true
  21. create_table :ticket_priorities do |t|
  22. t.column :name, :string, :limit => 250, :null => false
  23. t.column :note, :string, :limit => 250, :null => true
  24. t.column :active, :boolean, :null => false, :default => true
  25. t.column :updated_by_id, :integer, :null => false
  26. t.column :created_by_id, :integer, :null => false
  27. t.timestamps
  28. end
  29. add_index :ticket_priorities, [:name], :unique => true
  30. create_table :tickets do |t|
  31. t.references :group, :null => false
  32. t.references :ticket_priority, :null => false
  33. t.references :ticket_state, :null => false
  34. t.column :number, :string, :limit => 60, :null => false
  35. t.column :title, :string, :limit => 250, :null => false
  36. t.column :owner_id, :integer, :null => false
  37. t.column :customer_id, :integer, :null => false
  38. t.column :note, :string, :limit => 250, :null => true
  39. t.column :first_response, :timestamp, :null => true
  40. t.column :last_contact, :timestamp, :null => true
  41. t.column :last_contact_agent, :timestamp, :null => true
  42. t.column :last_contact_customer, :timestamp, :null => true
  43. t.column :close_time, :timestamp, :null => true
  44. t.column :updated_by_id, :integer, :null => false
  45. t.column :created_by_id, :integer, :null => false
  46. t.timestamps
  47. end
  48. add_index :tickets, [:ticket_state_id]
  49. add_index :tickets, [:ticket_priority_id]
  50. add_index :tickets, [:group_id]
  51. add_index :tickets, [:owner_id]
  52. add_index :tickets, [:customer_id]
  53. add_index :tickets, [:number], :unique => true
  54. add_index :tickets, [:title]
  55. add_index :tickets, [:created_at]
  56. add_index :tickets, [:first_response]
  57. add_index :tickets, [:last_contact]
  58. add_index :tickets, [:last_contact_agent]
  59. add_index :tickets, [:last_contact_customer]
  60. add_index :tickets, [:close_time]
  61. add_index :tickets, [:created_by_id]
  62. create_table :ticket_flags do |t|
  63. t.references :tickets, :null => false
  64. t.column :key, :string, :limit => 50, :null => false
  65. t.column :value, :string, :limit => 50, :null => true
  66. t.column :created_by_id, :integer, :null => false
  67. t.timestamps
  68. end
  69. add_index :ticket_flags, [:tickets_id, :created_by_id]
  70. add_index :ticket_flags, [:tickets_id, :key]
  71. add_index :ticket_flags, [:tickets_id]
  72. add_index :ticket_flags, [:created_by_id]
  73. create_table :ticket_time_accounting do |t|
  74. t.references :tickets, :null => false
  75. t.references :ticket_articles, :null => true
  76. t.column :time_unit, :decimal, :precision => 6, :scale => 2, :null => false
  77. t.column :created_by_id, :integer, :null => false
  78. t.timestamps
  79. end
  80. add_index :ticket_time_accounting, [:tickets_id]
  81. add_index :ticket_time_accounting, [:ticket_articles_id]
  82. add_index :ticket_time_accounting, [:created_by_id]
  83. create_table :ticket_article_types do |t|
  84. t.column :name, :string, :limit => 250, :null => false
  85. t.column :note, :string, :limit => 250, :null => true
  86. t.column :communication, :boolean, :null => false
  87. t.column :active, :boolean, :null => false, :default => true
  88. t.column :updated_by_id, :integer, :null => false
  89. t.column :created_by_id, :integer, :null => false
  90. t.timestamps
  91. end
  92. add_index :ticket_article_types, [:name], :unique => true
  93. create_table :ticket_article_senders do |t|
  94. t.column :name, :string, :limit => 250, :null => false
  95. t.column :note, :string, :limit => 250, :null => true
  96. t.column :updated_by_id, :integer, :null => false
  97. t.column :created_by_id, :integer, :null => false
  98. t.timestamps
  99. end
  100. add_index :ticket_article_senders, [:name], :unique => true
  101. create_table :ticket_articles do |t|
  102. t.references :ticket, :null => false
  103. t.references :ticket_article_type, :null => false
  104. t.references :ticket_article_sender, :null => false
  105. t.column :from, :string, :limit => 3000, :null => true
  106. t.column :to, :string, :limit => 3000, :null => true
  107. t.column :cc, :string, :limit => 3000, :null => true
  108. t.column :subject, :string, :limit => 3000, :null => true
  109. # t.column :reply_to, :string, :limit => 3000, :null => true
  110. t.column :message_id, :string, :limit => 3000, :null => true
  111. t.column :message_id_md5, :string, :limit => 32, :null => true
  112. t.column :in_reply_to, :string, :limit => 3000, :null => true
  113. t.column :references, :string, :limit => 3200, :null => true
  114. t.column :body, :text, :null => true
  115. t.column :internal, :boolean, :null => false, :default => false
  116. t.column :updated_by_id, :integer, :null => false
  117. t.column :created_by_id, :integer, :null => false
  118. t.timestamps
  119. end
  120. add_index :ticket_articles, [:ticket_id]
  121. add_index :ticket_articles, [:message_id_md5]
  122. add_index :ticket_articles, [:message_id_md5, :ticket_article_type_id], :name => 'index_ticket_articles_message_id_md5_type_id'
  123. add_index :ticket_articles, [:created_by_id]
  124. add_index :ticket_articles, [:internal]
  125. add_index :ticket_articles, [:ticket_article_type_id]
  126. add_index :ticket_articles, [:ticket_article_sender_id]
  127. create_table :ticket_article_flags do |t|
  128. t.references :ticket_articles, :null => false
  129. t.column :key, :string, :limit => 50, :null => false
  130. t.column :value, :string, :limit => 50, :null => true
  131. t.column :created_by_id, :integer, :null => false
  132. t.timestamps
  133. end
  134. add_index :ticket_article_flags, [:ticket_articles_id, :created_by_id], :name => 'index_ticket_article_flags_on_articles_id_and_created_by_id'
  135. add_index :ticket_article_flags, [:ticket_articles_id, :key]
  136. add_index :ticket_article_flags, [:ticket_articles_id]
  137. add_index :ticket_article_flags, [:created_by_id]
  138. create_table :overviews do |t|
  139. t.references :user, :null => true
  140. t.references :role, :null => false
  141. t.column :name, :string, :limit => 250, :null => false
  142. t.column :meta, :string, :limit => 1000, :null => false
  143. t.column :condition, :string, :limit => 2500, :null => false
  144. t.column :order, :string, :limit => 2500, :null => false
  145. t.column :group_by, :string, :limit => 250, :null => true
  146. t.column :view, :string, :limit => 1000, :null => false
  147. t.column :updated_by_id, :integer, :null => false
  148. t.column :created_by_id, :integer, :null => false
  149. t.timestamps
  150. end
  151. add_index :overviews, [:user_id]
  152. add_index :overviews, [:name]
  153. create_table :overviews_groups, :id => false do |t|
  154. t.integer :overview_id
  155. t.integer :group_id
  156. end
  157. add_index :overviews_groups, [:overview_id]
  158. add_index :overviews_groups, [:group_id]
  159. create_table :triggers do |t|
  160. t.column :name, :string, :limit => 250, :null => false
  161. t.column :key, :string, :limit => 250, :null => false
  162. t.column :value, :string, :limit => 250, :null => false
  163. end
  164. add_index :triggers, [:name]
  165. add_index :triggers, [:key]
  166. add_index :triggers, [:value]
  167. create_table :notifications do |t|
  168. t.column :subject, :string, :limit => 250, :null => false
  169. t.column :body, :string, :limit => 8000, :null => false
  170. t.column :content_type, :string, :limit => 250, :null => false
  171. t.column :active, :boolean, :null => false, :default => true
  172. t.column :note, :string, :limit => 250, :null => true
  173. t.timestamps
  174. end
  175. create_table :link_types do |t|
  176. t.column :name, :string, :limit => 250, :null => false
  177. t.column :note, :string, :limit => 250, :null => true
  178. t.column :active, :boolean, :null => false, :default => true
  179. t.timestamps
  180. end
  181. add_index :link_types, [:name], :unique => true
  182. create_table :link_objects do |t|
  183. t.column :name, :string, :limit => 250, :null => false
  184. t.column :note, :string, :limit => 250, :null => true
  185. t.column :active, :boolean, :null => false, :default => true
  186. t.timestamps
  187. end
  188. add_index :link_objects, [:name], :unique => true
  189. create_table :links do |t|
  190. t.references :link_type, :null => false
  191. t.column :link_object_source_id, :integer, :null => false
  192. t.column :link_object_source_value, :integer, :null => false
  193. t.column :link_object_target_id, :integer, :null => false
  194. t.column :link_object_target_value, :integer, :null => false
  195. t.timestamps
  196. end
  197. add_index :links, [:link_object_source_id, :link_object_source_value, :link_object_target_id, :link_object_target_value, :link_type_id], :unique => true, :name => 'links_uniq_total'
  198. end
  199. def self.down
  200. drop_table :notifications
  201. drop_table :triggers
  202. drop_table :links
  203. drop_table :link_types
  204. drop_table :link_objects
  205. drop_table :overviews
  206. drop_table :ticket_time_accounting
  207. drop_table :ticket_article_flags
  208. drop_table :ticket_articles
  209. drop_table :ticket_article_types
  210. drop_table :ticket_article_senders
  211. drop_table :ticket_flags
  212. drop_table :tickets
  213. drop_table :ticket_priorities
  214. drop_table :ticket_states
  215. drop_table :ticket_state_types
  216. end
  217. end