20120101000010_create_ticket.rb 26 KB

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