20160422000003_create_cti_log.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.text :preferences, limit: 500.kilobytes + 1, null: true
  16. t.timestamps null: false
  17. end
  18. add_index :cti_logs, [:call_id], unique: true
  19. add_index :cti_logs, [:direction]
  20. add_index :cti_logs, [:from]
  21. create_table :cti_caller_ids do |t|
  22. t.string :caller_id, limit: 100, null: false
  23. t.string :comment, limit: 500, null: true
  24. t.string :level, limit: 100, null: false
  25. t.string :object, limit: 100, null: false
  26. t.integer :o_id, null: false
  27. t.integer :user_id, null: true
  28. t.text :preferences, limit: 500.kilobytes + 1, null: true
  29. t.timestamps null: false
  30. end
  31. add_index :cti_caller_ids, [:caller_id]
  32. add_index :cti_caller_ids, [:caller_id, :level]
  33. add_index :cti_caller_ids, [:caller_id, :user_id]
  34. add_index :cti_caller_ids, [:object, :o_id]
  35. # return if it's a new setup
  36. return if !Setting.find_by(name: 'system_init_done')
  37. Role.create_if_not_exists(
  38. name: 'CTI',
  39. note: 'Access to CTI feature.',
  40. updated_by_id: 1,
  41. created_by_id: 1
  42. )
  43. Setting.create_if_not_exists(
  44. title: 'Define transaction backend.',
  45. name: '9100_cti_caller_id_detection',
  46. area: 'Transaction::Backend::Async',
  47. description: 'Define the transaction backend which detects caller ids in objects and store them for cti lookups.',
  48. options: {},
  49. state: 'Transaction::CtiCallerIdDetection',
  50. frontend: false
  51. )
  52. end
  53. end