20120101000010_create_ticket.rb 25 KB

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