perf: 优化启动,不再自动运行migrations

pull/5169/head^2
ibuler 4 years ago committed by Jiangjie.Bai
parent 36e9d8101a
commit 6385cb3f86

23
jms

@ -85,6 +85,17 @@ def check_database_connection():
sys.exit(10) 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(): def make_migrations():
logging.info("Check database structure change ...") logging.info("Check database structure change ...")
os.chdir(os.path.join(BASE_DIR, 'apps')) os.chdir(os.path.join(BASE_DIR, 'apps'))
@ -102,8 +113,7 @@ def collect_static():
def prepare(): def prepare():
check_database_connection() check_database_connection()
make_migrations() check_migrations()
collect_static()
def check_pid(pid): def check_pid(pid):
@ -512,6 +522,11 @@ def show_service_status(s):
print("{} is stopped".format(ns)) print("{} is stopped".format(ns))
def upgrade():
collect_static()
make_migrations()
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=""" description="""
@ -524,7 +539,7 @@ if __name__ == '__main__':
) )
parser.add_argument( parser.add_argument(
'action', type=str, 'action', type=str,
choices=("start", "stop", "restart", "status"), choices=("start", "stop", "restart", "status", "upgrade"),
help="Action to run" help="Action to run"
) )
parser.add_argument( parser.add_argument(
@ -559,5 +574,7 @@ if __name__ == '__main__':
stop_service(srv) stop_service(srv)
time.sleep(5) time.sleep(5)
start_services_and_watch(srv) start_services_and_watch(srv)
elif action == "upgrade":
upgrade()
else: else:
show_service_status(srv) show_service_status(srv)

Loading…
Cancel
Save