20120101000010_create_ticket.rb 10 KB

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