From 54b17af7bda8d5d1b00548e25ed8639b1dbf68f7 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Mon, 2 Dec 2013 14:48:53 -0200 Subject: [PATCH] Adding view to count collabs --- .../migrations/0006_views_to_count_collabs.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/proxy/migrations/0006_views_to_count_collabs.py diff --git a/src/proxy/migrations/0006_views_to_count_collabs.py b/src/proxy/migrations/0006_views_to_count_collabs.py new file mode 100644 index 00000000..1aa46633 --- /dev/null +++ b/src/proxy/migrations/0006_views_to_count_collabs.py @@ -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