20120101000010_create_ticket.rb 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class CreateTicket < ActiveRecord::Migration[4.2]
  3. def up
  4. create_table :ticket_state_types do |t|
  5. t.column :name, :string, limit: 250, null: false
  6. t.column :note, :string, limit: 250, null: true
  7. t.column :updated_by_id, :integer, null: false
  8. t.column :created_by_id, :integer, null: false
  9. t.timestamps limit: 3, null: false
  10. end
  11. add_index :ticket_state_types, [:name], unique: true
  12. add_foreign_key :ticket_state_types, :users, column: :created_by_id
  13. add_foreign_key :ticket_state_types, :users, column: :updated_by_id
  14. create_table :ticket_states do |t|
  15. t.references :state_type, null: false
  16. t.column :name, :string, limit: 250, null: false
  17. t.column :next_state_id, :integer, null: true
  18. t.column :ignore_escalation, :boolean, null: false, default: false
  19. t.column :default_create, :boolean, null: false, default: false
  20. t.column :default_follow_up, :boolean, null: false, default: false
  21. t.column :note, :string, limit: 250, null: true
  22. t.column :active, :boolean, null: false, default: true
  23. t.column :updated_by_id, :integer, null: false
  24. t.column :created_by_id, :integer, null: false
  25. t.timestamps limit: 3, null: false
  26. end
  27. add_index :ticket_states, [:name], unique: true
  28. add_index :ticket_states, [:default_create]
  29. add_index :ticket_states, [:default_follow_up]
  30. add_foreign_key :ticket_states, :ticket_state_types, column: :state_type_id
  31. add_foreign_key :ticket_states, :users, column: :created_by_id
  32. add_foreign_key :ticket_states, :users, column: :updated_by_id
  33. create_table :ticket_priorities do |t|
  34. t.column :name, :string, limit: 250, null: false
  35. t.column :default_create, :boolean, null: false, default: false
  36. t.column :ui_icon, :string, limit: 100, null: true
  37. t.column :ui_color, :string, limit: 100, null: true
  38. t.column :note, :string, limit: 250, null: true
  39. t.column :active, :boolean, null: false, default: true
  40. t.column :updated_by_id, :integer, null: false
  41. t.column :created_by_id, :integer, null: false
  42. t.timestamps limit: 3, null: false
  43. end
  44. add_index :ticket_priorities, [:name], unique: true
  45. add_index :ticket_priorities, [:default_create]
  46. add_foreign_key :ticket_priorities, :users, column: :created_by_id
  47. add_foreign_key :ticket_priorities, :users, column: :updated_by_id
  48. create_table :tickets do |t|
  49. t.references :group, null: false
  50. t.references :priority, null: false
  51. t.references :state, null: false
  52. t.references :organization, null: true
  53. t.column :number, :string, limit: 60, null: false
  54. t.column :title, :string, limit: 250, null: false
  55. t.column :owner_id, :integer, null: false
  56. t.column :customer_id, :integer, null: false
  57. t.column :note, :string, limit: 250, null: true
  58. t.column :first_response_at, :timestamp, limit: 3, null: true
  59. t.column :first_response_escalation_at, :timestamp, limit: 3, null: true
  60. t.column :first_response_in_min, :integer, null: true
  61. t.column :first_response_diff_in_min, :integer, null: true
  62. t.column :close_at, :timestamp, limit: 3, null: true
  63. t.column :close_escalation_at, :timestamp, limit: 3, null: true
  64. t.column :close_in_min, :integer, null: true
  65. t.column :close_diff_in_min, :integer, null: true
  66. t.column :update_escalation_at, :timestamp, limit: 3, null: true
  67. t.column :update_in_min, :integer, null: true
  68. t.column :update_diff_in_min, :integer, null: true
  69. t.column :last_close_at, :timestamp, limit: 3, null: true
  70. t.column :last_contact_at, :timestamp, limit: 3, null: true
  71. t.column :last_contact_agent_at, :timestamp, limit: 3, null: true
  72. t.column :last_contact_customer_at, :timestamp, limit: 3, null: true
  73. t.column :last_owner_update_at, :timestamp, limit: 3, null: true
  74. t.column :create_article_type_id, :integer, null: true
  75. t.column :create_article_sender_id, :integer, null: true
  76. t.column :article_count, :integer, null: true
  77. t.column :escalation_at, :timestamp, limit: 3, null: true
  78. t.column :pending_time, :timestamp, limit: 3, null: true
  79. t.column :type, :string, limit: 100, null: true
  80. t.column :time_unit, :decimal, precision: 6, scale: 2, null: true
  81. t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
  82. t.column :updated_by_id, :integer, null: false
  83. t.column :created_by_id, :integer, null: false
  84. t.timestamps limit: 3, null: false
  85. end
  86. add_index :tickets, [:state_id]
  87. add_index :tickets, [:priority_id]
  88. add_index :tickets, [:group_id]
  89. add_index :tickets, [:owner_id]
  90. add_index :tickets, [:customer_id]
  91. add_index :tickets, %i[customer_id state_id created_at]
  92. add_index :tickets, [:number], unique: true
  93. add_index :tickets, [:title]
  94. add_index :tickets, [:created_at]
  95. add_index :tickets, [:updated_at]
  96. add_index :tickets, [:first_response_at]
  97. add_index :tickets, [:first_response_escalation_at]
  98. add_index :tickets, [:first_response_in_min]
  99. add_index :tickets, [:first_response_diff_in_min]
  100. add_index :tickets, [:close_at]
  101. add_index :tickets, [:close_escalation_at]
  102. add_index :tickets, [:close_in_min]
  103. add_index :tickets, [:close_diff_in_min]
  104. add_index :tickets, [:escalation_at]
  105. add_index :tickets, [:update_in_min]
  106. add_index :tickets, [:update_diff_in_min]
  107. add_index :tickets, [:last_contact_at]
  108. add_index :tickets, [:last_contact_agent_at]
  109. add_index :tickets, [:last_contact_customer_at]
  110. add_index :tickets, [:last_owner_update_at]
  111. add_index :tickets, [:create_article_type_id]
  112. add_index :tickets, [:create_article_sender_id]
  113. add_index :tickets, [:created_by_id]
  114. add_index :tickets, [:pending_time]
  115. add_index :tickets, [:type]
  116. add_index :tickets, [:time_unit]
  117. add_index :tickets, %i[group_id state_id]
  118. add_index :tickets, %i[group_id state_id owner_id]
  119. add_index :tickets, %i[group_id state_id updated_at]
  120. add_index :tickets, %i[group_id state_id owner_id updated_at], name: 'index_tickets_on_group_id_state_id_owner_id_updated_at'
  121. add_index :tickets, %i[group_id state_id created_at]
  122. add_index :tickets, %i[group_id state_id owner_id created_at], name: 'index_tickets_on_group_id_state_id_owner_id_created_at'
  123. add_index :tickets, %i[group_id state_id close_at]
  124. add_index :tickets, %i[group_id state_id owner_id close_at], name: 'index_tickets_on_group_id_state_id_owner_id_close_at'
  125. add_foreign_key :tickets, :groups
  126. add_foreign_key :tickets, :users, column: :owner_id
  127. add_foreign_key :tickets, :users, column: :customer_id
  128. add_foreign_key :tickets, :ticket_priorities, column: :priority_id
  129. add_foreign_key :tickets, :ticket_states, column: :state_id
  130. add_foreign_key :tickets, :organizations
  131. add_foreign_key :tickets, :users, column: :created_by_id
  132. add_foreign_key :tickets, :users, column: :updated_by_id
  133. create_table :ticket_article_types do |t|
  134. t.column :name, :string, limit: 250, null: false
  135. t.column :note, :string, limit: 250, null: true
  136. t.column :communication, :boolean, null: false, default: false
  137. t.column :active, :boolean, null: false, default: true
  138. t.column :updated_by_id, :integer, null: false
  139. t.column :created_by_id, :integer, null: false
  140. t.timestamps limit: 3, null: false
  141. end
  142. add_index :ticket_article_types, [:name], unique: true
  143. add_foreign_key :ticket_article_types, :users, column: :created_by_id
  144. add_foreign_key :ticket_article_types, :users, column: :updated_by_id
  145. create_table :ticket_article_senders do |t|
  146. t.column :name, :string, limit: 250, null: false
  147. t.column :note, :string, limit: 250, null: true
  148. t.column :updated_by_id, :integer, null: false
  149. t.column :created_by_id, :integer, null: false
  150. t.timestamps limit: 3, null: false
  151. end
  152. add_index :ticket_article_senders, [:name], unique: true
  153. add_foreign_key :ticket_article_senders, :users, column: :created_by_id
  154. add_foreign_key :ticket_article_senders, :users, column: :updated_by_id
  155. create_table :ticket_articles do |t|
  156. t.references :ticket, null: false
  157. t.references :type, null: false
  158. t.references :sender, null: false
  159. t.column :from, :string, limit: 3000, null: true
  160. t.column :to, :string, limit: 3000, null: true
  161. t.column :cc, :string, limit: 3000, null: true
  162. t.column :subject, :string, limit: 3000, null: true
  163. t.column :reply_to, :string, limit: 300, null: true
  164. t.column :message_id, :string, limit: 3000, null: true
  165. t.column :message_id_md5, :string, limit: 32, null: true
  166. t.column :in_reply_to, :string, limit: 3000, null: true
  167. t.column :content_type, :string, limit: 20, null: false, default: 'text/plain'
  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_accounting_types do |t|
  204. t.column :name, :string, limit: 250, null: false
  205. t.column :note, :string, limit: 250, null: true
  206. t.column :active, :boolean, null: false, default: true
  207. t.column :updated_by_id, :integer, null: false
  208. t.column :created_by_id, :integer, null: false
  209. t.timestamps limit: 3, null: false
  210. end
  211. add_index :ticket_time_accounting_types, [:name], unique: true
  212. add_foreign_key :ticket_time_accounting_types, :users, column: :created_by_id
  213. add_foreign_key :ticket_time_accounting_types, :users, column: :updated_by_id
  214. create_table :ticket_time_accountings do |t|
  215. t.references :ticket, null: false
  216. t.references :ticket_article, null: true
  217. t.column :time_unit, :decimal, precision: 6, scale: 2, null: false
  218. t.column :type_id, :integer, null: true
  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. add_foreign_key :ticket_time_accountings, :ticket_time_accounting_types, column: :type_id
  230. create_table :ticket_counters do |t|
  231. t.column :content, :string, limit: 100, null: false
  232. t.column :generator, :string, limit: 100, null: false
  233. end
  234. add_index :ticket_counters, [:generator], unique: true
  235. create_table :overviews do |t|
  236. t.column :name, :string, limit: 250, null: false
  237. t.column :link, :string, limit: 250, null: false
  238. t.column :prio, :integer, null: false
  239. t.column :condition, :text, limit: 500.kilobytes + 1, null: false
  240. t.column :order, :string, limit: 2500, null: false
  241. t.column :group_by, :string, limit: 250, null: true
  242. t.column :group_direction, :string, limit: 250, null: true
  243. t.column :organization_shared, :boolean, null: false, default: false
  244. t.column :out_of_office, :boolean, null: false, default: false
  245. t.column :view, :string, limit: 1000, null: false
  246. t.column :active, :boolean, null: false, default: true
  247. t.column :updated_by_id, :integer, null: false
  248. t.column :created_by_id, :integer, null: false
  249. t.timestamps limit: 3, null: false
  250. end
  251. add_index :overviews, [:name]
  252. add_foreign_key :overviews, :users, column: :created_by_id
  253. add_foreign_key :overviews, :users, column: :updated_by_id
  254. create_table :overviews_roles, id: false do |t|
  255. t.references :overview
  256. t.references :role
  257. end
  258. add_index :overviews_roles, [:overview_id]
  259. add_index :overviews_roles, [:role_id]
  260. add_foreign_key :overviews_roles, :overviews
  261. add_foreign_key :overviews_roles, :roles
  262. create_table :overviews_users, id: false do |t|
  263. t.references :overview
  264. t.references :user
  265. end
  266. add_index :overviews_users, [:overview_id]
  267. add_index :overviews_users, [:user_id]
  268. add_foreign_key :overviews_users, :overviews
  269. add_foreign_key :overviews_users, :users
  270. create_table :overviews_groups, id: false do |t|
  271. t.references :overview
  272. t.references :group
  273. end
  274. add_index :overviews_groups, [:overview_id]
  275. add_index :overviews_groups, [:group_id]
  276. add_foreign_key :overviews_groups, :overviews
  277. add_foreign_key :overviews_groups, :groups
  278. create_table :triggers do |t|
  279. t.column :name, :string, limit: 250, null: false
  280. t.column :condition, :text, limit: 500.kilobytes + 1, null: false
  281. t.column :perform, :text, limit: 500.kilobytes + 1, null: false
  282. t.column :disable_notification, :boolean, null: false, default: true
  283. t.column :localization, :string, limit: 20, null: true # thx to ApplicationModel::CanCreatesAndUpdates ...
  284. t.column :timezone, :string, limit: 250, null: true
  285. t.column :note, :string, limit: 250, null: true
  286. t.column :activator, :string, limit: 50, null: false, default: 'action'
  287. t.column :execution_condition_mode, :string, limit: 50, null: false, default: 'selective'
  288. t.column :active, :boolean, null: false, default: true
  289. t.column :updated_by_id, :integer, null: false
  290. t.column :created_by_id, :integer, null: false
  291. t.timestamps limit: 3, null: false
  292. end
  293. add_index :triggers, [:name], unique: true
  294. add_index :triggers, %i[active activator]
  295. add_foreign_key :triggers, :users, column: :created_by_id
  296. add_foreign_key :triggers, :users, column: :updated_by_id
  297. create_table :link_types do |t|
  298. t.column :name, :string, limit: 250, null: false
  299. t.column :note, :string, limit: 250, null: true
  300. t.column :active, :boolean, null: false, default: true
  301. t.timestamps limit: 3, null: false
  302. end
  303. add_index :link_types, [:name], unique: true
  304. create_table :link_objects do |t|
  305. t.column :name, :string, limit: 250, null: false
  306. t.column :note, :string, limit: 250, null: true
  307. t.column :active, :boolean, null: false, default: true
  308. t.timestamps limit: 3, null: false
  309. end
  310. add_index :link_objects, [:name], unique: true
  311. create_table :links do |t|
  312. t.references :link_type, null: false
  313. t.column :link_object_source_id, :integer, null: false
  314. t.column :link_object_source_value, :integer, null: false
  315. t.column :link_object_target_id, :integer, null: false
  316. t.column :link_object_target_value, :integer, null: false
  317. t.timestamps limit: 3, null: false
  318. end
  319. 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'
  320. add_foreign_key :links, :link_types
  321. create_table :postmaster_filters do |t|
  322. t.column :name, :string, limit: 250, null: false
  323. t.column :channel, :string, limit: 250, null: false
  324. t.column :match, :text, limit: 500.kilobytes + 1, null: false
  325. t.column :perform, :text, limit: 500.kilobytes + 1, null: false
  326. t.column :active, :boolean, null: false, default: true
  327. t.column :note, :string, limit: 250, null: true
  328. t.column :updated_by_id, :integer, null: false
  329. t.column :created_by_id, :integer, null: false
  330. t.timestamps limit: 3, null: false
  331. end
  332. add_index :postmaster_filters, [:channel]
  333. add_foreign_key :postmaster_filters, :users, column: :created_by_id
  334. add_foreign_key :postmaster_filters, :users, column: :updated_by_id
  335. create_table :text_modules do |t|
  336. t.column :name, :string, limit: 250, null: false
  337. t.column :keywords, :string, limit: 500, null: true
  338. t.column :content, :text, limit: 10.megabytes + 1, null: false
  339. t.column :note, :string, limit: 250, null: true
  340. t.column :active, :boolean, null: false, default: true
  341. t.column :updated_by_id, :integer, null: false
  342. t.column :created_by_id, :integer, null: false
  343. t.timestamps limit: 3, null: false
  344. end
  345. add_index :text_modules, [:name]
  346. add_foreign_key :text_modules, :users, column: :created_by_id
  347. add_foreign_key :text_modules, :users, column: :updated_by_id
  348. create_table :text_modules_groups, id: false do |t|
  349. t.references :text_module
  350. t.references :group
  351. end
  352. add_index :text_modules_groups, [:text_module_id]
  353. add_index :text_modules_groups, [:group_id]
  354. add_foreign_key :text_modules_groups, :text_modules
  355. add_foreign_key :text_modules_groups, :groups
  356. create_table :templates do |t|
  357. t.column :name, :string, limit: 250, null: false
  358. t.column :options, :text, limit: 10.megabytes + 1, null: false
  359. t.column :active, :boolean, null: false, default: true
  360. t.column :updated_by_id, :integer, null: false
  361. t.column :created_by_id, :integer, null: false
  362. t.timestamps limit: 3, null: false
  363. end
  364. add_index :templates, [:name]
  365. add_foreign_key :templates, :users, column: :created_by_id
  366. add_foreign_key :templates, :users, column: :updated_by_id
  367. create_table :channels do |t|
  368. t.references :group, null: true
  369. t.column :area, :string, limit: 100, null: false
  370. t.column :options, :text, limit: 500.kilobytes + 1, null: true
  371. t.column :active, :boolean, null: false, default: true
  372. t.column :preferences, :string, limit: 2000, null: true
  373. t.column :last_log_in, :text, limit: 500.kilobytes + 1, null: true
  374. t.column :last_log_out, :text, limit: 500.kilobytes + 1, null: true
  375. t.column :status_in, :string, limit: 100, null: true
  376. t.column :status_out, :string, limit: 100, null: true
  377. t.column :updated_by_id, :integer, null: false
  378. t.column :created_by_id, :integer, null: false
  379. t.timestamps limit: 3, null: false
  380. end
  381. add_index :channels, [:area]
  382. add_foreign_key :channels, :groups
  383. add_foreign_key :channels, :users, column: :created_by_id
  384. add_foreign_key :channels, :users, column: :updated_by_id
  385. create_table :slas do |t|
  386. t.references :calendar, null: false
  387. t.column :name, :string, limit: 150, null: true
  388. t.column :first_response_time, :integer, null: true
  389. t.column :response_time, :integer, null: true
  390. t.column :update_time, :integer, null: true
  391. t.column :solution_time, :integer, null: true
  392. t.column :condition, :text, limit: 500.kilobytes + 1, null: true
  393. t.column :updated_by_id, :integer, null: false
  394. t.column :created_by_id, :integer, null: false
  395. t.timestamps limit: 3, null: false
  396. end
  397. add_index :slas, [:name], unique: true
  398. add_foreign_key :slas, :users, column: :created_by_id
  399. add_foreign_key :slas, :users, column: :updated_by_id
  400. create_table :macros do |t|
  401. t.string :name, limit: 250, null: true
  402. t.text :perform, limit: 500.kilobytes + 1, null: false
  403. t.boolean :active, null: false, default: true
  404. t.string :ux_flow_next_up, null: false, default: 'none'
  405. t.string :note, limit: 250, null: true
  406. t.integer :updated_by_id, null: false
  407. t.integer :created_by_id, null: false
  408. t.timestamps limit: 3, null: false
  409. end
  410. add_index :macros, [:name], unique: true
  411. add_foreign_key :macros, :users, column: :created_by_id
  412. add_foreign_key :macros, :users, column: :updated_by_id
  413. create_table :chats do |t|
  414. t.string :name, limit: 250, null: true
  415. t.integer :max_queue, null: false, default: 5
  416. t.string :note, limit: 250, null: true
  417. t.boolean :active, null: false, default: true
  418. t.boolean :public, null: false, default: false
  419. t.string :block_ip, limit: 5000, null: true
  420. t.string :block_country, limit: 5000, null: true
  421. t.string :allowed_websites, limit: 5000, null: true
  422. t.string :preferences, limit: 5000, null: true
  423. t.integer :updated_by_id, null: false
  424. t.integer :created_by_id, null: false
  425. t.timestamps limit: 3, null: false
  426. end
  427. add_index :chats, [:name], unique: true
  428. add_foreign_key :chats, :users, column: :created_by_id
  429. add_foreign_key :chats, :users, column: :updated_by_id
  430. create_table :chat_sessions do |t|
  431. t.references :chat, null: false
  432. t.string :session_id, null: false
  433. t.string :name, limit: 250, null: true
  434. t.string :state, limit: 50, null: false, default: 'waiting' # running, closed
  435. t.references :user, null: true
  436. t.text :preferences, limit: 100.kilobytes + 1, null: true
  437. t.integer :updated_by_id, null: true
  438. t.integer :created_by_id, null: true
  439. t.timestamps limit: 3, null: false
  440. end
  441. add_index :chat_sessions, [:session_id]
  442. add_index :chat_sessions, [:state]
  443. add_index :chat_sessions, [:user_id]
  444. add_index :chat_sessions, [:chat_id]
  445. add_foreign_key :chat_sessions, :chats
  446. add_foreign_key :chat_sessions, :users
  447. add_foreign_key :chat_sessions, :users, column: :created_by_id
  448. add_foreign_key :chat_sessions, :users, column: :updated_by_id
  449. create_table :chat_messages do |t|
  450. t.references :chat_session, null: false
  451. t.text :content, limit: 20.megabytes + 1, null: false
  452. t.integer :created_by_id, null: true
  453. t.timestamps limit: 3, null: false
  454. end
  455. add_index :chat_messages, [:chat_session_id]
  456. add_foreign_key :chat_messages, :chat_sessions
  457. add_foreign_key :chat_messages, :users, column: :created_by_id
  458. create_table :chat_agents do |t|
  459. t.boolean :active, null: false, default: true
  460. t.integer :concurrent, null: false, default: 5
  461. t.integer :updated_by_id, null: false
  462. t.integer :created_by_id, null: false
  463. t.timestamps limit: 3, null: false
  464. end
  465. add_index :chat_agents, [:active]
  466. add_index :chat_agents, [:updated_by_id], unique: true
  467. add_index :chat_agents, [:created_by_id], unique: true
  468. add_foreign_key :chat_agents, :users, column: :created_by_id
  469. add_foreign_key :chat_agents, :users, column: :updated_by_id
  470. create_table :report_profiles do |t|
  471. t.column :name, :string, limit: 150, null: true
  472. t.column :condition, :text, limit: 500.kilobytes + 1, null: true
  473. t.column :active, :boolean, null: false, default: true
  474. t.column :updated_by_id, :integer, null: false
  475. t.column :created_by_id, :integer, null: false
  476. t.timestamps limit: 3, null: false
  477. end
  478. add_index :report_profiles, [:name], unique: true
  479. add_foreign_key :report_profiles, :users, column: :created_by_id
  480. add_foreign_key :report_profiles, :users, column: :updated_by_id
  481. create_table :webhooks do |t|
  482. t.column :name, :string, limit: 250, null: false
  483. t.column :endpoint, :string, limit: 300, null: false
  484. t.column :signature_token, :string, limit: 200, null: true
  485. t.column :ssl_verify, :boolean, null: false, default: true
  486. t.column :basic_auth_username, :string, limit: 250, null: true
  487. t.column :basic_auth_password, :string, limit: 250, null: true
  488. t.column :note, :string, limit: 500, null: true
  489. t.column :pre_defined_webhook_type, :string, limit: 250, null: true
  490. t.column :customized_payload, :boolean, null: false, default: false
  491. t.column :custom_payload, :text, limit: 500.kilobytes + 1, null: true
  492. t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
  493. t.column :active, :boolean, null: false, default: true
  494. t.column :updated_by_id, :integer, null: false
  495. t.column :created_by_id, :integer, null: false
  496. t.timestamps limit: 3, null: false
  497. end
  498. create_table :ticket_shared_draft_zooms do |t|
  499. t.references :ticket, null: false, foreign_key: { to_table: :tickets }
  500. t.text :new_article
  501. t.text :ticket_attributes
  502. t.column :created_by_id, :integer, null: false
  503. t.column :updated_by_id, :integer, null: false
  504. t.timestamps limit: 3
  505. end
  506. create_table :ticket_shared_draft_starts do |t|
  507. t.references :group, null: false, foreign_key: { to_table: :groups }
  508. t.string :name
  509. t.text :content
  510. t.column :created_by_id, :integer, null: false
  511. t.column :updated_by_id, :integer, null: false
  512. t.timestamps limit: 3
  513. end
  514. create_table :checklists do |t|
  515. t.string :name, limit: 250, null: false, default: ''
  516. if Rails.application.config.db_column_array
  517. t.string :sorted_item_ids, null: false, array: true, default: []
  518. else
  519. t.json :sorted_item_ids, null: false
  520. end
  521. t.references :created_by, null: false, foreign_key: { to_table: :users }
  522. t.references :updated_by, null: false, foreign_key: { to_table: :users }
  523. t.timestamps limit: 3, null: false
  524. end
  525. change_table :tickets do |t|
  526. t.references :checklist, null: true, foreign_key: true, index: { unique: true }
  527. end
  528. create_table :checklist_items do |t|
  529. if ActiveRecord::Base.connection_db_config.configuration_hash[:adapter] == 'mysql2'
  530. t.text :text, null: false
  531. else
  532. t.text :text, null: false, default: ''
  533. end
  534. t.boolean :checked, null: false, default: false
  535. t.references :checklist, null: false, foreign_key: true
  536. t.references :created_by, null: false, foreign_key: { to_table: :users }
  537. t.references :updated_by, null: false, foreign_key: { to_table: :users }
  538. t.references :ticket, null: true, foreign_key: true
  539. t.timestamps limit: 3, null: false
  540. end
  541. add_index :checklist_items, [:checked]
  542. create_table :checklist_templates do |t|
  543. t.string :name, limit: 250, null: false, default: ''
  544. t.boolean :active, default: true, null: false
  545. if Rails.application.config.db_column_array
  546. t.string :sorted_item_ids, null: false, array: true, default: []
  547. else
  548. t.json :sorted_item_ids, null: false
  549. end
  550. t.references :created_by, null: false, foreign_key: { to_table: :users }
  551. t.references :updated_by, null: false, foreign_key: { to_table: :users }
  552. t.timestamps limit: 3, null: false
  553. end
  554. add_index :checklist_templates, [:active]
  555. create_table :checklist_template_items do |t|
  556. if ActiveRecord::Base.connection_db_config.configuration_hash[:adapter] == 'mysql2'
  557. t.text :text, null: false
  558. else
  559. t.text :text, null: false, default: ''
  560. end
  561. t.references :checklist_template, null: false, foreign_key: true
  562. t.references :created_by, null: false, foreign_key: { to_table: :users }
  563. t.references :updated_by, null: false, foreign_key: { to_table: :users }
  564. t.timestamps limit: 3, null: false
  565. end
  566. end
  567. def self.down
  568. drop_table :checklist_template_items
  569. drop_table :checklist_templates
  570. drop_table :checklist_items
  571. drop_table :checklists
  572. drop_table :report_profiles
  573. drop_table :chat_sessions
  574. drop_table :chat_messages
  575. drop_table :chat_agents
  576. drop_table :chats
  577. drop_table :macros
  578. drop_table :slas
  579. drop_table :channels
  580. drop_table :templates
  581. drop_table :text_modules_groups
  582. drop_table :text_modules
  583. drop_table :postmaster_filters
  584. drop_table :triggers
  585. drop_table :links
  586. drop_table :link_types
  587. drop_table :link_objects
  588. drop_table :overviews
  589. drop_table :ticket_counters
  590. drop_table :ticket_time_accounting
  591. drop_table :ticket_article_flags
  592. drop_table :ticket_articles
  593. drop_table :ticket_article_types
  594. drop_table :ticket_article_senders
  595. drop_table :tickets
  596. drop_table :ticket_priorities
  597. drop_table :ticket_states
  598. drop_table :ticket_state_types
  599. drop_table :webhooks
  600. drop_table :ticket_shared_draft_zooms
  601. drop_table :ticket_shared_draft_starts
  602. end
  603. end