F 修复update升级未正常更新表结构的问题

This commit is contained in:
vapao 2020-06-01 11:33:03 +08:00
parent fbad6d8cbf
commit 77669dd5a5
1 changed files with 12 additions and 7 deletions

View File

@ -2,7 +2,6 @@
# Copyright: (c) <spug.dev@gmail.com> # Copyright: (c) <spug.dev@gmail.com>
# Released under the MIT License. # Released under the MIT License.
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.conf import settings from django.conf import settings
import subprocess import subprocess
import requests import requests
@ -16,7 +15,7 @@ class Command(BaseCommand):
res = requests.get('https://gitee.com/api/v5/repos/openspug/spug/releases/latest').json() res = requests.get('https://gitee.com/api/v5/repos/openspug/spug/releases/latest').json()
version = res.get('tag_name') version = res.get('tag_name')
if not version: if not version:
return self.stderr.write(self.style.ERROR('获取新版本失败,排除网络问题后至官方论坛反馈')) return self.stderr.write(self.style.ERROR('获取新版本失败,排除网络问题后请附带输出内容至官方论坛反馈'))
if version == settings.SPUG_VERSION: if version == settings.SPUG_VERSION:
return self.stdout.write(self.style.SUCCESS('当前已是最新版本')) return self.stdout.write(self.style.SUCCESS('当前已是最新版本'))
answer = input(f'发现新版本 {version} 是否更新[y|n]') answer = input(f'发现新版本 {version} 是否更新[y|n]')
@ -32,7 +31,7 @@ class Command(BaseCommand):
] ]
task = subprocess.Popen(' && '.join(commands), shell=True) task = subprocess.Popen(' && '.join(commands), shell=True)
if task.wait() != 0: if task.wait() != 0:
return self.stderr.write(self.style.ERROR('获取更新失败,排除网络问题后至官方论坛反馈。')) return self.stderr.write(self.style.ERROR('获取更新失败,排除网络问题后请附带输出内容至官方论坛反馈。'))
# update api # update api
commands = [ commands = [
@ -42,7 +41,7 @@ class Command(BaseCommand):
] ]
task = subprocess.Popen(' && '.join(commands), shell=True) task = subprocess.Popen(' && '.join(commands), shell=True)
if task.wait() != 0: if task.wait() != 0:
return self.stderr.write(self.style.ERROR('获取更新失败,排除网络问题后至官方论坛反馈。')) return self.stderr.write(self.style.ERROR('获取更新失败,排除网络问题后请附带输出内容至官方论坛反馈。'))
# update dep # update dep
commands = [ commands = [
@ -51,12 +50,18 @@ class Command(BaseCommand):
] ]
task = subprocess.Popen(' && '.join(commands), shell=True) task = subprocess.Popen(' && '.join(commands), shell=True)
if task.wait() != 0: if task.wait() != 0:
return self.stderr.write(self.style.ERROR('更新依赖包失败,排除网络问题后至官方论坛反馈。')) return self.stderr.write(self.style.ERROR('更新依赖包失败,排除网络问题后请附带输出内容至官方论坛反馈。'))
# update db # update db
apps = [x.split('.')[-1] for x in settings.INSTALLED_APPS if x.startswith('apps.')] apps = [x.split('.')[-1] for x in settings.INSTALLED_APPS if x.startswith('apps.')]
call_command('makemigrations', *apps) commands = [
call_command('migrate') f'cd {settings.BASE_DIR}',
f'./manage.py makemigrations ' + ' '.join(apps),
f'./manage.py migrate'
]
task = subprocess.Popen(' && '.join(commands), shell=True)
if task.wait() != 0:
return self.stderr.write(self.style.ERROR('更新表结构失败,请附带输出内容至官方论坛反馈。'))
self.stdout.write(self.style.SUCCESS('''升级成功,请自行重启服务,如果通过官方文档安装一般重启命令为 self.stdout.write(self.style.SUCCESS('''升级成功,请自行重启服务,如果通过官方文档安装一般重启命令为
Docker: docker restart $CONTAINER_ID Docker: docker restart $CONTAINER_ID