Remove the relnotes field from the Version model
authorMagnus Hagander <magnus@hagander.net>
Tue, 18 May 2021 08:27:00 +0000 (10:27 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 18 May 2021 08:27:00 +0000 (10:27 +0200)
This field can be trivially calculated from the version number, the
pattern has only changed a couple of times in the past. So turn it into
a calculated field instead, which makes things like pushing a new
release easier since it leaves one less mistake to make.

pgweb/core/fixtures/data.json
pgweb/core/migrations/0005_remove_version_relnotes.py [new file with mode: 0644]
pgweb/core/models.py

index 0e3089e31f958bfc3984a7a57f8a3b569522477f..24a5a26296f658c4098766b143c053b9db430606 100644 (file)
@@ -6,7 +6,6 @@
   "tree": "8.4",
   "latestminor": 22,
   "reldate": "2014-07-24",
-  "relnotes": "release-8-4-22.html",
   "current": false,
   "supported": false,
   "testing": 0,
@@ -22,7 +21,6 @@
   "tree": "8.3",
   "latestminor": 23,
   "reldate": "2013-02-07",
-  "relnotes": "release-8-3-23.html",
   "current": false,
   "supported": false,
   "testing": 0,
@@ -38,7 +36,6 @@
   "tree": "8.2",
   "latestminor": 23,
   "reldate": "2011-12-05",
-  "relnotes": "release-8-2-23.html",
   "current": false,
   "supported": false,
   "testing": 0,
@@ -54,7 +51,6 @@
   "tree": "8.1",
   "latestminor": 23,
   "reldate": "2010-12-16",
-  "relnotes": "release.html#RELEASE-8-1-23",
   "current": false,
   "supported": false,
   "testing": 0,
@@ -70,7 +66,6 @@
   "tree": "8.0",
   "latestminor": 26,
   "reldate": "2010-10-04",
-  "relnotes": "release.html#RELEASE-8-0-26",
   "current": false,
   "supported": false,
   "testing": 0,
@@ -86,7 +81,6 @@
   "tree": "9.0",
   "latestminor": 23,
   "reldate": "2015-10-08",
-  "relnotes": "release-9-0-23.html",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "7.4",
   "latestminor": 30,
   "reldate": "2010-10-04",
-  "relnotes": "release.html#RELEASE-7-4-30",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "7.3",
   "latestminor": 21,
   "reldate": "2008-01-07",
-  "relnotes": "release.html#RELEASE-7-3-21",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "7.2",
   "latestminor": 8,
   "reldate": "2005-05-09",
-  "relnotes": "release.html#RELEASE-7-2-8",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "7.1",
   "latestminor": 3,
   "reldate": "2001-08-17",
-  "relnotes": "release.html",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "7.0",
   "latestminor": 3,
   "reldate": "2000-11-12",
-  "relnotes": "release.htm#AEN18262",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "6.5",
   "latestminor": 3,
   "reldate": "1999-11-04",
-  "relnotes": "release.htm",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "6.4",
   "latestminor": 2,
   "reldate": "1999-01-03",
-  "relnotes": "release.htm",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "9.1",
   "latestminor": 24,
   "reldate": "2016-10-27",
-  "relnotes": "release-9-1-24.html",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "0.0",
   "latestminor": 0,
   "reldate": "2011-11-22",
-  "relnotes": "x",
   "current": false,
   "supported": false,
   "testing": 2,
   "tree": "6.3",
   "latestminor": 2,
   "reldate": "1998-02-23",
-  "relnotes": "c2701.htm",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "9.2",
   "latestminor": 24,
   "reldate": "2017-11-09",
-  "relnotes": "release-9-2-24.html",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "9.3",
   "latestminor": 25,
   "reldate": "2018-11-08",
-  "relnotes": "release-9-3-25.html",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "9.4",
   "latestminor": 26,
   "reldate": "2020-02-13",
-  "relnotes": "release-9-4-26.html",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "9.5",
   "latestminor": 25,
   "reldate": "2021-02-11",
-  "relnotes": "release-9-5-25.html",
   "current": false,
   "supported": false,
   "testing": 0,
   "tree": "9.6",
   "latestminor": 21,
   "reldate": "2021-02-11",
-  "relnotes": "release-9-6-21.html",
   "current": false,
   "supported": true,
   "testing": 0,
   "tree": "10.0",
   "latestminor": 16,
   "reldate": "2021-02-11",
-  "relnotes": "release-10-16.html",
   "current": false,
   "supported": true,
   "testing": 0,
   "tree": "11.0",
   "latestminor": 11,
   "reldate": "2021-02-11",
-  "relnotes": "release-11-11.html",
   "current": false,
   "supported": true,
   "testing": 0,
   "tree": "12.0",
   "latestminor": 6,
   "reldate": "2021-02-11",
-  "relnotes": "release-12-6.html",
   "current": false,
   "supported": true,
   "testing": 0,
   "tree": "13.0",
   "latestminor": 2,
   "reldate": "2021-02-11",
-  "relnotes": "release-13-2.html",
   "current": true,
   "supported": true,
   "testing": 0,
diff --git a/pgweb/core/migrations/0005_remove_version_relnotes.py b/pgweb/core/migrations/0005_remove_version_relnotes.py
new file mode 100644 (file)
index 0000000..dc9cb48
--- /dev/null
@@ -0,0 +1,17 @@
+# Generated by Django 2.2.11 on 2021-05-18 08:23
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0004_org_emails'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='version',
+            name='relnotes',
+        ),
+    ]
index f912c68b48b2fdd883102649ca11bc8bd539c233..47e412e2e2f1969b2a393eba6da4cd04661746da 100644 (file)
@@ -4,6 +4,7 @@ from django.contrib.auth.models import User
 from pgweb.util.misc import varnish_purge
 
 import base64
+from decimal import Decimal
 
 from pgweb.util.moderation import TwostateModerateModel
 
@@ -20,7 +21,6 @@ class Version(models.Model):
     tree = models.DecimalField(max_digits=3, decimal_places=1, null=False, blank=False, unique=True)
     latestminor = models.IntegerField(null=False, blank=False, default=0, help_text="For testing versions, latestminor means latest beta/rc number. For other releases, it's the latest minor release number in the tree.")
     reldate = models.DateField(null=False, blank=False)
-    relnotes = models.CharField(max_length=32, null=False, blank=False)
     current = models.BooleanField(null=False, blank=False, default=False)
     supported = models.BooleanField(null=False, blank=False, default=True)
     testing = models.IntegerField(null=False, blank=False, default=0, help_text="Testing level of this release. latestminor indicates beta/rc number", choices=TESTING_CHOICES)
@@ -44,6 +44,20 @@ class Version(models.Model):
         else:
             return self.tree
 
+    @property
+    def relnotes(self):
+        if self.tree >= Decimal('8.2'):
+            return 'release-{}-{}.html'.format(str(self.numtree).replace('.', '-'), self.latestminor)
+        elif self.tree >= Decimal('7.1'):
+            return 'release.html'
+        elif self.tree >= Decimal('6.4'):
+            return 'release.htm'
+        elif self.tree >= Decimal('6.3'):
+            return 'c2701.htm'
+        else:
+            # Should never happen so return something broken
+            return 'x'
+
     def buildversionstring(self, minor):
         if not self.testing:
             return "%s.%s" % (self.numtree, minor)