Skip to content

Commit 85954c0

Browse files
committed
Fixed #368 -- add model custom permissions in migration.
1 parent 5dcd7a5 commit 85954c0

4 files changed

Lines changed: 424 additions & 26 deletions

File tree

api/migrations/0002_drop_djcelery_and_socialaccount.py renamed to api/migrations/0002_drop_djcelery.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,36 @@
33
from south.db import db
44
from south.v2 import SchemaMigration
55
from django.db import models
6-
from django.db.utils import OperationalError
6+
from django.db.utils import ProgrammingError
7+
from django.contrib.contenttypes.models import ContentType
78

89

910
class Migration(SchemaMigration):
1011

12+
# Deleting content_types raises an error if guardian isn't yet installed.
13+
depends_on = (
14+
('guardian', '0005_auto__chg_field_groupobjectpermission_object_pk__chg_field_userobjectp'),
15+
)
16+
1117
def forwards(self, orm):
12-
# Drop django-celery tables
13-
try:
14-
db.delete_table('djcelery_taskstate', cascade=True)
15-
db.delete_table('djcelery_workerstate', cascade=True)
16-
db.delete_table('djcelery_periodictask', cascade=True)
17-
db.delete_table('djcelery_periodictasks', cascade=True)
18-
db.delete_table('djcelery_crontabschedule', cascade=True)
19-
db.delete_table('djcelery_intervalschedule', cascade=True)
20-
db.delete_table('celery_tasksetmeta', cascade=True)
21-
db.delete_table('celery_taskmeta', cascade=True)
22-
except OperationalError:
23-
pass
24-
# Drop django-allauth.socialaccount tables
25-
try:
26-
db.delete_table('socialaccount_socialtoken', cascade=True)
27-
db.delete_table('socialaccount_socialaccount', cascade=True)
28-
db.delete_table('socialaccount_socialapp', cascade=True)
29-
db.delete_table('socialaccount_socialapp_sites', cascade=True)
30-
except OperationalError:
31-
pass
18+
"Drop django-celery tables."
19+
tables_to_drop = [
20+
'djcelery_taskstate',
21+
'djcelery_workerstate',
22+
'djcelery_periodictask',
23+
'djcelery_periodictasks',
24+
'djcelery_crontabschedule',
25+
'djcelery_intervalschedule',
26+
'celery_tasksetmeta',
27+
'celery_taskmeta',
28+
]
29+
for table in tables_to_drop:
30+
if table in orm:
31+
db.delete_table(table)
32+
ContentType.objects.filter(app_label='djcelery').delete()
3233

3334
def backwards(self, orm):
34-
pass
35+
raise RuntimeError('Cannot reverse this migration')
3536

