~lifeless/python-oops-tools/bug-881400

« back to all changes in this revision

Viewing changes to src/oopstools/oops/migrations/0008_initial_prefixes.py

  • Committer: Robert Collins
  • Date: 2011-10-13 20:18:51 UTC
  • Revision ID: robertc@robertcollins.net-20111013201851-ym8jmdhoeol3p83s
Export of cruft-deleted tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2005-2011 Canonical Ltd.  All rights reserved.
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU Affero General Public License as published by
 
5
# the Free Software Foundation, either version 3 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU Affero General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU Affero General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
from string import ascii_uppercase
 
17
 
 
18
from south.v2 import DataMigration
 
19
 
 
20
 
 
21
class Migration(DataMigration):
 
22
 
 
23
    def forwards(self, orm):
 
24
        """Data migration for OOPS prefixes.
 
25
 
 
26
        This data migration adds all prefixes needed by oops-tools tests.
 
27
        """
 
28
        appinstances_dict = {
 
29
            'staging': ["S", "X"]
 
30
            }
 
31
 
 
32
        for appinstance in appinstances_dict.keys():
 
33
            for prefix in appinstances_dict[appinstance]:
 
34
                a = orm.AppInstance.objects.get(title=appinstance)
 
35
                # If the prefix doesn't exist in the database, then add it.
 
36
                # This is to cope with the data already in the database added
 
37
                # by the previous mechanism using initial_data.json
 
38
                try:
 
39
                    p = orm.Prefix.objects.get(value=prefix)
 
40
                except orm.Prefix.DoesNotExist:
 
41
                    p = orm.Prefix(value=prefix, appinstance=a)
 
42
                p.save()
 
43
 
 
44
    def backwards(self, orm):
 
45
        raise RuntimeError("Can not reverse this migration.")
 
