20120101000010_create_ticket.rb 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 null: false
  9. end
  10. add_index :ticket_state_types, [:name], unique: true
  11. create_table :ticket_states do |t|
  12. t.references :state_type, null: false
  13. t.column :name, :string, limit: 250, null: false
  14. t.column :next_state_id, :integer, null: true
  15. t.column :note, :string, limit: 250, null: true
  16. t.column :active, :boolean, null: false, default: true
  17. t.column :updated_by_id, :integer, null: false
  18. t.column :created_by_id, :integer, null: false
  19. t.timestamps null: false
  20. end
  21. add_index :ticket_states, [:name], unique: true
  22. create_table :ticket_priorities do |t|
  23. t.column :name, :string, limit: 250, null: false
  24. t.column :note, :string, limit: 250, null: true
  25. t.column :active, :boolean, null: false, default: true
  26. t.column :updated_by_id, :integer, null: false
  27. t.column :created_by_id, :integer, null: false
  28. t.timestamps null: false
  29. end
  30. add_index :ticket_priorities, [:name], unique: true
  31. create_table :tickets do |t|
  32. t.references :group, null: false
  33. t.references :priority, null: false
  34. t.references :state, null: false
  35. t.references :organization, null: true
  36. t.column :number, :string, limit: 60, null: false
  37. t.column :title, :string, limit: 250, null: false
  38. t.column :owner_id, :integer, null: false
  39. t.column :customer_id, :integer, null: false
  40. t.column :note, :string, limit: 250, null: true
  41. t.column :first_response, :timestamp, null: true
  42. t.column :first_response_escal_date, :timestamp, null: true
  43. t.column :first_response_sla_time, :timestamp, null: true
  44. t.column :first_response_in_min, :integer, null: true
  45. t.column :first_response_diff_in_min, :integer, null: true
  46. t.column :close_time, :timestamp, null: true
  47. t.column :close_time_escal_date, :timestamp, null: true
  48. t.column :close_time_sla_time, :timestamp, null: true
  49. t.column :close_time_in_min, :integer, null: true
  50. t.column :close_time_diff_in_min, :integer, null: true
  51. t.column :update_time_escal_date, :timestamp, null: true
  52. t.column :update_time_sla_time, :timestamp, null: true
  53. t.column :update_time_in_min, :integer, null: true
  54. t.column :update_time_diff_in_min, :integer, null: true
  55. t.column :last_contact, :timestamp, null: true
  56. t.column :last_contact_agent, :timestamp, null: true
  57. t.column :last_contact_customer, :timestamp, null: true
  58. t.column :create_article_type_id, :integer, null: true
  59. t.column :create_article_sender_id, :integer, null: true
  60. t.column :article_count, :integer, null: true
  61. t.column :escalation_time, :timestamp, null: true
  62. t.column :pending_time, :timestamp, null: true
  63. t.column :type, :string, limit: 100, null: true
  64. t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
  65. t.column :updated_by_id, :integer, null: false
  66. t.column :created_by_id, :integer, null: false
  67. t.timestamps null: false
  68. end
  69. add_index :tickets, [:state_id]
  70. add_index :tickets, [:priority_id]
  71. add_index :tickets, [:group_id]
  72. add_index :tickets, [:owner_id]
  73. add_index :tickets, [:customer_id]
  74. add_index :tickets, [:number], unique: true
  75. add_index :tickets, [:title]
  76. add_index :tickets, [:created_at]
  77. add_index :tickets, [:first_response]
  78. add_index :tickets, [:first_response_escal_date]
  79. add_index :tickets, [:first_response_in_min]
  80. add_index :tickets, [:first_response_diff_in_min]
  81. add_index :tickets, [:close_time]
  82. add_index :tickets, [:close_time_escal_date]
  83. add_index :tickets, [:close_time_in_min]
  84. add_index :tickets, [:close_time_diff_in_min]
  85. add_index :tickets, [:escalation_time]
  86. add_index :tickets, [:update_time_in_min]
  87. add_index :tickets, [:update_time_diff_in_min]
  88. add_index :tickets, [:last_contact]
  89. add_index :tickets, [:last_contact_agent]
  90. add_index :tickets, [:last_contact_customer]
  91. add_index :tickets, [:create_article_type_id]
  92. add_index :tickets, [:create_article_sender_id]
  93. add_index :tickets, [:created_by_id]
  94. add_index :tickets, [:pending_time]
  95. add_index :tickets, [:type]
  96. create_table :ticket_flags do |t|
  97. t.references :tickets, null: false
  98. t.column :key, :string, limit: 50, null: false
  99. t.column :value, :string, limit: 50, null: true
  100. t.column :created_by_id, :integer, null: false
  101. t.timestamps null: false
  102. end
  103. add_index :ticket_flags, [:tickets_id, :created_by_id]
  104. add_index :ticket_flags, [:tickets_id, :key]
  105. add_index :ticket_flags, [:tickets_id]
  106. add_index :ticket_flags, [:created_by_id]
  107. create_table :ticket_time_accounting do |t|
  108. t.references :tickets, null: false
  109. t.references :ticket_articles, null: true
  110. t.column :time_unit, :decimal, precision: 6, scale: 2, null: false
  111. t.column :created_by_id, :integer, null: false
  112. t.timestamps null: false
  113. end
  114. add_index :ticket_time_accounting, [:tickets_id]
  115. add_index :ticket_time_accounting, [:ticket_articles_id]
  116. add_index :ticket_time_accounting, [:created_by_id]
  117. create_table :ticket_article_types do |t|
  118. t.column :name, :string, limit: 250, null: false
  119. t.column :note, :string, limit: 250, null: true
  120. t.column :communication, :boolean, null: false
  121. t.column :active, :boolean, null: false, default: true
  122. t.column :updated_by_id, :integer, null: false
  123. t.column :created_by_id, :integer, null: false
  124. t.timestamps null: false
  125. end
  126. add_index :ticket_article_types, [:name], unique: true
  127. create_table :ticket_article_senders do |t|
  128. t.column :name, :string, limit: 250, null: false
  129. t.column :note, :string, limit: 250, null: true
  130. t.column :updated_by_id, :integer, null: false
  131. t.column :created_by_id, :integer, null: false
  132. t.timestamps null: false
  133. end
  134. add_index :ticket_article_senders, [:name], unique: true
  135. create_table :ticket_articles do |t|
  136. t.references :ticket, null: false
  137. t.references :type, null: false
  138. t.references :sender, null: false
  139. t.column :from, :string, limit: 3000, null: true
  140. t.column :to, :string, limit: 3000, null: true
  141. t.column :cc, :string, limit: 3000, null: true
  142. t.column :subject, :string, limit: 3000, null: true
  143. # t.column :reply_to, :string, :limit => 3000, :null => true
  144. t.column :message_id, :string, limit: 3000, null: true
  145. t.column :message_id_md5, :string, limit: 32, null: true
  146. t.column :in_reply_to, :string, limit: 3000, null: true
  147. t.column :content_type, :string, limit: 20, null: false, default: 'text/plain'
  148. t.column :references, :string, limit: 3200, null: true
  149. t.column :body, :text, limit: 4.megabytes + 1
  150. t.column :internal, :boolean, null: false, default: false
  151. t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
  152. t.column :updated_by_id, :integer, null: false
  153. t.column :created_by_id, :integer, null: false
  154. t.timestamps null: false
  155. end
  156. add_index :ticket_articles, [:ticket_id]
  157. add_index :ticket_articles, [:message_id_md5]
  158. add_index :ticket_articles, [:message_id_md5, :type_id], name: 'index_ticket_articles_message_id_md5_type_id'
  159. add_index :ticket_articles, [:created_by_id]
  160. add_index :ticket_articles, [:created_at]
  161. add_index :ticket_articles, [:internal]
  162. add_index :ticket_articles, [:type_id]
  163. add_index :ticket_articles, [:sender_id]
  164. create_table :ticket_article_flags do |t|
  165. t.references :ticket_articles, null: false
  166. t.column :key, :string, limit: 50, null: false
  167. t.column :value, :string, limit: 50, null: true
  168. t.column :created_by_id, :integer, null: false
  169. t.timestamps null: false
  170. end
  171. add_index :ticket_article_flags, [:ticket_articles_id, :created_by_id], name: 'index_ticket_article_flags_on_articles_id_and_created_by_id'
  172. add_index :ticket_article_flags, [:ticket_articles_id, :key]
  173. add_index :ticket_article_flags, [:ticket_articles_id]
  174. add_index :ticket_article_flags, [:created_by_id]
  175. create_table :ticket_counters do |t|
  176. t.column :content, :string, limit: 100, null: false
  177. t.column :generator, :string, limit: 100, null: false
  178. end
  179. add_index :ticket_counters, [:generator], unique: true
  180. create_table :overviews do |t|
  181. t.references :user, null: true
  182. t.references :role, null: false
  183. t.column :name, :string, limit: 250, null: false
  184. t.column :link, :string, limit: 250, null: false
  185. t.column :prio, :integer, null: false
  186. t.column :condition, :string, limit: 2500, null: false
  187. t.column :order, :string, limit: 2500, null: false
  188. t.column :group_by, :string, limit: 250, null: true
  189. t.column :organization_shared, :boolean, null: false, default: false
  190. t.column :view, :string, limit: 1000, null: false
  191. t.column :active, :boolean, null: false, default: true
  192. t.column :updated_by_id, :integer, null: false
  193. t.column :created_by_id, :integer, null: false
  194. t.timestamps null: false
  195. end
  196. add_index :overviews, [:user_id]
  197. add_index :overviews, [:name]
  198. create_table :overviews_groups, id: false do |t|
  199. t.integer :overview_id
  200. t.integer :group_id
  201. end
  202. add_index :overviews_groups, [:overview_id]
  203. add_index :overviews_groups, [:group_id]
  204. create_table :triggers do |t|
  205. t.column :name, :string, limit: 250, null: false
  206. t.column :key, :string, limit: 250, null: false
  207. t.column :value, :string, limit: 250, null: false
  208. end
  209. add_index :triggers, [:name]
  210. add_index :triggers, [:key]
  211. add_index :triggers, [:value]
  212. create_table :notifications do |t|
  213. t.column :subject, :string, limit: 250, null: false
  214. t.column :body, :string, limit: 8000, null: false
  215. t.column :content_type, :string, limit: 250, null: false
  216. t.column :active, :boolean, null: false, default: true
  217. t.column :note, :string, limit: 250, null: true
  218. t.timestamps null: false
  219. end
  220. create_table :link_types do |t|
  221. t.column :name, :string, limit: 250, null: false
  222. t.column :note, :string, limit: 250, null: true
  223. t.column :active, :boolean, null: false, default: true
  224. t.timestamps null: false
  225. end
  226. add_index :link_types, [:name], unique: true
  227. create_table :link_objects do |t|
  228. t.column :name, :string, limit: 250, null: false
  229. t.column :note, :string, limit: 250, null: true
  230. t.column :active, :boolean, null: false, default: true
  231. t.timestamps null: false
  232. end
  233. add_index :link_objects, [:name], unique: true
  234. create_table :links do |t|
  235. t.references :link_type, null: false
  236. t.column :link_object_source_id, :integer, null: false
  237. t.column :link_object_source_value, :integer, null: false
  238. t.column :link_object_target_id, :integer, null: false
  239. t.column :link_object_target_value, :integer, null: false
  240. t.timestamps null: false
  241. end
  242. 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'
  243. create_table :postmaster_filters do |t|
  244. t.column :name, :string, limit: 250, null: false
  245. t.column :channel, :string, limit: 250, null: false
  246. t.column :match, :string, limit: 5000, null: false
  247. t.column :perform, :string, limit: 5000, null: false
  248. t.column :active, :boolean, null: false, default: true
  249. t.column :note, :string, limit: 250, null: true
  250. t.column :updated_by_id, :integer, null: false
  251. t.column :created_by_id, :integer, null: false
  252. t.timestamps null: false
  253. end
  254. add_index :postmaster_filters, [:channel]
  255. create_table :text_modules do |t|
  256. t.references :user, null: true
  257. t.column :name, :string, limit: 250, null: false
  258. t.column :keywords, :string, limit: 500, null: true
  259. t.column :content, :string, limit: 5000, null: false
  260. t.column :note, :string, limit: 250, null: true
  261. t.column :active, :boolean, null: false, default: true
  262. t.column :updated_by_id, :integer, null: false
  263. t.column :created_by_id, :integer, null: false
  264. t.timestamps null: false
  265. end
  266. add_index :text_modules, [:user_id]
  267. add_index :text_modules, [:name]
  268. create_table :text_modules_groups, id: false do |t|
  269. t.integer :text_module_id
  270. t.integer :group_id
  271. end
  272. add_index :text_modules_groups, [:text_module_id]
  273. add_index :text_modules_groups, [:group_id]
  274. create_table :templates do |t|
  275. t.references :user, null: true
  276. t.column :name, :string, limit: 250, null: false
  277. t.column :options, :string, limit: 2500, null: false
  278. t.column :updated_by_id, :integer, null: false
  279. t.column :created_by_id, :integer, null: false
  280. t.timestamps null: false
  281. end
  282. add_index :templates, [:user_id]
  283. add_index :templates, [:name]
  284. create_table :templates_groups, id: false do |t|
  285. t.integer :template_id
  286. t.integer :group_id
  287. end
  288. add_index :templates_groups, [:template_id]
  289. add_index :templates_groups, [:group_id]
  290. create_table :channels do |t|
  291. t.references :group, null: true
  292. t.column :adapter, :string, limit: 100, null: false
  293. t.column :area, :string, limit: 100, null: false
  294. t.column :options, :string, limit: 2000, null: true
  295. t.column :active, :boolean, null: false, default: true
  296. t.column :updated_by_id, :integer, null: false
  297. t.column :created_by_id, :integer, null: false
  298. t.timestamps null: false
  299. end
  300. add_index :channels, [:area]
  301. add_index :channels, [:adapter]
  302. create_table :slas do |t|
  303. t.column :name, :string, limit: 150, null: true
  304. t.column :first_response_time, :integer, null: true
  305. t.column :update_time, :integer, null: true
  306. t.column :close_time, :integer, null: true
  307. t.column :condition, :string, limit: 5000, null: true
  308. t.column :data, :string, limit: 5000, null: true
  309. t.column :timezone, :string, limit: 50, null: true
  310. t.column :active, :boolean, null: false, default: true
  311. t.column :updated_by_id, :integer, null: false
  312. t.column :created_by_id, :integer, null: false
  313. t.timestamps null: false
  314. end
  315. add_index :slas, [:name], unique: true
  316. end
  317. def self.down
  318. drop_table :slas
  319. drop_table :channels
  320. drop_table :templates_groups
  321. drop_table :templates
  322. drop_table :text_modules_groups
  323. drop_table :text_modules
  324. drop_table :postmaster_filters
  325. drop_table :notifications
  326. drop_table :triggers
  327. drop_table :links
  328. drop_table :link_types
  329. drop_table :link_objects
  330. drop_table :overviews
  331. drop_table :ticket_counters
  332. drop_table :ticket_time_accounting
  333. drop_table :ticket_article_flags
  334. drop_table :ticket_articles
  335. drop_table :ticket_article_types
  336. drop_table :ticket_article_senders
  337. drop_table :ticket_flags
  338. drop_table :tickets
  339. drop_table :ticket_priorities
  340. drop_table :ticket_states
  341. drop_table :ticket_state_types
  342. end
  343. end