Skip to content

Commit ce3430a

Browse files
author
Gabriel Monroy
committed
remove build version so push-hook doesn't have to increment it re #35
1 parent 519969b commit ce3430a

4 files changed

Lines changed: 208 additions & 13 deletions

File tree

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# -*- coding: utf-8 -*-
2+
import datetime
3+
from south.db import db
4+
from south.v2 import SchemaMigration
5+
from django.db import models
6+
7+
8+
class Migration(SchemaMigration):
9+
10+
def forwards(self, orm):
11+
# Removing unique constraint on 'Build', fields ['version', 'formation']
12+
db.delete_unique(u'api_build', ['version', 'formation_id'])
13+
14+
# Deleting field 'Build.version'
15+
db.delete_column(u'api_build', 'version')
16+
17+
18+
def backwards(self, orm):
19+
20+
# User chose to not deal with backwards NULL issues for 'Build.version'
21+
raise RuntimeError("Cannot reverse this migration. 'Build.version' and its values cannot be restored.")
22+
# Adding unique constraint on 'Build', fields ['version', 'formation']
23+
db.create_unique(u'api_build', ['version', 'formation_id'])
24+
25+
26+
models = {
27+
u'api.access': {
28+
'Meta': {'object_name': 'Access'},
29+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
30+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
31+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
32+
'role': ('django.db.models.fields.CharField', [], {'default': "u'user'", 'max_length': '6'}),
33+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
34+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
35+
},
36+
u'api.build': {
37+
'Meta': {'ordering': "[u'-created']", 'object_name': 'Build'},
38+
'checksum': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
39+
'config': ('api.fields.EnvVarsField', [], {'default': "u'null'", 'blank': 'True'}),
40+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
41+
'dockerfile': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
42+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
43+
'output': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
44+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
45+
'procfile': ('api.fields.ProcfileField', [], {'default': "u'null'", 'blank': 'True'}),
46+
'sha': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
47+
'size': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
48+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
49+
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
50+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
51+
},
52+
u'api.config': {
53+
'Meta': {'ordering': "[u'-created']", 'unique_together': "((u'formation', u'version'),)", 'object_name': 'Config'},
54+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
55+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
56+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
57+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
58+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}),
59+
'values': ('api.fields.EnvVarsField', [], {'default': "u'{}'", 'blank': 'True'}),
60+
'version': ('django.db.models.fields.PositiveIntegerField', [], {})
61+
},
62+
u'api.container': {
63+
'Meta': {'unique_together': "((u'formation', u'type', u'num'),)", 'object_name': 'Container'},
64+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
65+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
66+
'id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
67+
'metadata': ('json_field.fields.JSONField', [], {'default': "u'null'", 'blank': 'True'}),
68+
'node': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Node']"}),
69+
'num': ('django.db.models.fields.PositiveIntegerField', [], {}),
70+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
71+
'port': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
72+
'type': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
73+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
74+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
75+
},
76+
u'api.event': {
77+
'Meta': {'object_name': 'Event'},
78+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
79+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
80+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
81+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
82+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
83+
},
84+
u'api.flavor': {
85+
'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Flavor'},
86+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
87+
'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}),
88+
'init': ('api.fields.CloudInitField', [], {}),
89+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
90+
'params': ('api.fields.ParamsField', [], {'default': "u'null'"}),
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+
'containers': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}),
98+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
99+
'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}),
100+
'layers': ('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', [], {}),
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+
'chef_version': ('django.db.models.fields.CharField', [], {'default': "u'11.4.4'", 'max_length': '32'}),
117+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
118+
'environment': ('django.db.models.fields.CharField', [], {'default': "u'_default'", 'max_length': '64'}),
119+
'flavor': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Flavor']"}),
120+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
121+
'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}),
122+
'initial_attributes': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}),
123+
'level': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
124+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
125+
'run_list': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
126+
'ssh_private_key': ('django.db.models.fields.TextField', [], {}),
127+
'ssh_public_key': ('django.db.models.fields.TextField', [], {}),
128+
'ssh_username': ('django.db.models.fields.CharField', [], {'default': "u'ubuntu'", 'max_length': '64'}),
129+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
130+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
131+
},
132+
u'api.node': {
133+
'Meta': {'unique_together': "((u'formation', u'id'),)", 'object_name': 'Node'},
134+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
135+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
136+
'fqdn': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
137+
'id': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
138+
'layer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Layer']"}),
139+
'num': ('django.db.models.fields.PositiveIntegerField', [], {}),
140+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
141+
'provider_id': ('django.db.models.fields.SlugField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'}),
142+
'status': ('api.fields.NodeStatusField', [], {'default': "u'null'", 'null': 'True', 'blank': 'True'}),
143+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
144+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
145+
},
146+
u'api.provider': {
147+
'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Provider'},
148+
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
149+
'creds': ('api.fields.CredentialsField', [], {'default': "u'null'"}),
150+
'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}),
151+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
152+
'type': ('django.db.models.fields.SlugField', [], {'max_length': '16'}),
153+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
154+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'})
155+
},
156+
u'api.release': {
157+
'Meta': {'ordering': "[u'-created']", 'unique_together': "((u'formation', u'version'),)", 'object_name': 'Release'},
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+
'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}),
162+
'image': ('django.db.models.fields.CharField', [], {'default': "u'ubuntu'", 'max_length': '256'}),
163+
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
164+
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
165+
'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}),
166+
'version': ('django.db.models.fields.PositiveIntegerField', [], {})
167+
},
168+
u'auth.group': {
169+
'Meta': {'object_name': 'Group'},
170+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
171+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
172+
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
173+
},
174+
u'auth.permission': {
175+
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
176+
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
177+
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
178+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
179+
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
180+
},
181+
u'auth.user': {
182+
'Meta': {'object_name': 'User'},
183+
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
184+
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
185+
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
186+
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
187+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
188+
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
189+
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
190+
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
191+
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
192+
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
193+
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
194+
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
195+
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
196+
},
197+
u'contenttypes.contenttype': {
198+
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
199+
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
200+
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
201+
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
202+
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
203+
}
204+
}
205+
206+
complete_apps = ['api']

