Skip to content

Commit

Permalink
Adding Newton support things:
Browse files Browse the repository at this point in the history
- sid instead of id.
- unique verbs
- extra_data in Relationship

Slugs -> SlugField.

Compressing migrations into one file.

Rename related names to be more appropriate.

Fix a duplicate pk in initial_data
  • Loading branch information
Aniruddha Maru committed Sep 8, 2014
1 parent b2da26c commit d7c95bd
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 470 deletions.
12 changes: 6 additions & 6 deletions relationships/fixtures/initial_data.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[
{
"pk": 1,
"model": "relationships.relationshipstatus",
"model": "relationships.relationshipstatus",
"fields": {
"name": "Following",
"id": "RS_2c249083b333a261",
"name": "Following",
"to_slug": "followers",
"from_slug": "following",
"symmetrical_slug": "friends",
"verb": "follow"
}
},
{
"pk": 2,
"model": "relationships.relationshipstatus",
"model": "relationships.relationshipstatus",
"fields": {
"name": "Blocking",
"id": "RS_718a303ac84ccb20",
"name": "Blocking",
"to_slug": "blockers",
"from_slug": "blocking",
"symmetrical_slug": "!",
Expand Down
147 changes: 79 additions & 68 deletions relationships/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,102 +1,113 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from relationships.models import *
from south.v2 import SchemaMigration
from django.db import models

from ..utils import (User, user_orm_label, user_model_label)

class Migration:

def forwards(self, orm):
class Migration(SchemaMigration):

def forwards(self, orm):
# Adding model 'RelationshipStatus'
db.create_table('relationships_relationshipstatus', (
('id', orm['relationships.RelationshipStatus:id']),
('name', orm['relationships.RelationshipStatus:name']),
('verb', orm['relationships.RelationshipStatus:verb']),
('from_slug', orm['relationships.RelationshipStatus:from_slug']),
('to_slug', orm['relationships.RelationshipStatus:to_slug']),
('symmetrical_slug', orm['relationships.RelationshipStatus:symmetrical_slug']),
('login_required', orm['relationships.RelationshipStatus:login_required']),
('private', orm['relationships.RelationshipStatus:private']),
db.create_table(u'relationships_relationshipstatus', (
('id', self.gf('relationships.models.SIDField')(default='RS_e2988c32b44df4d0', unique=True, max_length=20, primary_key=True, db_index=True)),
('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
('verb', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=100)),
('from_slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=100)),
('to_slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=100)),
('symmetrical_slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=100)),
('login_required', self.gf('django.db.models.fields.BooleanField')(default=False)),
('private', self.gf('django.db.models.fields.BooleanField')(default=False)),
))
db.send_create_signal('relationships', ['RelationshipStatus'])
db.send_create_signal(u'relationships', ['RelationshipStatus'])

# Adding model 'Relationship'
db.create_table('relationships_relationship', (
('id', orm['relationships.Relationship:id']),
('from_user', orm['relationships.Relationship:from_user']),
('to_user', orm['relationships.Relationship:to_user']),
('status', orm['relationships.Relationship:status']),
('created', orm['relationships.Relationship:created']),
db.create_table(u'relationships_relationship', (
('id', self.gf('relationships.models.SIDField')(default='R_4d4e7df6f454c503', unique=True, max_length=20, primary_key=True, db_index=True)),
('from_user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='from_users', to=orm[user_orm_label])),
('to_user', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='to_users', null=True, to=orm[user_orm_label])),
('status', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['relationships.RelationshipStatus'])),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('weight', self.gf('django.db.models.fields.FloatField')(default=1.0, null=True, blank=True)),
('site', self.gf('django.db.models.fields.related.ForeignKey')(default=1, related_name='relationships', to=orm['sites.Site'])),
('extra_data', self.gf('jsonfield.fields.JSONField')(default=None, null=True, blank=True)),
))
db.send_create_signal('relationships', ['Relationship'])
db.send_create_signal(u'relationships', ['Relationship'])

# Creating unique_together for [from_user, to_user, status] on Relationship.
db.create_unique('relationships_relationship', ['from_user_id', 'to_user_id', 'status_id'])
# Adding unique constraint on 'Relationship', fields ['from_user', 'to_user', 'status', 'site']
db.create_unique(u'relationships_relationship', ['from_user_id', 'to_user_id', 'status_id', 'site_id'])

def backwards(self, orm):

# Deleting unique_together for [from_user, to_user, status] on Relationship.
db.delete_unique('relationships_relationship', ['from_user_id', 'to_user_id', 'status_id'])
def backwards(self, orm):
# Removing unique constraint on 'Relationship', fields ['from_user', 'to_user', 'status', 'site']
db.delete_unique(u'relationships_relationship', ['from_user_id', 'to_user_id', 'status_id', 'site_id'])

# Deleting model 'RelationshipStatus'
db.delete_table('relationships_relationshipstatus')
db.delete_table(u'relationships_relationshipstatus')

# Deleting model 'Relationship'
db.delete_table('relationships_relationship')
db.delete_table(u'relationships_relationship')


models = {
'auth.group': {
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'})
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'unique_together': "(('content_type', 'codename'),)"},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'relationships': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'unique_together': "(('app_label', 'model'),)", 'db_table': "'django_content_type'"},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'relationships.relationship': {
'Meta': {'unique_together': "(('from_user', 'to_user', 'status'),)"},
# http://kevindias.com/writing/django-custom-user-models-south-and-reusable-apps/
user_model_label: {
# We've accounted for changes to:
# the app name, table name, pk attribute name, pk column name.
# The only assumption left is that the pk is an AutoField (see below)
'Meta': { 'object_name': User.__name__, 'db_table': "'%s'" % User._meta.db_table },
User._meta.pk.attname: ('django.db.models.fields.AutoField', [], {'primary_key': 'True', 'db_column': "'%s'" % User._meta.pk.column})
},
u'relationships.relationship': {
'Meta': {'ordering': "('created',)", 'unique_together': "(('from_user', 'to_user', 'status', 'site'),)", 'object_name': 'Relationship'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'from_user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'from_users'", 'to': "orm['auth.User']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'status': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['relationships.RelationshipStatus']"}),
'to_user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'to_users'", 'to': "orm['auth.User']"})
'extra_data': ('jsonfield.fields.JSONField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'from_user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'from_users'", 'to': u"orm['{}']".format(user_orm_label)}),
'id': ('relationships.models.SIDField', [], {'default': "'R_968e881c1c1ee895'", 'unique': 'True', 'max_length': '20', 'primary_key': 'True', 'db_index': 'True'}),
'site': ('django.db.models.fields.related.ForeignKey', [], {'default': '1', 'related_name': "'relationships'", 'to': u"orm['sites.Site']"}),
'status': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['relationships.RelationshipStatus']"}),
'to_user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'to_users'", 'null': 'True', 'to': u"orm['{}']".format(user_orm_label)}),
'weight': ('django.db.models.fields.FloatField', [], {'default': '1.0', 'null': 'True', 'blank': 'True'})
},
'relationships.relationshipstatus': {
'from_slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
u'relationships.relationshipstatus': {
'Meta': {'ordering': "('name',)", 'object_name': 'RelationshipStatus'},
'from_slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'}),
'id': ('relationships.models.SIDField', [], {'default': "'RS_7d17358149d10a4f'", 'unique': 'True', 'max_length': '20', 'primary_key': 'True', 'db_index': 'True'}),
'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'private': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'symmetrical_slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'to_slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'verb': ('django.db.models.fields.CharField', [], {'max_length': '100'})
'private': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'symmetrical_slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'}),
'to_slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'}),
'verb': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
},
u'sites.site': {
'Meta': {'ordering': "(u'domain',)", 'object_name': 'Site', 'db_table': "u'django_site'"},
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
}
}

complete_apps = ['relationships']
complete_apps = ['relationships']
80 changes: 0 additions & 80 deletions relationships/migrations/0002_add_site_fk.py

This file was deleted.

Loading

0 comments on commit d7c95bd

Please sign in to comment.