20120101000001_create_base.rb 34 KB

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