20120101000001_create_base.rb 45 KB

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