20160422000003_create_cti_log.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class CreateCtiLog < ActiveRecord::Migration
  2. def up
  3. create_table :cti_logs do |t|
  4. t.string :direction, limit: 20, null: false
  5. t.string :state, limit: 20, null: false
  6. t.string :from, limit: 100, null: false
  7. t.string :from_comment, limit: 250, null: true
  8. t.string :to, limit: 100, null: false
  9. t.string :to_comment, limit: 250, null: true
  10. t.string :call_id, limit: 250, null: false
  11. t.string :comment, limit: 500, null: true
  12. t.timestamp :start, null: true
  13. t.timestamp :end, null: true
  14. t.boolean :done, null: false, default: true
  15. t.timestamps null: false
  16. end
  17. add_index :cti_logs, [:call_id], unique: true
  18. add_index :cti_logs, [:direction]
  19. add_index :cti_logs, [:from]
  20. create_table :cti_caller_ids do |t|
  21. t.string :caller_id, limit: 100, null: false
  22. t.string :comment, limit: 500, null: true
  23. t.string :level, limit: 100, null: false
  24. t.string :object, limit: 100, null: false
  25. t.integer :o_id, null: false
  26. t.integer :user_id, null: true
  27. t.text :preferences, limit: 500.kilobytes + 1, null: true
  28. t.timestamps null: false
  29. end
  30. add_index :cti_caller_ids, [:caller_id]
  31. add_index :cti_caller_ids, [:caller_id, :level]
  32. add_index :cti_caller_ids, [:caller_id, :user_id]
  33. add_index :cti_caller_ids, [:object, :o_id]
  34. # return if it's a new setup
  35. return if !Setting.find_by(name: 'system_init_done')
  36. Role.create_if_not_exists(
  37. name: 'CTI',
  38. note: 'Access to CTI feature.',
  39. updated_by_id: 1,
  40. created_by_id: 1
  41. )
  42. Setting.create_if_not_exists(
  43. title: 'Define transaction backend.',
  44. name: '9100_cti_caller_id_detection',
  45. area: 'Transaction::Backend',
  46. description: 'Define the transaction backend which detects caller ids in objects and store them for cti lookups.',
  47. options: {},
  48. state: 'Transaction::CtiCallerIdDetection',
  49. frontend: false
  50. )
  51. end
  52. end