20120101000001_create_base.rb 40 KB

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