From d6f7f76c4d8c35ebafb994f6f4ee01b932ae2bf0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Jan 2024 11:37:01 -0800 Subject: [PATCH] Removes outdated/unused version and updating code I had the bright idea of creating this update script but it doesn't work and hasn't been maintained, so it's just sitting there causing confusing and requiring weird things to exist in other places. Now, the unused `version` field can be removed and I can scrap the management command for getting versions. --- .../management/commands/instance_version.py | 54 ------------------- ..._version_sitesettings_available_version.py | 18 +++++++ bookwyrm/models/site.py | 2 +- bookwyrm/views/admin/dashboard.py | 18 ++----- update.sh | 37 ------------- 5 files changed, 24 insertions(+), 105 deletions(-) delete mode 100644 bookwyrm/management/commands/instance_version.py create mode 100644 bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py delete mode 100755 update.sh diff --git a/bookwyrm/management/commands/instance_version.py b/bookwyrm/management/commands/instance_version.py deleted file mode 100644 index ca150d640..000000000 --- a/bookwyrm/management/commands/instance_version.py +++ /dev/null @@ -1,54 +0,0 @@ -""" Get your admin code to allow install """ -from django.core.management.base import BaseCommand - -from bookwyrm import models -from bookwyrm.settings import VERSION - - -# pylint: disable=no-self-use -class Command(BaseCommand): - """command-line options""" - - help = "What version is this?" - - def add_arguments(self, parser): - """specify which function to run""" - parser.add_argument( - "--current", - action="store_true", - help="Version stored in database", - ) - parser.add_argument( - "--target", - action="store_true", - help="Version stored in settings", - ) - parser.add_argument( - "--update", - action="store_true", - help="Update database version", - ) - - # pylint: disable=unused-argument - def handle(self, *args, **options): - """execute init""" - site = models.SiteSettings.objects.get() - current = site.version or "0.0.1" - target = VERSION - if options.get("current"): - print(current) - return - - if options.get("target"): - print(target) - return - - if options.get("update"): - site.version = target - site.save() - return - - if current != target: - print(f"{current}/{target}") - else: - print(current) diff --git a/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py b/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py new file mode 100644 index 000000000..219ae32f6 --- /dev/null +++ b/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.23 on 2024-01-02 19:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0191_merge_20240102_0326'), + ] + + operations = [ + migrations.RenameField( + model_name='sitesettings', + old_name='version', + new_name='available_version', + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index bd53f1f07..7ca7e0015 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -45,7 +45,7 @@ class SiteSettings(SiteModel): default_theme = models.ForeignKey( "Theme", null=True, blank=True, on_delete=models.SET_NULL ) - version = models.CharField(null=True, blank=True, max_length=10) + available_version = models.CharField(null=True, blank=True, max_length=10) # admin setup options install_mode = models.BooleanField(default=False) diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index 9d256fc6c..c5648ff11 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -15,7 +15,6 @@ from django.views import View from csp.decorators import csp_update from bookwyrm import models, settings -from bookwyrm.connectors.abstract_connector import get_data from bookwyrm.utils import regex @@ -59,18 +58,11 @@ class Dashboard(View): == site._meta.get_field("privacy_policy").get_default() ) - # check version - - try: - release = get_data(settings.RELEASE_API, timeout=3) - available_version = release.get("tag_name", None) - if available_version and version.parse(available_version) > version.parse( - settings.VERSION - ): - data["current_version"] = settings.VERSION - data["available_version"] = available_version - except: # pylint: disable= bare-except - pass + if site.available_version and version.parse(site.available_version) > version.parse( + settings.VERSION + ): + data["current_version"] = settings.VERSION + data["available_version"] = site.available_version return TemplateResponse(request, "settings/dashboard/dashboard.html", data) diff --git a/update.sh b/update.sh deleted file mode 100755 index 727ce1b24..000000000 --- a/update.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -set -e - -# determine inital and target versions -initial_version="`./bw-dev runweb python manage.py instance_version --current`" -target_version="`./bw-dev runweb python manage.py instance_version --target`" - -initial_version="`echo $initial_version | tail -n 1 | xargs`" -target_version="`echo $target_version | tail -n 1 | xargs`" -if [[ "$initial_version" = "$target_version" ]]; then - echo "Already up to date; version $initial_version" - exit -fi - -echo "---------------------------------------" -echo "Updating from version: $initial_version" -echo ".......... to version: $target_version" -echo "---------------------------------------" - -function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } - -# execute scripts between initial and target -for version in `ls -A updates/ | sort -V `; do - if version_gt $initial_version $version; then - # too early - continue - fi - if version_gt $version $target_version; then - # too late - continue - fi - echo "Running tasks for version $version" - ./updates/$version -done - -./bw-dev runweb python manage.py instance_version --update -echo "✨ ----------- Done! --------------- ✨"