summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-03-07 11:37:03 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-03-07 11:37:03 +0100
commit11f186a118285fbc87a536af26730780a9ad01f5 (patch)
treefe6363b036f60f238916d070b3d0cb0625dd53c8 /db/migrate
parent2b94b16ee1201d15b3b9d66e142df311141a47db (diff)
parent3e19646f46c772e10ed3d7a45e8c974ab23f625b (diff)
Merge branch 'develop'5.1.1
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20130307065200_create_calls_active.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/db/migrate/20130307065200_create_calls_active.rb b/db/migrate/20130307065200_create_calls_active.rb
new file mode 100644
index 0000000..0ea877d
--- /dev/null
+++ b/db/migrate/20130307065200_create_calls_active.rb
@@ -0,0 +1,75 @@
+class CreateCallsActive < ActiveRecord::Migration
+ def self.up
+ if ActiveRecord::Base.connection_config[:adapter] != 'sqlite3'
+ execute <<-SQL
+ CREATE VIEW calls_active AS SELECT
+ a.uuid AS uuid,
+ a.direction AS direction,
+ a.created_epoch AS start_stamp,
+ a.cid_name AS caller_id_name,
+ a.cid_num AS caller_id_number,
+ a.dest AS destination,
+ d.id AS sip_account_id,
+ d.caller_name AS sip_caller_name,
+ a.callee_name as callee_name,
+ a.callee_num as callee_number,
+ a.callstate AS callstate,
+ a.read_codec AS read_codec,
+ a.read_rate AS read_rate,
+ a.read_bit_rate AS read_bit_rate,
+ a.write_codec AS write_codec,
+ a.write_rate AS write_rate,
+ a.write_bit_rate AS write_bit_rate,
+ a.secure AS secure,
+ b.uuid AS b_uuid,
+ b.cid_name AS b_caller_id_name,
+ b.cid_num AS b_caller_id_number,
+ e.id AS b_sip_account_id,
+ e.caller_name AS b_sip_caller_name
+ FROM channels a
+ LEFT JOIN calls c ON a.uuid = c.caller_uuid AND a.hostname = c.hostname
+ LEFT JOIN channels b ON b.uuid = c.callee_uuid AND b.hostname = c.hostname
+ LEFT JOIN sip_accounts d ON a.presence_id LIKE CONCAT(d.auth_name, "@%")
+ LEFT JOIN sip_accounts e ON b.presence_id LIKE CONCAT(e.auth_name, "@%")
+ WHERE a.uuid = c.caller_uuid OR a.uuid NOT IN (select callee_uuid from calls)
+ SQL
+ else
+ execute <<-SQL
+ CREATE VIEW calls_active AS SELECT
+ a.uuid AS uuid,
+ a.direction AS direction,
+ a.created_epoch AS start_stamp,
+ a.cid_name AS caller_id_name,
+ a.cid_num AS caller_id_number,
+ a.dest AS destination,
+ d.id AS sip_account_id,
+ d.caller_name AS sip_caller_name,
+ a.callee_name as callee_name,
+ a.callee_num as callee_number,
+ a.callstate AS callstate,
+ a.read_codec AS read_codec,
+ a.read_rate AS read_rate,
+ a.read_bit_rate AS read_bit_rate,
+ a.write_codec AS write_codec,
+ a.write_rate AS write_rate,
+ a.write_bit_rate AS write_bit_rate,
+ a.secure AS secure,
+ b.uuid AS b_uuid,
+ b.cid_name AS b_caller_id_name,
+ b.cid_num AS b_caller_id_number,
+ e.id AS b_sip_account_id,
+ e.caller_name AS b_sip_caller_name
+ FROM channels a
+ LEFT JOIN calls c ON a.uuid = c.caller_uuid AND a.hostname = c.hostname
+ LEFT JOIN channels b ON b.uuid = c.callee_uuid AND b.hostname = c.hostname
+ LEFT JOIN sip_accounts d ON a.presence_id LIKE (d.auth_name || "@%")
+ LEFT JOIN sip_accounts e ON b.presence_id LIKE (e.auth_name || "@%")
+ WHERE a.uuid = c.caller_uuid OR a.uuid NOT IN (select callee_uuid from calls)
+ SQL
+ end
+ end
+
+ def self.down
+ execute "DROP VIEW calls_active"
+ end
+end \ No newline at end of file