Skip to content

Commit

Permalink
Adding view to count collabs
Browse files Browse the repository at this point in the history
  • Loading branch information
seocam committed Dec 2, 2013
1 parent caf9995 commit 54b17af
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/proxy/migrations/0006_views_to_count_collabs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
from django.db import connections
from south.v2 import DataMigration

class Migration(DataMigration):

def forwards(self, orm):
# Selecting trac database
connection = connections['trac']

cursor = connection.cursor()
cursor.execute('''
CREATE OR REPLACE VIEW ticket_collab_count_view AS
SELECT
COALESCE (t1.author, t2.author) as author,
(COALESCE(t1.count, 0) + COALESCE(t2.count, 0)) as count
FROM
(SELECT author, count(*) as count
FROM ticket_change
GROUP BY author
ORDER BY author
) AS t1
FULL OUTER JOIN
(SELECT reporter as author, count(*) as count
FROM ticket
GROUP BY reporter
ORDER BY reporter
) AS t2
ON t1.author = t2.author;
CREATE OR REPLACE VIEW wiki_collab_count_view AS
SELECT author, count(*) from wiki GROUP BY author;
''')

def backwards(self, orm):
# Selecting trac database
connection = connections['trac']

cursor = connection.cursor()
cursor.execute('''
DROP VIEW ticket_collab_count_view;
DROP VIEW wiki_collab_count_view;
''')

complete_apps = ['proxy']
symmetrical = True

0 comments on commit 54b17af

Please sign in to comment.