api/models.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,6 @@ class Build(UuidAuditedModel):
662662

663663
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
664664
formation = models.ForeignKey('Formation')
665-
version = models.PositiveIntegerField()
666-
667665
sha = models.CharField('SHA', max_length=255, blank=True)
668666
output = models.TextField(blank=True)
669667

@@ -678,7 +676,6 @@ class Build(UuidAuditedModel):
678676
class Meta:
679677
get_latest_by = 'created'
680678
ordering = ['-created']
681-
unique_together = (('formation', 'version'),)
682679

683680
def __str__(self):
684681
return '{0}-v{1}'.format(self.formation.id, self.version)
@@ -694,10 +691,10 @@ def push(cls, push):
694691
# SECURITY:
695692
# we assume the first part of the ssh key name
696693
# is the authenticated user because we trust gitosis
697-
username = push.pop('ssh_key').split('_')[0]
694+
username = push.pop('username').split('_')[0]
698695
# retrieve the user and formation instances
699696
user = User.objects.get(username=username)
700-
formation = Formation.objects.get(owner=push['owner'],
697+
formation = Formation.objects.get(owner=user,
701698
id=push.pop('formation'))
702699
# merge the push with the required model instances
703700
push['owner'] = user

api/tests/build.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def test_build(self):
6363
self.assertEqual(response.status_code, 201)
6464
build1 = response.data
6565
self.assertEqual(response.data['url'], body['url'])
66-
self.assertEqual(response.data['version'], 1)
6766
# read the build
6867
response = self.client.get(url)
6968
self.assertEqual(response.status_code, 200)
@@ -80,7 +79,6 @@ def test_build(self):
8079
response = self.client.post(url, json.dumps(body), content_type='application/json')
8180
self.assertEqual(response.status_code, 201)
8281
build3 = response.data
83-
self.assertEqual(response.data['version'], 2)
8482
self.assertEqual(response.data['url'], body['url'])
8583
self.assertNotEqual(build2['uuid'], build3['uuid'])
8684
# disallow put/patch/delete

api/views.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from django.conf import settings
1111
from django.contrib.auth.models import Group, AnonymousUser, User
1212
from django.db.utils import IntegrityError
13-
from django.http.response import Http404
1413
from django.utils import timezone
1514
from rest_framework import permissions, status, viewsets
1615
from rest_framework.authentication import BaseAuthentication
@@ -399,11 +398,6 @@ def post_save(self, obj, created=False):
399398

400399
def create(self, request, *args, **kwargs):
401400
request._data = request.DATA.copy()
402-
try:
403-
obj = self.get_object()
404-
request.DATA['version'] = obj.version + 1
405-
except Http404:
406-
request.DATA['version'] = 1
407401
formation = models.Formation.objects.get(
408402
owner=self.request.user, id=self.kwargs['id'])
409403
request.DATA['formation'] = formation

0 commit comments

Comments
 (0)