ソースを参照

feat: Option to skip failing patches in migrate (#7959)

version-14
Faris Ansari 5年前
committed by GitHub
コミット
d06abbd852
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 4AEE18F83AFDEB23
3個のファイルの変更19行の追加10行の削除
  1. +3
    -2
      frappe/commands/site.py
  2. +2
    -2
      frappe/migrate.py
  3. +14
    -6
      frappe/modules/patch_handler.py

+ 3
- 2
frappe/commands/site.py ファイルの表示

@@ -220,8 +220,9 @@ def disable_user(context, email):

@click.command('migrate')
@click.option('--rebuild-website', help="Rebuild webpages after migration")
@click.option('--skip-failing', is_flag=True, help="Skip patches that fail to run")
@pass_context
def migrate(context, rebuild_website=False):
def migrate(context, rebuild_website=False, skip_failing=False):
"Run patches, sync schema and rebuild files/translations"
from frappe.migrate import migrate

@@ -230,7 +231,7 @@ def migrate(context, rebuild_website=False):
frappe.init(site=site)
frappe.connect()
try:
migrate(context.verbose, rebuild_website=rebuild_website)
migrate(context.verbose, rebuild_website=rebuild_website, skip_failing=skip_failing)
finally:
frappe.destroy()



+ 2
- 2
frappe/migrate.py ファイルの表示

@@ -17,7 +17,7 @@ from frappe.core.doctype.language.language import sync_languages
from frappe.modules.utils import sync_customizations
from frappe.utils import global_search

def migrate(verbose=True, rebuild_website=False):
def migrate(verbose=True, rebuild_website=False, skip_failing=False):
'''Migrate all apps to the latest version, will:
- run before migrate hooks
- run patches
@@ -45,7 +45,7 @@ def migrate(verbose=True, rebuild_website=False):
frappe.get_attr(fn)()

# run patches
frappe.modules.patch_handler.run_all()
frappe.modules.patch_handler.run_all(skip_failing)
# sync
frappe.model.sync.sync_all(verbose=verbose)
frappe.translate.clear_cache()


+ 14
- 6
frappe/modules/patch_handler.py ファイルの表示

@@ -19,23 +19,31 @@ import os

class PatchError(Exception): pass

def run_all():
def run_all(skip_failing=False):
"""run all pending patches"""
executed = [p[0] for p in frappe.db.sql("""select patch from `tabPatch Log`""")]

frappe.flags.final_patches = []
for patch in get_all_patches():
if patch and (patch not in executed):

def run_patch(patch):
try:
if not run_single(patchmodule = patch):
log(patch + ': failed: STOPPED')
raise PatchError(patch)
except Exception:
if not skip_failing:
raise
else:
log('Failed to execute patch')

for patch in get_all_patches():
if patch and (patch not in executed):
run_patch(patch)

# patches to be run in the end
for patch in frappe.flags.final_patches:
patch = patch.replace('finally:', '')
if not run_single(patchmodule = patch):
log(patch + ': failed: STOPPED')
raise PatchError(patch)
run_patch(patch)

def get_all_patches():
patches = []


読み込み中…
キャンセル
保存