fix: handle older gzipped backups as well
Also fix the actual comparison Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
a06e402f38
commit
998f2c10d6
1 changed files with 9 additions and 3 deletions
|
|
@ -53,7 +53,7 @@ def _new_site(
|
|||
):
|
||||
"""Install a new Frappe site"""
|
||||
|
||||
from frappe.utils import get_site_path, scheduler
|
||||
from frappe.utils import scheduler
|
||||
|
||||
if not force and os.path.exists(site):
|
||||
print(f"Site {site} already exists")
|
||||
|
|
@ -756,11 +756,17 @@ def is_downgrade(sql_file_path, verbose=False):
|
|||
|
||||
backup_version = extract_version_from_dump(sql_file_path)
|
||||
if backup_version is None:
|
||||
if sql_file_path.endswith(".sql.gz"):
|
||||
open_method = gzip.open
|
||||
else:
|
||||
open_method = open
|
||||
# Handle older backups in the same way
|
||||
head = "INSERT INTO `tabInstalled Application` VALUES"
|
||||
|
||||
with open(sql_file_path) as f:
|
||||
with open_method(sql_file_path) as f:
|
||||
for line in f:
|
||||
if isinstance(line, bytes):
|
||||
line = line.decode("utf-8").strip()
|
||||
if head in line:
|
||||
# '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()
|
||||
|
|
@ -790,7 +796,7 @@ def is_downgrade(sql_file_path, verbose=False):
|
|||
return False
|
||||
|
||||
current_version = Version(frappe.__version__)
|
||||
downgrade = Version(backup_version) > current_version
|
||||
downgrade = Version(backup_version) < current_version
|
||||
|
||||
if verbose and downgrade:
|
||||
print(f"Your site will be downgraded from Frappe {backup_version} to {current_version}")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue