20120101000001_create_base.rb 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class CreateBase < ActiveRecord::Migration[4.2]
  3. def up
  4. # clear old caches to start from scratch
  5. Cache.clear
  6. create_table :sessions do |t|
  7. t.string :session_id, null: false
  8. t.boolean :persistent, null: true
  9. t.text :data
  10. t.timestamps limit: 3, null: false
  11. end
  12. add_index :sessions, :session_id
  13. add_index :sessions, :updated_at
  14. add_index :sessions, :persistent
  15. create_table :users do |t|
  16. t.references :organization, null: true
  17. t.string :login, limit: 255, null: false
  18. t.string :firstname, limit: 100, null: true, default: ''
  19. t.string :lastname, limit: 100, null: true, default: ''
  20. t.string :email, limit: 255, null: true, default: ''
  21. t.string :image, limit: 100, null: true
  22. t.string :image_source, limit: 200, null: true
  23. t.string :web, limit: 100, null: true, default: ''
  24. t.string :password, limit: 100, null: true
  25. t.string :phone, limit: 100, null: true, default: ''
  26. t.string :fax, limit: 100, null: true, default: ''
  27. t.string :mobile, limit: 100, null: true, default: ''
  28. t.string :department, limit: 200, null: true, default: ''
  29. t.string :street, limit: 120, null: true, default: ''
  30. t.string :zip, limit: 100, null: true, default: ''
  31. t.string :city, limit: 100, null: true, default: ''
  32. t.string :country, limit: 100, null: true, default: ''
  33. t.string :address, limit: 500, null: true, default: ''
  34. t.boolean :vip, default: false
  35. t.boolean :verified, null: false, default: false
  36. t.boolean :active, null: false, default: true
  37. t.string :note, limit: 5000, null: true, default: ''
  38. t.timestamp :last_login, limit: 3, null: true
  39. t.string :source, limit: 200, null: true
  40. t.integer :login_failed, null: false, default: 0
  41. t.boolean :out_of_office, null: false, default: false
  42. t.date :out_of_office_start_at, null: true
  43. t.date :out_of_office_end_at, null: true
  44. t.integer :out_of_office_replacement_id, null: true
  45. t.string :preferences, limit: 8000, null: true
  46. t.integer :updated_by_id, null: false
  47. t.integer :created_by_id, null: false
  48. t.timestamps limit: 3, null: false
  49. end
  50. add_index :users, [:login], unique: true
  51. add_index :users, [:email]
  52. # add_index :users, [:email], unique: => true
  53. add_index :users, [:organization_id]
  54. add_index :users, [:image]
  55. add_index :users, [:department]
  56. add_index :users, [:phone]
  57. add_index :users, [:fax]
  58. add_index :users, [:mobile]
  59. add_index :users, %i[out_of_office out_of_office_start_at out_of_office_end_at], name: 'index_out_of_office'
  60. add_index :users, [:out_of_office_replacement_id]
  61. add_index :users, [:source]
  62. add_index :users, [:created_by_id]
  63. add_foreign_key :users, :users, column: :created_by_id
  64. add_foreign_key :users, :users, column: :updated_by_id
  65. add_foreign_key :users, :users, column: :out_of_office_replacement_id
  66. create_table :signatures do |t|
  67. t.string :name, limit: 100, null: false
  68. t.text :body, limit: 10.megabytes + 1, null: true
  69. t.boolean :active, null: false, default: true
  70. t.string :note, limit: 250, null: true
  71. t.integer :updated_by_id, null: false
  72. t.integer :created_by_id, null: false
  73. t.timestamps limit: 3, null: false
  74. end
  75. add_index :signatures, [:name], unique: true
  76. add_foreign_key :signatures, :users, column: :created_by_id
  77. add_foreign_key :signatures, :users, column: :updated_by_id
  78. create_table :email_addresses do |t|
  79. t.integer :channel_id, null: true
  80. t.string :realname, limit: 250, null: false
  81. t.string :email, limit: 250, null: false
  82. t.boolean :active, null: false, default: true
  83. t.string :note, limit: 250, null: true
  84. t.string :preferences, limit: 2000, null: true
  85. t.integer :updated_by_id, null: false
  86. t.integer :created_by_id, null: false
  87. t.timestamps limit: 3, null: false
  88. end
  89. add_index :email_addresses, [:email], unique: true
  90. add_foreign_key :email_addresses, :users, column: :created_by_id
  91. add_foreign_key :email_addresses, :users, column: :updated_by_id
  92. create_table :groups do |t|
  93. t.references :signature, null: true
  94. t.references :email_address, null: true
  95. t.string :name, limit: 160, null: false
  96. t.integer :assignment_timeout, null: true
  97. t.string :follow_up_possible, limit: 100, null: false, default: 'yes'
  98. t.boolean :follow_up_assignment, null: false, default: true
  99. t.boolean :active, null: false, default: true
  100. t.string :note, limit: 250, null: true
  101. t.integer :updated_by_id, null: false
  102. t.integer :created_by_id, null: false
  103. t.timestamps limit: 3, null: false
  104. end
  105. add_index :groups, [:name], unique: true
  106. add_foreign_key :groups, :signatures
  107. add_foreign_key :groups, :email_addresses
  108. add_foreign_key :groups, :users, column: :created_by_id
  109. add_foreign_key :groups, :users, column: :updated_by_id
  110. create_table :roles do |t|
  111. t.string :name, limit: 100, null: false
  112. t.text :preferences, limit: 500.kilobytes + 1, null: true
  113. t.boolean :default_at_signup, null: true, default: false
  114. t.boolean :active, null: false, default: true
  115. t.string :note, limit: 250, null: true
  116. t.integer :updated_by_id, null: false
  117. t.integer :created_by_id, null: false
  118. t.timestamps limit: 3, null: false
  119. end
  120. add_index :roles, [:name], unique: true
  121. add_foreign_key :roles, :users, column: :created_by_id
  122. add_foreign_key :roles, :users, column: :updated_by_id
  123. create_table :permissions do |t|
  124. t.string :name, limit: 255, null: false
  125. t.string :note, limit: 500, null: true
  126. t.string :preferences, limit: 10_000, null: true
  127. t.boolean :active, null: false, default: true
  128. t.boolean :allow_signup, null: false, default: false
  129. t.timestamps limit: 3, null: false
  130. end
  131. add_index :permissions, [:name], unique: true
  132. create_table :permissions_roles, id: false do |t|
  133. t.belongs_to :role, index: true
  134. t.belongs_to :permission, index: true
  135. end
  136. create_table :organizations do |t|
  137. t.string :name, limit: 100, null: false
  138. t.boolean :shared, null: false, default: true
  139. t.string :domain, limit: 250, null: true, default: ''
  140. t.boolean :domain_assignment, null: false, default: false
  141. t.boolean :active, null: false, default: true
  142. t.string :note, limit: 5000, null: true, default: ''
  143. t.integer :updated_by_id, null: false
  144. t.integer :created_by_id, null: false
  145. t.timestamps limit: 3, null: false
  146. end
  147. add_index :organizations, [:name], unique: true
  148. add_index :organizations, [:domain]
  149. add_foreign_key :users, :organizations
  150. add_foreign_key :organizations, :users, column: :created_by_id
  151. add_foreign_key :organizations, :users, column: :updated_by_id
  152. create_table :roles_users, id: false do |t|
  153. t.references :user
  154. t.references :role
  155. end
  156. add_index :roles_users, [:user_id]
  157. add_index :roles_users, [:role_id]
  158. add_foreign_key :roles_users, :users
  159. add_foreign_key :roles_users, :roles
  160. create_table :groups_users, id: false do |t|
  161. t.references :user, null: false
  162. t.references :group, null: false
  163. t.string :access, limit: 50, null: false, default: 'full'
  164. end
  165. add_index :groups_users, [:user_id]
  166. add_index :groups_users, [:group_id]
  167. add_index :groups_users, [:access]
  168. add_index :groups_users, %i[user_id group_id access]
  169. add_foreign_key :groups_users, :users
  170. add_foreign_key :groups_users, :groups
  171. create_table :roles_groups, id: false do |t|
  172. t.references :role, null: false
  173. t.references :group, null: false
  174. t.string :access, limit: 50, null: false, default: 'full'
  175. end
  176. add_index :roles_groups, [:role_id]
  177. add_index :roles_groups, [:group_id]
  178. add_index :roles_groups, [:access]
  179. add_foreign_key :roles_groups, :roles
  180. add_foreign_key :roles_groups, :groups
  181. create_table :organizations_users, id: false do |t|
  182. t.references :user
  183. t.references :organization
  184. end
  185. add_index :organizations_users, [:user_id]
  186. add_index :organizations_users, [:organization_id]
  187. add_foreign_key :organizations_users, :users
  188. add_foreign_key :organizations_users, :organizations
  189. create_table :authorizations do |t|
  190. t.string :provider, limit: 250, null: false
  191. t.string :uid, limit: 250, null: false
  192. t.string :token, limit: 2500, null: true
  193. t.string :secret, limit: 250, null: true
  194. t.string :username, limit: 250, null: true
  195. t.references :user, null: false
  196. t.timestamps limit: 3, null: false
  197. end
  198. add_index :authorizations, %i[uid provider], unique: true
  199. add_index :authorizations, [:user_id]
  200. add_index :authorizations, [:username]
  201. add_foreign_key :authorizations, :users
  202. create_table :locales do |t|
  203. t.string :locale, limit: 20, null: false
  204. t.string :alias, limit: 20, null: true
  205. t.string :name, limit: 255, null: false
  206. t.string :dir, limit: 9, null: false, default: 'ltr'
  207. t.boolean :active, null: false, default: true
  208. t.timestamps limit: 3, null: false
  209. end
  210. add_index :locales, [:locale], unique: true
  211. add_index :locales, [:name], unique: true
  212. create_table :translations do |t|
  213. t.string :locale, limit: 10, null: false
  214. t.string :source, limit: 3000, null: false
  215. t.string :target, limit: 3000, null: false
  216. t.string :target_initial, limit: 3000, null: false
  217. t.boolean :is_synchronized_from_codebase, null: false, default: false
  218. t.string :synchronized_from_translation_file, limit: 255
  219. t.integer :updated_by_id, null: false
  220. t.integer :created_by_id, null: false
  221. t.timestamps limit: 3, null: false
  222. end
  223. add_index :translations, [:source], length: 255
  224. add_index :translations, [:locale]
  225. add_foreign_key :translations, :users, column: :created_by_id
  226. add_foreign_key :translations, :users, column: :updated_by_id
  227. create_table :object_lookups do |t|
  228. t.string :name, limit: 250, null: false
  229. t.timestamps limit: 3, null: false
  230. end
  231. add_index :object_lookups, [:name], unique: true
  232. create_table :type_lookups do |t|
  233. t.string :name, limit: 250, null: false
  234. t.timestamps limit: 3, null: false
  235. end
  236. add_index :type_lookups, [:name], unique: true
  237. create_table :tokens do |t|
  238. t.references :user, null: false
  239. t.boolean :persistent
  240. t.string :name, limit: 100, null: false
  241. t.string :action, limit: 40, null: false
  242. t.string :label, limit: 255, null: true
  243. t.text :preferences, limit: 500.kilobytes + 1, null: true
  244. t.timestamp :last_used_at, limit: 3, null: true
  245. t.date :expires_at, null: true
  246. t.timestamps limit: 3, null: false
  247. end
  248. add_index :tokens, :user_id
  249. add_index :tokens, %i[name action], unique: true
  250. add_index :tokens, :created_at
  251. add_index :tokens, :persistent
  252. add_foreign_key :tokens, :users
  253. create_table :packages do |t|
  254. t.string :name, limit: 250, null: false
  255. t.string :version, limit: 50, null: false
  256. t.string :vendor, limit: 150, null: false
  257. t.string :state, limit: 50, null: false
  258. t.integer :updated_by_id, null: false
  259. t.integer :created_by_id, null: false
  260. t.timestamps limit: 3, null: false
  261. end
  262. add_foreign_key :packages, :users, column: :created_by_id
  263. add_foreign_key :packages, :users, column: :updated_by_id
  264. create_table :package_migrations do |t|
  265. t.string :name, limit: 250, null: false
  266. t.string :version, limit: 250, null: false
  267. t.timestamps limit: 3, null: false
  268. end
  269. create_table :taskbars do |t|
  270. t.references :user, null: false
  271. t.datetime :last_contact, null: false, limit: 3
  272. t.string :client_id, null: false
  273. t.string :key, limit: 100, null: false
  274. t.string :callback, limit: 100, null: false
  275. t.text :state, limit: 20.megabytes + 1, null: true
  276. t.text :preferences, limit: 5.megabytes + 1, null: true
  277. t.string :params, limit: 2000, null: true
  278. t.integer :prio, null: false
  279. t.boolean :notify, null: false, default: false
  280. t.boolean :active, null: false, default: false
  281. t.timestamps limit: 3, null: false
  282. end
  283. add_index :taskbars, [:user_id]
  284. add_index :taskbars, [:client_id]
  285. add_index :taskbars, [:key]
  286. add_foreign_key :taskbars, :users
  287. create_table :tag_objects do |t|
  288. t.string :name, limit: 250, null: false
  289. t.timestamps limit: 3, null: false
  290. end
  291. add_index :tag_objects, [:name], unique: true
  292. create_table :tag_items do |t|
  293. t.string :name, limit: 250, null: false
  294. t.string :name_downcase, limit: 250, null: false
  295. t.timestamps limit: 3, null: false
  296. end
  297. add_index :tag_items, [:name_downcase]
  298. create_table :tags do |t|
  299. t.references :tag_item, null: false
  300. t.references :tag_object, null: false
  301. t.integer :o_id, null: false
  302. t.integer :created_by_id, null: false
  303. t.timestamps limit: 3, null: false
  304. end
  305. add_index :tags, [:o_id]
  306. add_index :tags, [:tag_object_id]
  307. add_foreign_key :tags, :tag_items
  308. add_foreign_key :tags, :tag_objects
  309. add_foreign_key :tags, :users, column: :created_by_id
  310. create_table :recent_views do |t|
  311. t.references :recent_view_object, null: false
  312. t.integer :o_id, null: false
  313. t.integer :created_by_id, null: false
  314. t.timestamps limit: 3, null: false
  315. end
  316. add_index :recent_views, [:o_id]
  317. add_index :recent_views, [:created_by_id]
  318. add_index :recent_views, [:created_at]
  319. add_index :recent_views, [:recent_view_object_id]
  320. add_foreign_key :recent_views, :object_lookups, column: :recent_view_object_id
  321. add_foreign_key :recent_views, :users, column: :created_by_id
  322. create_table :activity_streams do |t|
  323. t.references :activity_stream_type, null: false
  324. t.references :activity_stream_object, null: false
  325. t.references :permission, null: true
  326. t.references :group, null: true
  327. t.integer :o_id, null: false
  328. t.integer :created_by_id, null: false
  329. t.timestamps limit: 3, null: false
  330. end
  331. add_index :activity_streams, [:o_id]
  332. add_index :activity_streams, [:created_by_id]
  333. add_index :activity_streams, [:permission_id]
  334. add_index :activity_streams, %i[permission_id group_id]
  335. add_index :activity_streams, %i[permission_id group_id created_at], name: 'index_activity_streams_on_permission_id_group_id_created_at'
  336. add_index :activity_streams, [:group_id]
  337. add_index :activity_streams, [:created_at]
  338. add_index :activity_streams, [:activity_stream_object_id]
  339. add_index :activity_streams, [:activity_stream_type_id]
  340. add_foreign_key :activity_streams, :type_lookups, column: :activity_stream_type_id
  341. add_foreign_key :activity_streams, :object_lookups, column: :activity_stream_object_id
  342. add_foreign_key :activity_streams, :permissions
  343. add_foreign_key :activity_streams, :groups
  344. add_foreign_key :activity_streams, :users, column: :created_by_id
  345. create_table :history_types do |t|
  346. t.string :name, limit: 250, null: false
  347. t.timestamps limit: 3, null: false
  348. end
  349. add_index :history_types, [:name], unique: true
  350. create_table :history_objects do |t|
  351. t.string :name, limit: 250, null: false
  352. t.string :note, limit: 250, null: true
  353. t.timestamps limit: 3, null: false
  354. end
  355. add_index :history_objects, [:name], unique: true
  356. create_table :history_attributes do |t|
  357. t.string :name, limit: 250, null: false
  358. t.timestamps limit: 3, null: false
  359. end
  360. add_index :history_attributes, [:name], unique: true
  361. create_table :histories do |t|
  362. t.references :history_type, null: false
  363. t.references :history_object, null: false
  364. t.references :history_attribute, null: true
  365. t.integer :o_id, null: false
  366. t.integer :related_o_id, null: true
  367. t.integer :related_history_object_id, null: true
  368. t.integer :id_to, null: true
  369. t.integer :id_from, null: true
  370. t.string :value_from, limit: 500, null: true
  371. t.string :value_to, limit: 500, null: true
  372. t.integer :created_by_id, null: false
  373. t.timestamps limit: 3, null: false
  374. end
  375. add_index :histories, [:o_id]
  376. add_index :histories, [:created_by_id]
  377. add_index :histories, [:created_at]
  378. add_index :histories, [:history_object_id]
  379. add_index :histories, [:history_attribute_id]
  380. add_index :histories, [:history_type_id]
  381. add_index :histories, [:id_to]
  382. add_index :histories, [:id_from]
  383. add_index :histories, [:value_from], length: 255
  384. add_index :histories, [:value_to], length: 255
  385. add_index :histories, [:related_o_id]
  386. add_index :histories, [:related_history_object_id]
  387. add_index :histories, %i[o_id history_object_id related_o_id]
  388. add_foreign_key :histories, :history_types
  389. add_foreign_key :histories, :history_objects
  390. add_foreign_key :histories, :history_attributes
  391. add_foreign_key :histories, :users, column: :created_by_id
  392. create_table :settings do |t|
  393. t.string :title, limit: 200, null: false
  394. t.string :name, limit: 200, null: false
  395. t.string :area, limit: 100, null: false
  396. t.string :description, limit: 2000, null: false
  397. t.text :options, null: true
  398. t.text :state_current, limit: 200.kilobytes + 1, null: true
  399. t.string :state_initial, limit: 2000, null: true
  400. t.boolean :frontend, null: false
  401. t.text :preferences, limit: 200.kilobytes + 1, null: true
  402. t.timestamps limit: 3, null: false
  403. end
  404. add_index :settings, [:name], unique: true
  405. add_index :settings, [:area]
  406. add_index :settings, [:frontend]
  407. create_table :store_objects do |t|
  408. t.string :name, limit: 250, null: false
  409. t.string :note, limit: 250, null: true
  410. t.timestamps limit: 3, null: false
  411. end
  412. add_index :store_objects, [:name], unique: true
  413. create_table :store_files do |t|
  414. t.string :sha, limit: 128, null: false
  415. t.string :provider, limit: 20, null: true
  416. t.timestamps limit: 3, null: false
  417. end
  418. add_index :store_files, [:sha], unique: true
  419. add_index :store_files, [:provider]
  420. create_table :stores do |t|
  421. t.references :store_object, null: false
  422. t.references :store_file, null: false
  423. t.integer :o_id, limit: 8, null: false
  424. t.string :preferences, limit: 2500, null: true
  425. t.string :size, limit: 50, null: true
  426. t.string :filename, limit: 250, null: false
  427. t.integer :created_by_id, null: false
  428. t.timestamps limit: 3, null: false
  429. end
  430. add_index :stores, %i[store_object_id o_id]
  431. add_index :stores, %i[store_file_id]
  432. add_foreign_key :stores, :store_objects
  433. add_foreign_key :stores, :store_files
  434. add_foreign_key :stores, :users, column: :created_by_id
  435. create_table :store_provider_dbs do |t|
  436. t.string :sha, limit: 128, null: false
  437. t.binary :data, limit: 200.megabytes, null: true
  438. t.timestamps limit: 3, null: false
  439. end
  440. add_index :store_provider_dbs, [:sha], unique: true
  441. create_table :avatars do |t|
  442. t.integer :o_id, null: false
  443. t.integer :object_lookup_id, null: false
  444. t.boolean :default, null: false, default: false
  445. t.boolean :deletable, null: false, default: true
  446. t.boolean :initial, null: false, default: false
  447. t.integer :store_full_id, null: true
  448. t.integer :store_resize_id, null: true
  449. t.string :store_hash, limit: 32, null: true
  450. t.string :source, limit: 100, null: false
  451. t.string :source_url, limit: 512, null: true
  452. t.integer :updated_by_id, null: false
  453. t.integer :created_by_id, null: false
  454. t.timestamps limit: 3, null: false
  455. end
  456. add_index :avatars, %i[o_id object_lookup_id]
  457. add_index :avatars, [:store_hash]
  458. add_index :avatars, [:source]
  459. add_index :avatars, [:default]
  460. add_foreign_key :avatars, :users, column: :created_by_id
  461. add_foreign_key :avatars, :users, column: :updated_by_id
  462. create_table :online_notifications do |t|
  463. t.integer :o_id, null: false
  464. t.integer :object_lookup_id, null: false
  465. t.integer :type_lookup_id, null: false
  466. t.integer :user_id, null: false
  467. t.boolean :seen, null: false, default: false
  468. t.integer :updated_by_id, null: false
  469. t.integer :created_by_id, null: false
  470. t.timestamps limit: 3, null: false
  471. end
  472. add_index :online_notifications, [:user_id]
  473. add_index :online_notifications, [:seen]
  474. add_index :online_notifications, [:created_at]
  475. add_index :online_notifications, [:updated_at]
  476. add_foreign_key :online_notifications, :users
  477. add_foreign_key :online_notifications, :users, column: :created_by_id
  478. add_foreign_key :online_notifications, :users, column: :updated_by_id
  479. create_table :schedulers do |t|
  480. t.string :name, limit: 250, null: false
  481. t.string :method, limit: 250, null: false
  482. t.integer :period, null: true
  483. t.integer :running, null: false, default: false
  484. t.timestamp :last_run, limit: 3, null: true
  485. t.integer :prio, null: false
  486. t.string :pid, limit: 250, null: true
  487. t.string :note, limit: 250, null: true
  488. t.string :error_message, null: true
  489. t.string :status, null: true
  490. t.boolean :active, null: false, default: false
  491. t.integer :updated_by_id, null: false
  492. t.integer :created_by_id, null: false
  493. t.timestamps limit: 3, null: false
  494. end
  495. add_index :schedulers, [:name], unique: true
  496. add_foreign_key :schedulers, :users, column: :created_by_id
  497. add_foreign_key :schedulers, :users, column: :updated_by_id
  498. create_table :calendars do |t|
  499. t.string :name, limit: 250, null: true
  500. t.string :timezone, limit: 250, null: true
  501. t.string :business_hours, limit: 3000, null: true
  502. t.boolean :default, null: false, default: false
  503. t.string :ical_url, limit: 500, null: true
  504. t.text :public_holidays, limit: 500.kilobytes + 1, null: true
  505. t.text :last_log, limit: 500.kilobytes + 1, null: true
  506. t.timestamp :last_sync, limit: 3, null: true
  507. t.integer :updated_by_id, null: false
  508. t.integer :created_by_id, null: false
  509. t.timestamps limit: 3, null: false
  510. end
  511. add_index :calendars, [:name], unique: true
  512. add_foreign_key :calendars, :users, column: :created_by_id
  513. add_foreign_key :calendars, :users, column: :updated_by_id
  514. create_table :user_devices do |t|
  515. t.references :user, null: false
  516. t.string :name, limit: 250, null: false
  517. t.string :os, limit: 150, null: true
  518. t.string :browser, limit: 250, null: true
  519. t.string :location, limit: 150, null: true
  520. t.string :device_details, limit: 2500, null: true
  521. t.string :location_details, limit: 2500, null: true
  522. t.string :fingerprint, limit: 160, null: true
  523. t.string :user_agent, limit: 250, null: true
  524. t.string :ip, limit: 160, null: true
  525. t.timestamps limit: 3, null: false
  526. end
  527. add_index :user_devices, [:user_id]
  528. add_index :user_devices, %i[os browser location]
  529. add_index :user_devices, [:fingerprint]
  530. add_index :user_devices, [:updated_at]
  531. add_index :user_devices, [:created_at]
  532. add_foreign_key :user_devices, :users
  533. create_table :external_credentials do |t|
  534. t.string :name
  535. t.string :credentials, limit: 2500, null: false
  536. t.timestamps limit: 3, null: false
  537. end
  538. create_table :object_manager_attributes do |t|
  539. t.references :object_lookup, null: false
  540. t.string :name, limit: 200, null: false
  541. t.string :display, limit: 200, null: false
  542. t.string :data_type, limit: 100, null: false
  543. t.text :data_option, limit: 800.kilobytes + 1, null: true
  544. t.text :data_option_new, limit: 800.kilobytes + 1, null: true
  545. t.boolean :editable, null: false, default: true
  546. t.boolean :active, null: false, default: true
  547. t.string :screens, limit: 2000, null: true
  548. t.boolean :to_create, null: false, default: false
  549. t.boolean :to_migrate, null: false, default: false
  550. t.boolean :to_delete, null: false, default: false
  551. t.boolean :to_config, null: false, default: false
  552. t.integer :position, null: false
  553. t.integer :created_by_id, null: false
  554. t.integer :updated_by_id, null: false
  555. t.timestamps limit: 3, null: false
  556. end
  557. add_index :object_manager_attributes, %i[object_lookup_id name], unique: true
  558. add_index :object_manager_attributes, [:object_lookup_id]
  559. add_foreign_key :object_manager_attributes, :object_lookups
  560. add_foreign_key :object_manager_attributes, :users, column: :created_by_id
  561. add_foreign_key :object_manager_attributes, :users, column: :updated_by_id
  562. create_table :delayed_jobs, force: true do |t|
  563. t.integer :priority, default: 0 # Allows some jobs to jump to the front of the queue
  564. t.integer :attempts, default: 0 # Provides for retries, but still fail eventually.
  565. t.text :handler # YAML-encoded string of the object that will do work
  566. t.text :last_error # reason for last failure (See Note below)
  567. t.datetime :run_at, limit: 3 # When to run. Could be Time.zone.now for immediately, or sometime in the future.
  568. t.datetime :locked_at, limit: 3 # Set when a client is working on this object
  569. t.datetime :failed_at, limit: 3 # Set when all retries have failed (actually, by default, the record is deleted instead)
  570. t.string :locked_by # Who is working on this object (if locked)
  571. t.string :queue # The name of the queue this job is in
  572. t.timestamps limit: 3, null: false
  573. end
  574. add_index :delayed_jobs, %i[priority run_at], name: 'delayed_jobs_priority'
  575. create_table :external_syncs do |t|
  576. t.string :source, limit: 100, null: false
  577. t.string :source_id, limit: 200, null: false
  578. t.string :object, limit: 100, null: false
  579. t.integer :o_id, null: false
  580. t.text :last_payload, limit: 500.kilobytes + 1, null: true
  581. t.timestamps limit: 3, null: false
  582. end
  583. add_index :external_syncs, %i[source source_id], unique: true
  584. add_index :external_syncs, %i[source source_id object o_id], name: 'index_external_syncs_on_source_and_source_id_and_object_o_id'
  585. add_index :external_syncs, %i[object o_id]
  586. create_table :import_jobs do |t|
  587. t.string :name, limit: 250, null: false
  588. t.boolean :dry_run, default: false
  589. t.text :payload, limit: 80_000
  590. t.text :result, limit: 80_000
  591. t.datetime :started_at, limit: 3
  592. t.datetime :finished_at, limit: 3
  593. t.timestamps limit: 3, null: false
  594. end
  595. create_table :cti_logs do |t|
  596. t.string :direction, limit: 20, null: false
  597. t.string :state, limit: 20, null: false
  598. t.string :from, limit: 100, null: false
  599. t.string :from_comment, limit: 250, null: true
  600. t.string :to, limit: 100, null: false
  601. t.string :to_comment, limit: 250, null: true
  602. t.string :queue, limit: 250, null: true
  603. t.string :call_id, limit: 250, null: false
  604. t.string :comment, limit: 500, null: true
  605. t.timestamp :initialized_at, limit: 3, null: true
  606. t.timestamp :start_at, limit: 3, null: true
  607. t.timestamp :end_at, limit: 3, null: true
  608. t.integer :duration_waiting_time, null: true
  609. t.integer :duration_talking_time, null: true
  610. t.boolean :done, null: false, default: true
  611. t.text :preferences, limit: 500.kilobytes + 1, null: true
  612. t.timestamps limit: 3, null: false
  613. end
  614. add_index :cti_logs, [:call_id], unique: true
  615. add_index :cti_logs, [:direction]
  616. add_index :cti_logs, [:from]
  617. create_table :cti_caller_ids do |t|
  618. t.string :caller_id, limit: 100, null: false
  619. t.string :comment, limit: 500, null: true
  620. t.string :level, limit: 100, null: false
  621. t.string :object, limit: 100, null: false
  622. t.integer :o_id, null: false
  623. t.references :user, null: true
  624. t.text :preferences, limit: 500.kilobytes + 1, null: true
  625. t.timestamps limit: 3, null: false
  626. end
  627. add_index :cti_caller_ids, [:caller_id]
  628. add_index :cti_caller_ids, %i[caller_id level]
  629. add_index :cti_caller_ids, %i[caller_id user_id]
  630. add_index :cti_caller_ids, %i[object o_id]
  631. add_index :cti_caller_ids, %i[object o_id level user_id caller_id], name: 'index_cti_caller_ids_on_object_o_id_level_user_id_caller_id'
  632. add_foreign_key :cti_caller_ids, :users
  633. create_table :stats_stores do |t|
  634. t.references :stats_storable, polymorphic: true, index: true
  635. t.string :key, limit: 250, null: true
  636. t.string :data, limit: 5000, null: true
  637. t.integer :created_by_id, null: false
  638. t.timestamps limit: 3, null: false
  639. end
  640. add_index :stats_stores, [:key]
  641. add_index :stats_stores, [:created_by_id]
  642. add_index :stats_stores, [:created_at]
  643. add_foreign_key :stats_stores, :users, column: :created_by_id
  644. create_table :http_logs do |t|
  645. t.column :direction, :string, limit: 20, null: false
  646. t.column :facility, :string, limit: 100, null: false
  647. t.column :method, :string, limit: 100, null: false
  648. t.column :url, :string, limit: 255, null: false
  649. t.column :status, :string, limit: 20, null: true
  650. t.column :ip, :string, limit: 50, null: true
  651. t.column :request, :string, limit: 10_000, null: false
  652. t.column :response, :string, limit: 10_000, null: false
  653. t.column :updated_by_id, :integer, null: true
  654. t.column :created_by_id, :integer, null: true
  655. t.timestamps limit: 3, null: false
  656. end
  657. add_index :http_logs, [:facility]
  658. add_index :http_logs, [:created_by_id]
  659. add_index :http_logs, [:created_at]
  660. add_foreign_key :http_logs, :users, column: :created_by_id
  661. add_foreign_key :http_logs, :users, column: :updated_by_id
  662. create_table :active_job_locks do |t|
  663. t.string :lock_key
  664. t.string :active_job_id
  665. t.timestamps limit: 3
  666. end
  667. add_index :active_job_locks, :lock_key, unique: true
  668. add_index :active_job_locks, :active_job_id, unique: true
  669. create_table :smime_certificates do |t|
  670. t.string :subject, limit: 500, null: false
  671. t.string :doc_hash, limit: 250, null: false
  672. t.string :fingerprint, limit: 250, null: false
  673. t.string :modulus, limit: 1024, null: false
  674. t.datetime :not_before_at, null: true, limit: 3
  675. t.datetime :not_after_at, null: true, limit: 3
  676. t.binary :raw, limit: 10.megabytes, null: false
  677. t.binary :private_key, limit: 10.megabytes, null: true
  678. t.string :private_key_secret, limit: 500, null: true
  679. t.timestamps limit: 3, null: false
  680. end
  681. add_index :smime_certificates, [:fingerprint], unique: true
  682. add_index :smime_certificates, [:modulus]
  683. add_index :smime_certificates, [:subject]
  684. create_table :data_privacy_tasks do |t|
  685. t.column :state, :string, limit: 150, default: 'in process', null: true
  686. t.references :deletable, polymorphic: true
  687. t.text :preferences
  688. t.column :updated_by_id, :integer, null: false
  689. t.column :created_by_id, :integer, null: false
  690. t.timestamps limit: 3, null: false
  691. end
  692. add_index :data_privacy_tasks, [:state]
  693. create_table :mentions do |t|
  694. t.references :mentionable, polymorphic: true, null: false
  695. t.column :user_id, :integer, null: false
  696. t.column :updated_by_id, :integer, null: false
  697. t.column :created_by_id, :integer, null: false
  698. t.timestamps limit: 3, null: false
  699. end
  700. add_index :mentions, %i[mentionable_id mentionable_type user_id], unique: true, name: 'index_mentions_mentionable_user'
  701. add_foreign_key :mentions, :users, column: :created_by_id
  702. add_foreign_key :mentions, :users, column: :updated_by_id
  703. add_foreign_key :mentions, :users, column: :user_id
  704. create_table :core_workflows do |t|
  705. t.string :name, limit: 100, null: false
  706. t.string :object, limit: 100, null: true
  707. t.text :preferences, limit: 500.kilobytes + 1, null: true
  708. t.text :condition_saved, limit: 500.kilobytes + 1, null: true
  709. t.text :condition_selected, limit: 500.kilobytes + 1, null: true
  710. t.text :perform, limit: 500.kilobytes + 1, null: true
  711. t.boolean :active, null: false, default: true
  712. t.boolean :stop_after_match, null: false, default: false
  713. t.boolean :changeable, null: false, default: true
  714. t.integer :priority, null: false, default: 0
  715. t.integer :updated_by_id, null: false
  716. t.integer :created_by_id, null: false
  717. t.timestamps limit: 3, null: false
  718. end
  719. add_index :core_workflows, [:name], unique: true
  720. add_foreign_key :core_workflows, :users, column: :created_by_id
  721. add_foreign_key :core_workflows, :users, column: :updated_by_id
  722. end
  723. end