3637
models = {
3738
u'api.app': {
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# -*- coding: utf-8 -*-
2+
from south.utils import datetime_utils as datetime
3+
from south.db import db
4+
from south.v2 import DataMigration
5+
from django.conf import settings
6+
from django.db import models
7+
from django.contrib.auth.management import create_permissions
8+
from django.contrib.contenttypes.models import ContentType
9+
10+
11+
class Migration(DataMigration):
12+
13+
depends_on = (
14+
('guardian', '0005_auto__chg_field_groupobjectpermission_object_pk__chg_field_userobjectp'),
15+
)
16+
17+
def forwards(self, orm):
18+
"Drop socialaccount tables."
19+
tables_to_drop = [
20+
'socialaccount_socialtoken',
21+
'socialaccount_socialaccount',
22+
'socialaccount_socialapp',
23+
'socialaccount_socialapp_sites',
24+
]
25+
for table in tables_to_drop:
26+
if table in orm:
27+
db.delete_table(table)
28+
ContentType.objects.filter(app_label='socialaccount').delete()
29+
30+
def backwards(self, orm):
31+
raise RuntimeError('Cannot reverse this migration')
32+
33+
models = {
34+
u'api.app': {
35+
'Meta': {'object_name': 'App'},
36+
'containers': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}),
37+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
38+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
39+
'id': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '64'}),
40+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
41+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
42+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
43+
},
44+
u'api.build': {
45+
'Meta': {'ordering': "[u'-created']", 'unique_together': "((u'app', u'uuid'),)", 'object_name': 'Build'},
46+
'app': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.App']"}),
47+
'checksum': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
48+
'config': ('json_field.fields.JSONField', [], {'default': "u'null'", 'blank': 'True'}),
49+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
50+
'dockerfile': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
51+
'image': ('django.db.models.fields.CharField', [], {'default': "u'deis/buildstep'", 'max_length': '256'}),
52+
'output': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
53+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
54+
'procfile': ('json_field.fields.JSONField', [], {'default': "u'null'", 'blank': 'True'}),
55+
'sha': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
56+
'size': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
57+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
58+
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
59+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
60+
},
61+
u'api.config': {
62+
'Meta': {'ordering': "[u'-created']", 'unique_together': "((u'app', u'version'),)", 'object_name': 'Config'},
63+
'app': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.App']"}),
64+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
65+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
66+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
67+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}),
68+
'values': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}),
69+
'version': ('django.db.models.fields.PositiveIntegerField', [], {})
70+
},
71+
u'api.container': {
72+
'Meta': {'ordering': "[u'created']", 'unique_together': "((u'app', u'type', u'num'), (u'formation', u'port'))", 'object_name': 'Container'},
73+
'app': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.App']"}),
74+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
75+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
76+
'node': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Node']"}),
77+
'num': ('django.db.models.fields.PositiveIntegerField', [], {}),
78+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
79+
'port': ('django.db.models.fields.PositiveIntegerField', [], {}),
80+
'status': ('django.db.models.fields.CharField', [], {'default': "u'up'", 'max_length': '64'}),
81+
'type': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
82+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
83+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
84+
},
85+
u'api.flavor': {
86+
'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Flavor'},
87+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
88+
'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}),
89+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
90+
'params': ('json_field.fields.JSONField', [], {'default': "u'null'", 'blank': 'True'}),
91+
'provider': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Provider']"}),
92+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
93+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
94+
},
95+
u'api.formation': {
96+
'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Formation'},
97+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
98+
'domain': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
99+
'id': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '64'}),
100+
'nodes': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}),
101+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
102+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
103+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
104+
},
105+
u'api.key': {
106+
'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Key'},
107+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
108+
'id': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
109+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
110+
'public': ('django.db.models.fields.TextField', [], {'unique': 'True'}),
111+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
112+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
113+
},
114+
u'api.layer': {
115+
'Meta': {'unique_together': "((u'formation', u'id'),)", 'object_name': 'Layer'},
116+
'config': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}),
117+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
118+
'flavor': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Flavor']"}),
119+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
120+
'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}),
121+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
122+
'proxy': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
123+
'runtime': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
124+
'ssh_port': ('django.db.models.fields.SmallIntegerField', [], {'default': '22'}),
125+
'ssh_private_key': ('django.db.models.fields.TextField', [], {}),
126+
'ssh_public_key': ('django.db.models.fields.TextField', [], {}),
127+
'ssh_username': ('django.db.models.fields.CharField', [], {'default': "u'ubuntu'", 'max_length': '64'}),
128+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
129+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
130+
},
131+
u'api.node': {
132+
'Meta': {'unique_together': "((u'formation', u'id'),)", 'object_name': 'Node'},
133+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
134+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
135+
'fqdn': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
136+
'id': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
137+
'layer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Layer']"}),
138+
'num': ('django.db.models.fields.PositiveIntegerField', [], {}),
139+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
140+
'provider_id': ('django.db.models.fields.SlugField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'}),
141+
'status': ('json_field.fields.JSONField', [], {'default': "u'null'", 'null': 'True', 'blank': 'True'}),
142+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
143+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
144+
},
145+
u'api.provider': {
146+
'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Provider'},
147+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
148+
'creds': ('json_field.fields.JSONField', [], {'default': "u'null'", 'blank': 'True'}),
149+
'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}),
150+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
151+
'type': ('django.db.models.fields.SlugField', [], {'max_length': '16'}),
152+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
153+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
154+
},
155+
u'api.release': {
156+
'Meta': {'ordering': "[u'-created']", 'unique_together': "((u'app', u'version'),)", 'object_name': 'Release'},
157+
'app': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.App']"}),
158+
'build': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Build']", 'null': 'True', 'blank': 'True'}),
159+
'config': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Config']"}),
160+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
161+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
162+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
163+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}),
164+
'version': ('django.db.models.fields.PositiveIntegerField', [], {})
165+
},
166+
u'auth.group': {
167+
'Meta': {'object_name': 'Group'},
168+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
169+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
170+
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
171+
},
172+
u'auth.permission': {
173+
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
174+
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
175+
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
176+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
177+
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
178+
},
179+
u'auth.user': {
180+
'Meta': {'object_name': 'User'},
181+
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
182+
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
183+
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
184+
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
185+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
186+
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
187+
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
188+
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
189+
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
190+
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
191+
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
192+
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
193+
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
194+
},
195+
u'contenttypes.contenttype': {
196+
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
197+
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
198+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
199+
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
200+
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
201+
}
202+
}
203+
204+
complete_apps = ['contenttypes', 'auth', 'api']
205+
symmetrical = True

0 commit comments

Comments
 (0)