Commit 54b17af7bda8d5d1b00548e25ed8639b1dbf68f7
1 parent
caf99954
Exists in
master
and in
39 other branches
Adding view to count collabs
Showing
1 changed file
with
46 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,46 @@ |
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +from django.db import connections | |
| 3 | +from south.v2 import DataMigration | |
| 4 | + | |
| 5 | +class Migration(DataMigration): | |
| 6 | + | |
| 7 | + def forwards(self, orm): | |
| 8 | + # Selecting trac database | |
| 9 | + connection = connections['trac'] | |
| 10 | + | |
| 11 | + cursor = connection.cursor() | |
| 12 | + cursor.execute(''' | |
| 13 | + CREATE OR REPLACE VIEW ticket_collab_count_view AS | |
| 14 | + SELECT | |
| 15 | + COALESCE (t1.author, t2.author) as author, | |
| 16 | + (COALESCE(t1.count, 0) + COALESCE(t2.count, 0)) as count | |
| 17 | + FROM | |
| 18 | + (SELECT author, count(*) as count | |
| 19 | + FROM ticket_change | |
| 20 | + GROUP BY author | |
| 21 | + ORDER BY author | |
| 22 | + ) AS t1 | |
| 23 | + FULL OUTER JOIN | |
| 24 | + (SELECT reporter as author, count(*) as count | |
| 25 | + FROM ticket | |
| 26 | + GROUP BY reporter | |
| 27 | + ORDER BY reporter | |
| 28 | + ) AS t2 | |
| 29 | + ON t1.author = t2.author; | |
| 30 | + | |
| 31 | + CREATE OR REPLACE VIEW wiki_collab_count_view AS | |
| 32 | + SELECT author, count(*) from wiki GROUP BY author; | |
| 33 | + ''') | |
| 34 | + | |
| 35 | + def backwards(self, orm): | |
| 36 | + # Selecting trac database | |
| 37 | + connection = connections['trac'] | |
| 38 | + | |
| 39 | + cursor = connection.cursor() | |
| 40 | + cursor.execute(''' | |
| 41 | + DROP VIEW ticket_collab_count_view; | |
| 42 | + DROP VIEW wiki_collab_count_view; | |
| 43 | + ''') | |
| 44 | + | |
| 45 | + complete_apps = ['proxy'] | |
| 46 | + symmetrical = True | ... | ... |