20120101000001_create_base.rb 42 KB

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