Skip to content

Commit

Permalink
Fix migration failure (#1737)
Browse files Browse the repository at this point in the history
* Fix migration failure

Fix bug where migration fails if no spatial units are associated with project.

* Add sanity test

* Use ProjectFactory

* Fixup

* Flake8 cleanup
  • Loading branch information
alukach authored and amplifi committed Aug 26, 2017
1 parent e32e6ee commit 7b50f51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
operations = [
migrations.RunSQL(
(
'UPDATE organization_project SET area = (SELECT sum(area) from spatial_spatialunit where "spatial_spatialunit".project_id = "organization_project".id)'
'UPDATE organization_project SET area = (SELECT COALESCE(sum(area), 0) from spatial_spatialunit where "spatial_spatialunit".project_id = "organization_project".id)'
),
reverse_sql=migrations.RunSQL.noop
),
Expand Down
5 changes: 4 additions & 1 deletion cadasta/organization/tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def test_migration(self):
call_command('migrate', 'organization', self.migrate_from)

org = Organization.objects.create(name='Test Org')
project = Project.objects.create(name='Test Proj', organization=org)
Project.objects.create(
id=1, name='No Locations Proj', organization=org)
project = Project.objects.create(
id=2, name='Test Proj', organization=org)

su1 = SpatialUnit.objects.create(
id='abc',
Expand Down

0 comments on commit 7b50f51

Please sign in to comment.