20120101000010_create_ticket.rb 33 KB

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