20120101000010_create_ticket.rb 32 KB

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