0006_views_to_count_collabs.py
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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