diff --git a/frappe/commands/site.py b/frappe/commands/site.py index c327d85af0..812d63b2f6 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -136,8 +136,9 @@ def restore(context, sql_file_path, mariadb_root_username=None, mariadb_root_pas frappe.init(site=site) # dont allow downgrading to older versions of frappe without force - if not force and is_downgrade(decompressed_file_name): - click.confirm("Downgrading sites may lead to a broken site. Do you wish to continue?", abort=True) + if not force and is_downgrade(decompressed_file_name, verbose=True): + warn_message = "This is not recommended and may lead to unexpected behaviour. Do you want to continue anyway?" + click.confirm(warn_message, abort=True) _new_site(frappe.conf.db_name, site, mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password, admin_password=admin_password, diff --git a/frappe/installer.py b/frappe/installer.py index 962a9e40e5..fa6e25375e 100755 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -327,7 +327,7 @@ def extract_tar_files(site_name, file_path, folder_name): return tar_path -def is_downgrade(sql_file_path): +def is_downgrade(sql_file_path, verbose=False): """checks if input db backup will get downgraded on current bench""" from semantic_version import Version head = "INSERT INTO `tabInstalled Application` VALUES" @@ -335,9 +335,9 @@ def is_downgrade(sql_file_path): with open(sql_file_path) as f: for line in f: if head in line: - # ('2056588823','2020-05-11 18:21:31.488367','2020-06-12 11:49:31.079506','Administrator','Administrator',0,'Installed Applications','installed_applications','Installed Applications',1,'frappe','v10.1.71-74 (3c50d5e) (v10.x.x)','v10.x.x'),('855c640b8e','2020-05-11 18:21:31.488367','2020-06-12 11:49:31.079506','Administrator','Administrator',0,'Installed Applications','installed_applications','Installed Applications',2,'press','0.0.1','master') + # 'line' (str) format: ('2056588823','2020-05-11 18:21:31.488367','2020-06-12 11:49:31.079506','Administrator','Administrator',0,'Installed Applications','installed_applications','Installed Applications',1,'frappe','v10.1.71-74 (3c50d5e) (v10.x.x)','v10.x.x'),('855c640b8e','2020-05-11 18:21:31.488367','2020-06-12 11:49:31.079506','Administrator','Administrator',0,'Installed Applications','installed_applications','Installed Applications',2,'your_custom_app','0.0.1','master') line = line.strip().lstrip(head).rstrip(";").strip() - # [('frappe', '12.x.x-develop ()', 'develop'), ('press', '0.0.1', 'master')] + # 'all_apps' (list) format: [('frappe', '12.x.x-develop ()', 'develop'), ('your_custom_app', '0.0.1', 'master')] all_apps = [ x[-3:] for x in frappe.safe_eval(line) ] for app in all_apps: @@ -351,4 +351,9 @@ def is_downgrade(sql_file_path): except ValueError: return False - return backup_version > current_version + downgrade = backup_version > current_version + + if verbose and downgrade: + print("Your site will be downgraded from Frappe {0} to {1}".format(current_version, backup_version)) + + return downgrade