46
 
 
47
    models = {
 
48
        'oops.appinstance': {
 
49
            'Meta': {'object_name': 'AppInstance'},
 
50
            'id': ('django.db.models.fields.AutoField', [],
 
51
                {'primary_key': 'True'}),
 
52
            'title': ('django.db.models.fields.CharField', [],
 
53
                {'unique': 'True', 'max_length': '50'})
 
54
        },
 
55
        'oops.classification': {
 
56
            'Meta': {'object_name': 'Classification'},
 
57
            'id': ('django.db.models.fields.AutoField', [],
 
58
                {'primary_key': 'True'}),
 
59
            'title': ('django.db.models.fields.CharField', [],
 
60
                {'unique': 'True', 'max_length': '100'})
 
61
        },
 
62
        'oops.dboopsrootdirectory': {
 
63
            'Meta': {'object_name': 'DBOopsRootDirectory'},
 
64
            'id': ('django.db.models.fields.AutoField', [],
 
65
                {'primary_key': 'True'}),
 
66
            'last_date': ('django.db.models.fields.DateField', [],
 
67
                {'null': 'True'}),
 
68
            'last_oops': ('django.db.models.fields.CharField', [],
 
69
                {'max_length': '200', 'null': 'True'}),
 
70
            'root_dir': ('django.db.models.fields.CharField', [],
 
71
                {'unique': 'True', 'max_length': '200'})
 
72
        },
 
73
        'oops.infestation': {
 
74
            'Meta': {'unique_together':
 
75
                "(('exception_type', 'exception_value'),)",
 
76
                'object_name': 'Infestation'},
 
77
            'bug': ('django.db.models.fields.PositiveIntegerField', [],
 
78
                {'null': 'True'}),
 
79
            'exception_type': ('django.db.models.fields.CharField', [],
 
80
                {'max_length': '100'}),
 
81
            'exception_value': ('django.db.models.fields.CharField', [],
 
82
                {'max_length': '1000'}),
 
83
            'id': ('django.db.models.fields.AutoField', [],
 
84
                {'primary_key': 'True'}),
 
85
        },
 
86
        'oops.oops': {
 
87
            'Meta': {'object_name': 'Oops'},
 
88
            'appinstance': ('django.db.models.fields.related.ForeignKey', [],
 
89
                {'to': "orm['oops.AppInstance']"}),
 
90
            'classification': ('django.db.models.fields.related.ForeignKey', [],
 
91
                {'to': "orm['oops.Classification']", 'null': 'True'}),
 
92
            'date': ('django.db.models.fields.DateTimeField', [],
 
93
                {'db_index': 'True'}),
 
94
            'duration': ('django.db.models.fields.FloatField', [],
 
95
                {'null': 'True'}),
 
96
            'http_method': ('django.db.models.fields.CharField', [],
 
97
                {'max_length': '10', 'null': 'True'}),
 
98
            'id': ('django.db.models.fields.AutoField', [],
 
99
                {'primary_key': 'True'}),
 
100
            'informational': ('django.db.models.fields.NullBooleanField', [],
 
101
                {'null': 'True'}),
 
102
            'is_bot': ('django.db.models.fields.NullBooleanField', [],
 
103
                {'null': 'True', 'db_index': 'True'}),
 
104
            'is_local_referrer': ('django.db.models.fields.NullBooleanField', [],
 
105
                {'null': 'True', 'db_index': 'True'}),
 
106
            'most_expensive_statement': ('django.db.models.fields.CharField', [],
 
107
                {'max_length': '200', 'null': 'True', 'db_index': 'True'}),
 
108
            'oopsid': ('django.db.models.fields.CharField', [],
 
109
                {'unique': 'True', 'max_length': '200'}),
 
110
            'oopsinfestation': ('django.db.models.fields.related.ForeignKey', [],
 
111
                {'to': "orm['oops.Infestation']"}),
 
112
            'pageid': ('django.db.models.fields.CharField', [],
 
113
                {'max_length': '500'}),
 
114
            'pathname': ('django.db.models.fields.CharField', [],
 
115
                {'unique': 'True', 'max_length': '200'}),
 
116
            'prefix': ('django.db.models.fields.related.ForeignKey', [],
 
117
                {'to': "orm['oops.Prefix']"}),
 
118
            'referrer': ('django.db.models.fields.URLField', [],
 
119
                {'max_length': '500', 'null': 'True'}),
 
120
            'statements_count': ('django.db.models.fields.PositiveIntegerField', [],
 
121
                {}),
 
122
            'time_is_estimate': ('django.db.models.fields.NullBooleanField', [],
 
123
                {'null': 'True'}),
 
124
            'total_time': ('django.db.models.fields.PositiveIntegerField', [],
 
125
                {}),
 
126
            'url': ('django.db.models.fields.URLField', [],
 
127
                {'max_length': '500', 'null': 'True', 'db_index': 'True'}),
 
128
            'user_agent': ('django.db.models.fields.CharField', [],
 
129
                {'max_length': '200', 'null': 'True'})
 
130
        },
 
131
        'oops.prefix': {
 
132
            'Meta': {'object_name': 'Prefix'},
 
133
            'appinstance': ('django.db.models.fields.related.ForeignKey', [],
 
134
                {'to': "orm['oops.AppInstance']"}),
 
135
            'id': ('django.db.models.fields.AutoField', [],
 
136
                {'primary_key': 'True'}),
 
137
            'value': ('django.db.models.fields.CharField', [],
 
138
                {'unique': 'True', 'max_length': '20'})
 
139
        },
 
140
        'oops.project': {
 
141
            'Meta': {'object_name': 'Project'},
 
142
            'id': ('django.db.models.fields.AutoField', [],
 
143
                {'primary_key': 'True'}),
 
144
            'title': ('django.db.models.fields.CharField', [],
 
145
                {'unique': 'True', 'max_length': '200'})
 
146
        },
 
147
    }
 
148
 
 
149
    complete_apps = ['oops']