Skip to content

Commit

Permalink
Merge pull request #179 from rapidpro/develop
Browse files Browse the repository at this point in the history
Release: Uuid is only unique together with another model field
  • Loading branch information
Rebecca committed Mar 28, 2016
2 parents cde29d4 + c3194d4 commit 10bde96
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = "1.3.3"
release = "1.4.0"
# The short X.Y version.
version = "1.3"
version = "1.4"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
9 changes: 9 additions & 0 deletions docs/source/releases/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ Tracpro's version is incremented upon each merge to master according to our
We recommend reviewing the release notes and code diffs before upgrading
between versions.

v1.4.0 (released 2016-03-28)
----------------------------

Code diff: https://github.com/rapidpro/tracpro/compare/v1.3.3...v1.4.0

* Migrations to move RapidPro uuid unique constraint to unique_together with
another model field (`org` for Contact, Region, and Group models; `pollrun`
for Response)

v1.3.3 (released 2016-03-28)
----------------------------

Expand Down
2 changes: 1 addition & 1 deletion tracpro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


# NOTE: Version must be updated in docs/source/conf.py as well.
VERSION = (1, 3, 3, "final")
VERSION = (1, 4, 0, "final")


def get_version(version):
Expand Down
23 changes: 23 additions & 0 deletions tracpro/contacts/migrations/0011_uuid_is_unique_to_org.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('contacts', '0010_auto_20151111_2239'),
]

operations = [
migrations.AlterField(
model_name='contact',
name='uuid',
field=models.CharField(max_length=36),
),
migrations.AlterUniqueTogether(
name='contact',
unique_together=set([('uuid', 'org')]),
),
]
8 changes: 6 additions & 2 deletions tracpro/contacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def sync(self, org):
class Contact(models.Model):
"""Corresponds to a RapidPro contact."""

uuid = models.CharField(
max_length=36, unique=True)
uuid = models.CharField(max_length=36)
org = models.ForeignKey(
'orgs.Org', verbose_name=_("Organization"), related_name="contacts")
name = models.CharField(
Expand Down Expand Up @@ -116,6 +115,11 @@ class Contact(models.Model):

objects = ContactManager()

class Meta:
unique_together = [
('uuid', 'org'),
]

def __init__(self, *args, **kwargs):
self._data_field_values = kwargs.pop('_data_field_values', None)
super(Contact, self).__init__(*args, **kwargs)
Expand Down
28 changes: 28 additions & 0 deletions tracpro/groups/migrations/0008_uuid_is_unique_to_org.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('groups', '0007_region_boundary'),
]

operations = [
migrations.AlterField(
model_name='group',
name='uuid',
field=models.CharField(max_length=36),
),
migrations.AlterField(
model_name='region',
name='uuid',
field=models.CharField(max_length=36),
),
migrations.AlterUniqueTogether(
name='group',
unique_together=set([('org', 'uuid')]),
),
]
5 changes: 4 additions & 1 deletion tracpro/groups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class AbstractGroup(models.Model):
"""Corresponds to a RapidPro contact group."""

uuid = models.CharField(max_length=36, unique=True)
uuid = models.CharField(max_length=36)
org = models.ForeignKey(
'orgs.Org', verbose_name=_("Organization"), related_name="%(class)ss")
name = models.CharField(
Expand All @@ -33,6 +33,9 @@ class AbstractGroup(models.Model):

class Meta:
abstract = True
unique_together = [
('org', 'uuid'),
]

def __str__(self):
return self.name
Expand Down
23 changes: 23 additions & 0 deletions tracpro/polls/migrations/0032_uuid_is_unique_to_pollrun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('polls', '0031_question_json_rules'),
]

operations = [
migrations.AlterField(
model_name='response',
name='flow_run_id',
field=models.IntegerField(null=True),
),
migrations.AlterUniqueTogether(
name='response',
unique_together=set([('flow_run_id', 'pollrun')]),
),
]
7 changes: 6 additions & 1 deletion tracpro/polls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class Response(models.Model):
(STATUS_COMPLETE, _("Complete")),
)

flow_run_id = models.IntegerField(unique=True, null=True)
flow_run_id = models.IntegerField(null=True)

pollrun = models.ForeignKey('polls.PollRun', null=True, related_name='responses')

Expand All @@ -541,6 +541,11 @@ class Response(models.Model):

objects = ResponseQuerySet.as_manager()

class Meta:
unique_together = [
('flow_run_id', 'pollrun'),
]

@classmethod
def create_empty(cls, org, pollrun, run):
"""
Expand Down

0 comments on commit 10bde96

Please sign in to comment.