20120101000010_create_ticket.rb 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 limit: 3, 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 :ignore_escalation, :boolean, null: false, default: false
  16. t.column :default_create, :boolean, null: false, default: false
  17. t.column :default_follow_up, :boolean, null: false, default: false
  18. t.column :note, :string, limit: 250, null: true
  19. t.column :active, :boolean, null: false, default: true
  20. t.column :updated_by_id, :integer, null: false
  21. t.column :created_by_id, :integer, null: false
  22. t.timestamps limit: 3, null: false
  23. end
  24. add_index :ticket_states, [:name], unique: true
  25. add_index :ticket_states, [:default_create]
  26. add_index :ticket_states, [:default_follow_up]
  27. create_table :ticket_priorities do |t|
  28. t.column :name, :string, limit: 250, null: false
  29. t.column :default_create, :boolean, null: false, default: false
  30. t.column :note, :string, limit: 250, null: true
  31. t.column :active, :boolean, null: false, default: true
  32. t.column :updated_by_id, :integer, null: false
  33. t.column :created_by_id, :integer, null: false
  34. t.timestamps limit: 3, null: false
  35. end
  36. add_index :ticket_priorities, [:name], unique: true
  37. add_index :ticket_priorities, [:default_create]
  38. create_table :tickets do |t|
  39. t.references :group, null: false
  40. t.references :priority, null: false
  41. t.references :state, null: false
  42. t.references :organization, null: true
  43. t.column :number, :string, limit: 60, null: false
  44. t.column :title, :string, limit: 250, null: false
  45. t.column :owner_id, :integer, null: false
  46. t.column :customer_id, :integer, null: false
  47. t.column :note, :string, limit: 250, null: true
  48. t.column :first_response_at, :timestamp, limit: 3, null: true
  49. t.column :first_response_escalation_at, :timestamp, limit: 3, null: true
  50. t.column :first_response_in_min, :integer, null: true
  51. t.column :first_response_diff_in_min, :integer, null: true
  52. t.column :close_at, :timestamp, limit: 3, null: true
  53. t.column :close_escalation_at, :timestamp, limit: 3, null: true
  54. t.column :close_in_min, :integer, null: true
  55. t.column :close_diff_in_min, :integer, null: true
  56. t.column :update_escalation_at, :timestamp, limit: 3, null: true
  57. t.column :update_in_min, :integer, null: true
  58. t.column :update_diff_in_min, :integer, null: true
  59. t.column :last_contact_at, :timestamp, limit: 3, null: true
  60. t.column :last_contact_agent_at, :timestamp, limit: 3, null: true
  61. t.column :last_contact_customer_at, :timestamp, limit: 3, null: true
  62. t.column :create_article_type_id, :integer, null: true
  63. t.column :create_article_sender_id, :integer, null: true
  64. t.column :article_count, :integer, null: true
  65. t.column :escalation_at, :timestamp, limit: 3, null: true
  66. t.column :pending_time, :timestamp, limit: 3, null: true
  67. t.column :type, :string, limit: 100, null: true
  68. t.column :time_unit, :decimal, precision: 6, scale: 2, null: true
  69. t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
  70. t.column :updated_by_id, :integer, null: false
  71. t.column :created_by_id, :integer, null: false
  72. t.timestamps limit: 3, null: false
  73. end
  74. add_index :tickets, [:state_id]
  75. add_index :tickets, [:priority_id]
  76. add_index :tickets, [:group_id]
  77. add_index :tickets, [:owner_id]
  78. add_index :tickets, [:customer_id]
  79. add_index :tickets, [:number], unique: true
  80. add_index :tickets, [:title]
  81. add_index :tickets, [:created_at]
  82. add_index :tickets, [:first_response_at]
  83. add_index :tickets, [:first_response_escalation_at]
  84. add_index :tickets, [:first_response_in_min]
  85. add_index :tickets, [:first_response_diff_in_min]
  86. add_index :tickets, [:close_at]
  87. add_index :tickets, [:close_escalation_at]
  88. add_index :tickets, [:close_in_min]
  89. add_index :tickets, [:close_diff_in_min]
  90. add_index :tickets, [:escalation_at]
  91. add_index :tickets, [:update_in_min]
  92. add_index :tickets, [:update_diff_in_min]
  93. add_index :tickets, [:last_contact_at]
  94. add_index :tickets, [:last_contact_agent_at]
  95. add_index :tickets, [:last_contact_customer_at]
  96. add_index :tickets, [:create_article_type_id]
  97. add_index :tickets, [:create_article_sender_id]
  98. add_index :tickets, [:created_by_id]
  99. add_index :tickets, [:pending_time]
  100. add_index :tickets, [:type]
  101. add_index :tickets, [:time_unit]
  102. create_table :ticket_flags do |t|
  103. t.references :tickets, null: false
  104. t.column :key, :string, limit: 50, null: false
  105. t.column :value, :string, limit: 50, null: true
  106. t.column :created_by_id, :integer, null: false
  107. t.timestamps limit: 3, null: false
  108. end
  109. add_index :ticket_flags, [:tickets_id, :created_by_id]
  110. add_index :ticket_flags, [:tickets_id, :key]
  111. add_index :ticket_flags, [:tickets_id]
  112. add_index :ticket_flags, [:created_by_id]
  113. create_table :ticket_time_accountings do |t|
  114. t.references :ticket, null: false
  115. t.references :ticket_article, null: true
  116. t.column :time_unit, :decimal, precision: 6, scale: 2, null: false
  117. t.column :created_by_id, :integer, null: false
  118. t.timestamps limit: 3, null: false
  119. end
  120. add_index :ticket_time_accountings, [:ticket_id]
  121. add_index :ticket_time_accountings, [:ticket_article_id]
  122. add_index :ticket_time_accountings, [:created_by_id]
  123. add_index :ticket_time_accountings, [:time_unit]
  124. create_table :ticket_article_types do |t|
  125. t.column :name, :string, limit: 250, null: false
  126. t.column :note, :string, limit: 250, null: true
  127. t.column :communication, :boolean, null: false
  128. t.column :active, :boolean, null: false, default: true
  129. t.column :updated_by_id, :integer, null: false
  130. t.column :created_by_id, :integer, null: false
  131. t.timestamps limit: 3, null: false
  132. end
  133. add_index :ticket_article_types, [:name], unique: true
  134. create_table :ticket_article_senders do |t|
  135. t.column :name, :string, limit: 250, null: false
  136. t.column :note, :string, limit: 250, null: true
  137. t.column :updated_by_id, :integer, null: false
  138. t.column :created_by_id, :integer, null: false
  139. t.timestamps limit: 3, null: false
  140. end
  141. add_index :ticket_article_senders, [:name], unique: true
  142. create_table :ticket_articles do |t|
  143. t.references :ticket, null: false
  144. t.references :type, null: false
  145. t.references :sender, null: false
  146. t.column :from, :string, limit: 3000, null: true
  147. t.column :to, :string, limit: 3000, null: true
  148. t.column :cc, :string, limit: 3000, null: true
  149. t.column :subject, :string, limit: 3000, null: true
  150. # t.column :reply_to, :string, :limit => 3000, :null => true
  151. t.column :message_id, :string, limit: 3000, null: true
  152. t.column :message_id_md5, :string, limit: 32, null: true
  153. t.column :in_reply_to, :string, limit: 3000, null: true
  154. t.column :content_type, :string, limit: 20, null: false, default: 'text/plain'
  155. t.column :references, :string, limit: 3200, null: true
  156. t.column :body, :text, limit: 20.megabytes + 1, null: false
  157. t.column :internal, :boolean, null: false, default: false
  158. t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
  159. t.column :updated_by_id, :integer, null: false
  160. t.column :created_by_id, :integer, null: false
  161. t.timestamps limit: 3, null: false
  162. end
  163. add_index :ticket_articles, [:ticket_id]
  164. add_index :ticket_articles, [:message_id_md5]
  165. add_index :ticket_articles, [:message_id_md5, :type_id], name: 'index_ticket_articles_message_id_md5_type_id'
  166. add_index :ticket_articles, [:created_by_id]
  167. add_index :ticket_articles, [:created_at]
  168. add_index :ticket_articles, [:internal]
  169. add_index :ticket_articles, [:type_id]
  170. add_index :ticket_articles, [:sender_id]
  171. create_table :ticket_article_flags do |t|
  172. t.references :ticket_articles, null: false
  173. t.column :key, :string, limit: 50, null: false
  174. t.column :value, :string, limit: 50, null: true
  175. t.column :created_by_id, :integer, null: false
  176. t.timestamps limit: 3, null: false
  177. end
  178. add_index :ticket_article_flags, [:ticket_articles_id, :created_by_id], name: 'index_ticket_article_flags_on_articles_id_and_created_by_id'
  179. add_index :ticket_article_flags, [:ticket_articles_id, :key]
  180. add_index :ticket_article_flags, [:ticket_articles_id]
  181. add_index :ticket_article_flags, [:created_by_id]
  182. create_table :ticket_counters do |t|
  183. t.column :content, :string, limit: 100, null: false
  184. t.column :generator, :string, limit: 100, null: false
  185. end
  186. add_index :ticket_counters, [:generator], unique: true
  187. create_table :overviews do |t|
  188. t.references :role, null: false
  189. t.column :name, :string, limit: 250, null: false
  190. t.column :link, :string, limit: 250, null: false
  191. t.column :prio, :integer, null: false
  192. t.column :condition, :text, limit: 500.kilobytes + 1, null: false
  193. t.column :order, :string, limit: 2500, null: false
  194. t.column :group_by, :string, limit: 250, null: true
  195. t.column :organization_shared, :boolean, null: false, default: false
  196. t.column :view, :string, limit: 1000, null: false
  197. t.column :active, :boolean, null: false, default: true
  198. t.column :updated_by_id, :integer, null: false
  199. t.column :created_by_id, :integer, null: false
  200. t.timestamps limit: 3, null: false
  201. end
  202. add_index :overviews, [:name]
  203. create_table :overviews_users, id: false do |t|
  204. t.integer :overview_id
  205. t.integer :user_id
  206. end
  207. add_index :overviews_users, [:overview_id]
  208. add_index :overviews_users, [:user_id]
  209. create_table :overviews_groups, id: false do |t|
  210. t.integer :overview_id
  211. t.integer :group_id
  212. end
  213. add_index :overviews_groups, [:overview_id]
  214. add_index :overviews_groups, [:group_id]
  215. create_table :triggers do |t|
  216. t.column :name, :string, limit: 250, null: false
  217. t.column :condition, :text, limit: 500.kilobytes + 1, null: false
  218. t.column :perform, :text, limit: 500.kilobytes + 1, null: false
  219. t.column :disable_notification, :boolean, null: false, default: true
  220. t.column :note, :string, limit: 250, null: true
  221. t.column :active, :boolean, null: false, default: true
  222. t.column :updated_by_id, :integer, null: false
  223. t.column :created_by_id, :integer, null: false
  224. t.timestamps limit: 3, null: false
  225. end
  226. add_index :triggers, [:name], unique: true
  227. create_table :jobs do |t|
  228. t.column :name, :string, limit: 250, null: false
  229. t.column :timeplan, :string, limit: 2500, null: false
  230. t.column :condition, :text, limit: 500.kilobytes + 1, null: false
  231. t.column :perform, :text, limit: 500.kilobytes + 1, null: false
  232. t.column :disable_notification, :boolean, null: false, default: true
  233. t.column :last_run_at, :timestamp, limit: 3, null: true
  234. t.column :next_run_at, :timestamp, limit: 3, null: true
  235. t.column :running, :boolean, null: false, default: false
  236. t.column :processed, :integer, null: false, default: 0
  237. t.column :matching, :integer, null: false
  238. t.column :pid, :string, limit: 250, null: true
  239. t.column :note, :string, limit: 250, null: true
  240. t.column :active, :boolean, null: false, default: false
  241. t.column :updated_by_id, :integer, null: false
  242. t.column :created_by_id, :integer, null: false
  243. t.timestamps limit: 3, null: false
  244. end
  245. add_index :jobs, [:name], unique: true
  246. create_table :notifications do |t|
  247. t.column :subject, :string, limit: 250, null: false
  248. t.column :body, :string, limit: 8000, null: false
  249. t.column :content_type, :string, limit: 250, null: false
  250. t.column :active, :boolean, null: false, default: true
  251. t.column :note, :string, limit: 250, null: true
  252. t.timestamps limit: 3, null: false
  253. end
  254. create_table :link_types do |t|
  255. t.column :name, :string, limit: 250, null: false
  256. t.column :note, :string, limit: 250, null: true
  257. t.column :active, :boolean, null: false, default: true
  258. t.timestamps limit: 3, null: false
  259. end
  260. add_index :link_types, [:name], unique: true
  261. create_table :link_objects do |t|
  262. t.column :name, :string, limit: 250, null: false
  263. t.column :note, :string, limit: 250, null: true
  264. t.column :active, :boolean, null: false, default: true
  265. t.timestamps limit: 3, null: false
  266. end
  267. add_index :link_objects, [:name], unique: true
  268. create_table :links do |t|
  269. t.references :link_type, null: false
  270. t.column :link_object_source_id, :integer, null: false
  271. t.column :link_object_source_value, :integer, null: false
  272. t.column :link_object_target_id, :integer, null: false
  273. t.column :link_object_target_value, :integer, null: false
  274. t.timestamps limit: 3, null: false
  275. end
  276. 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'
  277. create_table :postmaster_filters do |t|
  278. t.column :name, :string, limit: 250, null: false
  279. t.column :channel, :string, limit: 250, null: false
  280. t.column :match, :text, limit: 500.kilobytes + 1, null: false
  281. t.column :perform, :text, limit: 500.kilobytes + 1, null: false
  282. t.column :active, :boolean, null: false, default: true
  283. t.column :note, :string, limit: 250, null: true
  284. t.column :updated_by_id, :integer, null: false
  285. t.column :created_by_id, :integer, null: false
  286. t.timestamps limit: 3, null: false
  287. end
  288. add_index :postmaster_filters, [:channel]
  289. create_table :text_modules do |t|
  290. t.references :user, null: true
  291. t.column :name, :string, limit: 250, null: false
  292. t.column :keywords, :string, limit: 500, null: true
  293. t.column :content, :text, limit: 10.megabytes + 1, null: false
  294. t.column :note, :string, limit: 250, null: true
  295. t.column :active, :boolean, null: false, default: true
  296. t.column :foreign_id, :integer, null: true
  297. t.column :updated_by_id, :integer, null: false
  298. t.column :created_by_id, :integer, null: false
  299. t.timestamps limit: 3, null: false
  300. end
  301. add_index :text_modules, [:user_id]
  302. add_index :text_modules, [:name]
  303. create_table :text_modules_groups, id: false do |t|
  304. t.integer :text_module_id
  305. t.integer :group_id
  306. end
  307. add_index :text_modules_groups, [:text_module_id]
  308. add_index :text_modules_groups, [:group_id]
  309. create_table :templates do |t|
  310. t.references :user, null: true
  311. t.column :name, :string, limit: 250, null: false
  312. t.column :options, :text, limit: 10.megabytes + 1, null: false
  313. t.column :updated_by_id, :integer, null: false
  314. t.column :created_by_id, :integer, null: false
  315. t.timestamps limit: 3, null: false
  316. end
  317. add_index :templates, [:user_id]
  318. add_index :templates, [:name]
  319. create_table :templates_groups, id: false do |t|
  320. t.integer :template_id
  321. t.integer :group_id
  322. end
  323. add_index :templates_groups, [:template_id]
  324. add_index :templates_groups, [:group_id]
  325. create_table :channels do |t|
  326. t.references :group, null: true
  327. t.column :area, :string, limit: 100, null: false
  328. t.column :options, :text, limit: 500.kilobytes + 1, null: true
  329. t.column :active, :boolean, null: false, default: true
  330. t.column :preferences, :string, limit: 2000, null: true
  331. t.column :last_log_in, :text, limit: 500.kilobytes + 1, null: true
  332. t.column :last_log_out, :text, limit: 500.kilobytes + 1, null: true
  333. t.column :status_in, :string, limit: 100, null: true
  334. t.column :status_out, :string, limit: 100, null: true
  335. t.column :updated_by_id, :integer, null: false
  336. t.column :created_by_id, :integer, null: false
  337. t.timestamps limit: 3, null: false
  338. end
  339. add_index :channels, [:area]
  340. create_table :slas do |t|
  341. t.column :name, :string, limit: 150, null: true
  342. t.column :calendar_id, :integer, null: false
  343. t.column :first_response_time, :integer, null: true
  344. t.column :update_time, :integer, null: true
  345. t.column :solution_time, :integer, null: true
  346. t.column :condition, :text, limit: 500.kilobytes + 1, null: true
  347. t.column :updated_by_id, :integer, null: false
  348. t.column :created_by_id, :integer, null: false
  349. t.timestamps limit: 3, null: false
  350. end
  351. add_index :slas, [:name], unique: true
  352. create_table :macros do |t|
  353. t.string :name, limit: 250, null: true
  354. t.text :perform, limit: 500.kilobytes + 1, null: false
  355. t.boolean :active, null: false, default: true
  356. t.string :note, limit: 250, null: true
  357. t.integer :updated_by_id, null: false
  358. t.integer :created_by_id, null: false
  359. t.timestamps limit: 3, null: false
  360. end
  361. add_index :macros, [:name], unique: true
  362. create_table :chats do |t|
  363. t.string :name, limit: 250, null: true
  364. t.integer :max_queue, null: false, default: 5
  365. t.string :note, limit: 250, null: true
  366. t.boolean :active, null: false, default: true
  367. t.boolean :public, null: false, default: false
  368. t.string :preferences, limit: 5000, null: true
  369. t.integer :updated_by_id, null: false
  370. t.integer :created_by_id, null: false
  371. t.timestamps limit: 3, null: false
  372. end
  373. add_index :chats, [:name], unique: true
  374. create_table :chat_topics do |t|
  375. t.integer :chat_id, null: false
  376. t.string :name, limit: 250, null: false
  377. t.string :note, limit: 250, null: true
  378. t.integer :updated_by_id, null: false
  379. t.integer :created_by_id, null: false
  380. t.timestamps limit: 3, null: false
  381. end
  382. add_index :chat_topics, [:name], unique: true
  383. create_table :chat_sessions do |t|
  384. t.integer :chat_id, null: false
  385. t.string :session_id, null: false
  386. t.string :name, limit: 250, null: true
  387. t.string :state, limit: 50, null: false, default: 'waiting' # running, closed
  388. t.integer :user_id, null: true
  389. t.text :preferences, limit: 100.kilobytes + 1, null: true
  390. t.integer :updated_by_id, null: true
  391. t.integer :created_by_id, null: true
  392. t.timestamps limit: 3, null: false
  393. end
  394. add_index :chat_sessions, [:session_id]
  395. add_index :chat_sessions, [:state]
  396. add_index :chat_sessions, [:user_id]
  397. add_index :chat_sessions, [:chat_id]
  398. create_table :chat_messages do |t|
  399. t.integer :chat_session_id, null: false
  400. t.string :content, limit: 5000, null: false
  401. t.integer :created_by_id, null: true
  402. t.timestamps limit: 3, null: false
  403. end
  404. add_index :chat_messages, [:chat_session_id]
  405. create_table :chat_agents do |t|
  406. t.boolean :active, null: false, default: true
  407. t.integer :concurrent, null: false, default: 5
  408. t.integer :updated_by_id, null: false
  409. t.integer :created_by_id, null: false
  410. t.timestamps limit: 3, null: false
  411. end
  412. add_index :chat_agents, [:active]
  413. add_index :chat_agents, [:updated_by_id], unique: true
  414. add_index :chat_agents, [:created_by_id], unique: true
  415. create_table :report_profiles do |t|
  416. t.column :name, :string, limit: 150, null: true
  417. t.column :condition, :text, limit: 500.kilobytes + 1, null: true
  418. t.column :active, :boolean, null: false, default: true
  419. t.column :updated_by_id, :integer, null: false
  420. t.column :created_by_id, :integer, null: false
  421. t.timestamps limit: 3, null: false
  422. end
  423. add_index :report_profiles, [:name], unique: true
  424. create_table :karma_users do |t|
  425. t.integer :user_id, null: false
  426. t.integer :score, null: false
  427. t.string :level, limit: 200, null: false
  428. t.timestamps limit: 3, null: false
  429. end
  430. add_index :karma_users, [:user_id], unique: true
  431. create_table :karma_activities do |t|
  432. t.string :name, limit: 200, null: false
  433. t.string :description, limit: 200, null: false
  434. t.integer :score, null: false
  435. t.integer :once_ttl, null: false
  436. t.timestamps limit: 3, null: false
  437. end
  438. add_index :karma_activities, [:name], unique: true
  439. create_table :karma_activity_logs do |t|
  440. t.integer :o_id, null: false
  441. t.integer :object_lookup_id, null: false
  442. t.integer :user_id, null: false
  443. t.integer :activity_id, null: false
  444. t.integer :score, null: false
  445. t.integer :score_total, null: false
  446. t.timestamps limit: 3, null: false
  447. end
  448. add_index :karma_activity_logs, [:user_id]
  449. add_index :karma_activity_logs, [:created_at]
  450. add_index :karma_activity_logs, [:o_id, :object_lookup_id]
  451. end
  452. def self.down
  453. drop_table :karma_activity_logs
  454. drop_table :karma_activities
  455. drop_table :karma_users
  456. drop_table :report_profiles
  457. drop_table :chat_topics
  458. drop_table :chat_sessions
  459. drop_table :chat_messages
  460. drop_table :chat_agents
  461. drop_table :chats
  462. drop_table :macros
  463. drop_table :slas
  464. drop_table :channels
  465. drop_table :templates_groups
  466. drop_table :templates
  467. drop_table :text_modules_groups
  468. drop_table :text_modules
  469. drop_table :postmaster_filters
  470. drop_table :notifications
  471. drop_table :triggers
  472. drop_table :links
  473. drop_table :link_types
  474. drop_table :link_objects
  475. drop_table :overviews
  476. drop_table :ticket_counters
  477. drop_table :ticket_time_accounting
  478. drop_table :ticket_article_flags
  479. drop_table :ticket_articles
  480. drop_table :ticket_article_types
  481. drop_table :ticket_article_senders
  482. drop_table :ticket_flags
  483. drop_table :tickets
  484. drop_table :ticket_priorities
  485. drop_table :ticket_states
  486. drop_table :ticket_state_types
  487. end
  488. end