mirror of
https://github.com/frappe/bench.git
synced 2024-11-11 15:51:03 +00:00
[fix] bench update --upgrade --force option to force running of pre and post upgrade operations
This commit is contained in:
parent
35e58a7c2e
commit
6e26f74250
15
bench/app.py
15
bench/app.py
@ -98,8 +98,9 @@ def is_version_upgrade(bench='.', branch=None):
|
||||
upstream_version = get_major_version(upstream_version)
|
||||
|
||||
if upstream_version - local_version > 0:
|
||||
return (local_version, upstream_version)
|
||||
return False
|
||||
return (True, local_version, upstream_version)
|
||||
|
||||
return (False, local_version, upstream_version)
|
||||
|
||||
def get_current_frappe_version(bench='.'):
|
||||
try:
|
||||
@ -145,8 +146,8 @@ def switch_branch(branch, apps=None, bench='.', upgrade=False):
|
||||
import utils
|
||||
apps_dir = os.path.join(bench, 'apps')
|
||||
version_upgrade = is_version_upgrade(bench=bench, branch=branch)
|
||||
if version_upgrade and not upgrade:
|
||||
raise MajorVersionUpgradeException("Switching to {0} will cause upgrade from {1} to {2}. Pass --upgrade to confirm".format(branch, version_upgrade[0], version_upgrade[1]), version_upgrade[0], version_upgrade[1])
|
||||
if version_upgrade[0] and not upgrade:
|
||||
raise MajorVersionUpgradeException("Switching to {0} will cause upgrade from {1} to {2}. Pass --upgrade to confirm".format(branch, version_upgrade[1], version_upgrade[2]), version_upgrade[1], version_upgrade[2])
|
||||
|
||||
if not apps:
|
||||
apps = ('frappe', 'erpnext', 'shopping_cart')
|
||||
@ -160,14 +161,14 @@ def switch_branch(branch, apps=None, bench='.', upgrade=False):
|
||||
exec_cmd("git checkout {branch}".format(branch=branch), cwd=app_dir)
|
||||
exec_cmd("git merge upstream/{branch}".format(branch=branch), cwd=app_dir)
|
||||
|
||||
if version_upgrade and upgrade:
|
||||
if version_upgrade[0] and upgrade:
|
||||
update_requirements()
|
||||
pre_upgrade(version_upgrade[0], version_upgrade[1])
|
||||
pre_upgrade(version_upgrade[1], version_upgrade[2])
|
||||
reload(utils)
|
||||
backup_all_sites()
|
||||
patch_sites()
|
||||
build_assets()
|
||||
post_upgrade(version_upgrade[0], version_upgrade[1])
|
||||
post_upgrade(version_upgrade[1], version_upgrade[2])
|
||||
|
||||
def switch_to_master(apps=None, bench='.', upgrade=False):
|
||||
switch_branch('master', apps=apps, bench=bench, upgrade=upgrade)
|
||||
|
63
bench/cli.py
63
bench/cli.py
@ -155,9 +155,9 @@ def bench(bench='.'):
|
||||
@click.option('--apps_path', default=None, help="path to json files with apps to install after init")
|
||||
@click.option('--frappe-path', default=None, help="path to frappe repo")
|
||||
@click.option('--frappe-branch', default=None, help="path to frappe repo")
|
||||
@click.option('--no-procfile', flag_value=True, type=bool, help="Pull changes in all the apps in bench")
|
||||
@click.option('--no-backups',flag_value=True, type=bool, help="Run migrations for all sites in the bench")
|
||||
@click.option('--no-auto-update',flag_value=True, type=bool, help="Build JS and CSS artifacts for the bench")
|
||||
@click.option('--no-procfile', is_flag=True, help="Pull changes in all the apps in bench")
|
||||
@click.option('--no-backups',is_flag=True, help="Run migrations for all sites in the bench")
|
||||
@click.option('--no-auto-update',is_flag=True, help="Build JS and CSS artifacts for the bench")
|
||||
def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups,
|
||||
no_auto_update):
|
||||
"Create a new bench"
|
||||
@ -189,16 +189,17 @@ def new_site(site, mariadb_root_password=None, admin_password=None):
|
||||
|
||||
#TODO: Not DRY
|
||||
@click.command('update')
|
||||
@click.option('--pull', flag_value=True, type=bool, help="Pull changes in all the apps in bench")
|
||||
@click.option('--patch',flag_value=True, type=bool, help="Run migrations for all sites in the bench")
|
||||
@click.option('--build',flag_value=True, type=bool, help="Build JS and CSS artifacts for the bench")
|
||||
@click.option('--bench',flag_value=True, type=bool, help="Update bench")
|
||||
@click.option('--requirements',flag_value=True, type=bool, help="Update requirements")
|
||||
@click.option('--restart-supervisor',flag_value=True, type=bool, help="restart supervisor processes after update")
|
||||
@click.option('--auto',flag_value=True, type=bool)
|
||||
@click.option('--upgrade',flag_value=True, type=bool)
|
||||
@click.option('--no-backup',flag_value=True, type=bool)
|
||||
def _update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False):
|
||||
@click.option('--pull', is_flag=True, help="Pull changes in all the apps in bench")
|
||||
@click.option('--patch',is_flag=True, help="Run migrations for all sites in the bench")
|
||||
@click.option('--build',is_flag=True, help="Build JS and CSS artifacts for the bench")
|
||||
@click.option('--bench',is_flag=True, help="Update bench")
|
||||
@click.option('--requirements',is_flag=True, help="Update requirements")
|
||||
@click.option('--restart-supervisor',is_flag=True, help="restart supervisor processes after update")
|
||||
@click.option('--auto',is_flag=True)
|
||||
@click.option('--upgrade',is_flag=True)
|
||||
@click.option('--no-backup',is_flag=True)
|
||||
@click.option('--force',is_flag=True)
|
||||
def _update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False, force=False):
|
||||
"Update bench"
|
||||
|
||||
if not (pull or patch or build or bench or requirements):
|
||||
@ -208,14 +209,14 @@ def _update(pull=False, patch=False, build=False, bench=False, auto=False, resta
|
||||
|
||||
version_upgrade = is_version_upgrade()
|
||||
|
||||
if version_upgrade and not upgrade:
|
||||
if version_upgrade[0] and not upgrade:
|
||||
print
|
||||
print
|
||||
print "This update will cause a major version change in Frappe/ERPNext from {0} to {1}.".format(*version_upgrade)
|
||||
print "This update will cause a major version change in Frappe/ERPNext from {0} to {1}.".format(*version_upgrade[1:])
|
||||
print "This would take significant time to migrate and might break custom apps. Please run `bench update --upgrade` to confirm."
|
||||
print
|
||||
# print "You can also pin your bench to {0} by running `bench swtich-to-v{0}`".format(version_upgrade[0])
|
||||
print "You can stay on the latest stable release by running `bench switch-to-master` or pin your bench to {0} by running `bench swtich-to-v{0}`".format(version_upgrade[0])
|
||||
print "You can stay on the latest stable release by running `bench switch-to-master` or pin your bench to {0} by running `bench swtich-to-v{0}`".format(version_upgrade[1])
|
||||
sys.exit(1)
|
||||
|
||||
if conf.get('release_bench'):
|
||||
@ -237,20 +238,20 @@ def _update(pull=False, patch=False, build=False, bench=False, auto=False, resta
|
||||
'upgrade': upgrade
|
||||
})
|
||||
|
||||
update(pull, patch, build, bench, auto, restart_supervisor, requirements, no_backup, upgrade)
|
||||
update(pull, patch, build, bench, auto, restart_supervisor, requirements, no_backup, upgrade, force=force)
|
||||
|
||||
print "_"*80
|
||||
print "https://frappe.io/buy - Donate to help make better free and open source tools"
|
||||
print
|
||||
|
||||
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False, bench_path='.'):
|
||||
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False, bench_path='.', force=False):
|
||||
conf = get_config(bench=bench_path)
|
||||
version_upgrade = is_version_upgrade(bench=bench_path)
|
||||
if version_upgrade and not upgrade:
|
||||
if version_upgrade[0] and not upgrade:
|
||||
raise Exception("Major Version Upgrade")
|
||||
|
||||
if upgrade:
|
||||
validate_upgrade(version_upgrade[0], version_upgrade[1], bench=bench_path)
|
||||
if upgrade and (version_upgrade[0] or (not version_upgrade[0] and force)):
|
||||
validate_upgrade(version_upgrade[1], version_upgrade[2], bench=bench_path)
|
||||
|
||||
if pull:
|
||||
pull_all_apps(bench=bench_path)
|
||||
@ -258,8 +259,8 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
|
||||
if requirements:
|
||||
update_requirements(bench=bench_path)
|
||||
|
||||
if upgrade:
|
||||
pre_upgrade(version_upgrade[0], version_upgrade[1], bench=bench_path)
|
||||
if upgrade and (version_upgrade[0] or (not version_upgrade[0] and force)):
|
||||
pre_upgrade(version_upgrade[1], version_upgrade[2], bench=bench_path)
|
||||
import utils, app
|
||||
reload(utils)
|
||||
reload(app)
|
||||
@ -270,8 +271,8 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
|
||||
patch_sites(bench=bench_path)
|
||||
if build:
|
||||
build_assets(bench=bench_path)
|
||||
if upgrade:
|
||||
post_upgrade(version_upgrade[0], version_upgrade[1], bench=bench_path)
|
||||
if upgrade and (version_upgrade[0] or (not version_upgrade[0] and force)):
|
||||
post_upgrade(version_upgrade[1], version_upgrade[2], bench=bench_path)
|
||||
if restart_supervisor or conf.get('restart_supervisor_on_update'):
|
||||
restart_supervisor_processes(bench=bench_path)
|
||||
|
||||
@ -297,7 +298,7 @@ def restart():
|
||||
restart_supervisor_processes()
|
||||
|
||||
@click.command('start')
|
||||
@click.option('--no-dev', flag_value=True, type=bool)
|
||||
@click.option('--no-dev', is_flag=True)
|
||||
def start(no_dev=False):
|
||||
"Start Frappe development processes"
|
||||
_start(no_dev=no_dev)
|
||||
@ -312,7 +313,7 @@ def migrate_3to4(path):
|
||||
site=path))
|
||||
|
||||
@click.command('switch-to-master')
|
||||
@click.option('--upgrade',flag_value=True, type=bool)
|
||||
@click.option('--upgrade',is_flag=True)
|
||||
def _switch_to_master(upgrade=False):
|
||||
"Switch frappe and erpnext to master branch"
|
||||
switch_to_master(upgrade=upgrade)
|
||||
@ -321,7 +322,7 @@ def _switch_to_master(upgrade=False):
|
||||
print 'Please run `bench update --patch` to be safe from any differences in database schema'
|
||||
|
||||
@click.command('switch-to-develop')
|
||||
@click.option('--upgrade',flag_value=True, type=bool)
|
||||
@click.option('--upgrade',is_flag=True)
|
||||
def _switch_to_develop(upgrade=False):
|
||||
"Switch frappe and erpnext to develop branch"
|
||||
switch_to_develop(upgrade=upgrade)
|
||||
@ -330,7 +331,7 @@ def _switch_to_develop(upgrade=False):
|
||||
print 'Please run `bench update --patch` to be safe from any differences in database schema'
|
||||
|
||||
@click.command('switch-to-v4')
|
||||
@click.option('--upgrade',flag_value=True, type=bool)
|
||||
@click.option('--upgrade',is_flag=True)
|
||||
def _switch_to_v4(upgrade=False):
|
||||
"Switch frappe and erpnext to v4 branch"
|
||||
switch_to_v4(upgrade=upgrade)
|
||||
@ -466,8 +467,8 @@ def setup_env():
|
||||
_setup_env()
|
||||
|
||||
@click.command('procfile')
|
||||
@click.option('--with-watch', flag_value=True, type=bool)
|
||||
@click.option('--with-celery-broker', flag_value=True, type=bool)
|
||||
@click.option('--with-watch', is_flag=True)
|
||||
@click.option('--with-celery-broker', is_flag=True)
|
||||
def setup_procfile(with_celery_broker, with_watch):
|
||||
"Setup Procfile for bench start"
|
||||
_setup_procfile(with_celery_broker, with_watch)
|
||||
|
@ -524,7 +524,6 @@ def post_upgrade(from_ver, to_ver, bench='.'):
|
||||
generate_redis_cache_config(bench=bench)
|
||||
generate_supervisor_config(bench=bench)
|
||||
generate_nginx_config(bench=bench)
|
||||
setup_procfile(bench=bench)
|
||||
setup_backups(bench=bench)
|
||||
|
||||
if from_ver <= 5 and to_ver == 6:
|
||||
@ -537,6 +536,10 @@ def post_upgrade(from_ver, to_ver, bench='.'):
|
||||
print "sudo service nginx restart"
|
||||
print "sudo supervisorctl reload"
|
||||
|
||||
if (to_ver >= 5):
|
||||
# For dev server. Always set this up incase someone wants to start a dev server.
|
||||
setup_procfile(bench=bench)
|
||||
|
||||
def update_translations_p(args):
|
||||
update_translations(*args)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user