From 6385cb3f86e68915b7750cb6d42ffaee72ecbacf Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 3 Dec 2020 12:24:46 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=86=8D=E8=87=AA=E5=8A=A8=E8=BF=90=E8=A1=8C?= =?UTF-8?q?migrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jms | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/jms b/jms index 4cc7e916d..e92c1c236 100755 --- a/jms +++ b/jms @@ -85,6 +85,17 @@ def check_database_connection(): sys.exit(10) +def check_migrations(): + apps_dir = os.path.join(BASE_DIR, 'apps') + code = subprocess.call("python manage.py showmigrations | grep '\[.\]' | grep -v '\[X\]'", shell=True, cwd=apps_dir) + + if code == 1: + return + for i in range(3): + print("!!! Warning: Has SQL migrations not perform, 有 SQL 变更没有执行") + print("You should run ./PROC upgrade first, 请先运行 ./PROC upgrade, 进行表结构变更") + + def make_migrations(): logging.info("Check database structure change ...") os.chdir(os.path.join(BASE_DIR, 'apps')) @@ -102,8 +113,7 @@ def collect_static(): def prepare(): check_database_connection() - make_migrations() - collect_static() + check_migrations() def check_pid(pid): @@ -512,6 +522,11 @@ def show_service_status(s): print("{} is stopped".format(ns)) +def upgrade(): + collect_static() + make_migrations() + + if __name__ == '__main__': parser = argparse.ArgumentParser( description=""" @@ -524,7 +539,7 @@ if __name__ == '__main__': ) parser.add_argument( 'action', type=str, - choices=("start", "stop", "restart", "status"), + choices=("start", "stop", "restart", "status", "upgrade"), help="Action to run" ) parser.add_argument( @@ -559,5 +574,7 @@ if __name__ == '__main__': stop_service(srv) time.sleep(5) start_services_and_watch(srv) + elif action == "upgrade": + upgrade() else: show_service_status(srv)