From a6f654ebfbcfadde07ddd464038334758c41a231 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.anjos@idiap.ch>
Date: Thu, 30 Jun 2016 17:12:36 +0200
Subject: [PATCH] [databases] Add missing ordering requirements for back-ups

---
 .../migrations/0003_auto_20160630_1710.py     | 19 +++++++++++++++++++
 beat/web/databases/models.py                  |  7 ++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 beat/web/databases/migrations/0003_auto_20160630_1710.py

diff --git a/beat/web/databases/migrations/0003_auto_20160630_1710.py b/beat/web/databases/migrations/0003_auto_20160630_1710.py
new file mode 100644
index 000000000..9ba33dccc
--- /dev/null
+++ b/beat/web/databases/migrations/0003_auto_20160630_1710.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.5 on 2016-06-30 17:10
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('databases', '0002_scheduler_addons'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='database',
+            options={'ordering': ['previous_version_id', 'fork_of_id', 'id']},
+        ),
+    ]
diff --git a/beat/web/databases/models.py b/beat/web/databases/models.py
index 01bb490b1..d7f500102 100755
--- a/beat/web/databases/models.py
+++ b/beat/web/databases/models.py
@@ -189,9 +189,14 @@ class Database(Versionable):
 
     #_____ Meta parameters __________
 
-    class Meta:
+    class Meta(Versionable.Meta):
         unique_together = ('name', 'version')
 
+        # setup ordering so that the dump order respects self dependencies
+        # note: Versionable already has the right ordering - not sure why
+        # `django makemigrations' is not detecting it though.
+        ordering = ['previous_version_id', 'fork_of_id', 'id']
+
 
     #_____ Utilities __________
 
-- 
GitLab