upgrade update script

pull/223/head
vapao 2020-11-10 12:38:17 +08:00
parent dd53b5907a
commit 4d8dcf5d66
3 changed files with 44 additions and 8 deletions

View File

@ -60,7 +60,8 @@ class Command(BaseCommand):
commands = [
f'cd {settings.BASE_DIR}',
f'python3 ./manage.py makemigrations ' + ' '.join(apps),
f'python3 ./manage.py migrate'
f'python3 ./manage.py migrate',
f'python3 ./tools/migrate.py {version}'
]
task = subprocess.Popen(' && '.join(commands), shell=True)
if task.wait() != 0:

View File

@ -12,13 +12,6 @@ import subprocess
import json
import os
# v2.3.14 临时数据初始化
ap = App.objects.first()
if ap and hasattr(ap, 'sort_id') and ap.sort_id == 0:
for ap in App.objects.all():
ap.sort_id = ap.id
ap.save()
class AppView(View):
def get(self, request):

42
spug_api/tools/migrate.py Normal file
View File

@ -0,0 +1,42 @@
import django
import sys
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "spug.settings")
django.setup()
from django.conf import settings
from apps.app.models import App
import sys
class Version:
def __init__(self, version):
self.version = version.lstrip('vV').split('.')
def __gt__(self, other):
if not isinstance(other, Version):
raise TypeError('required type Version')
for v1, v2 in zip(self.version, other.version):
if int(v1) == int(v2):
continue
elif int(v1) > int(v2):
return True
else:
return False
return False
if __name__ == '__main__':
old_version = Version(sys.argv[1])
now_version = Version(settings.SPUG_VERSION)
if old_version < Version('v2.3.14'):
app = App.objects.first()
if app and hasattr(app, 'sort_id') and app.sort_id == 0:
print('执行v2.3.14数据初始化')
for app in App.objects.all():
app.sort_id = app.id
app.save()