浏览代码

fix: Table view for bench trim-tables

version-14
Gavin D'souza 3 年前
父节点
当前提交
0413349cc8
共有 2 个文件被更改,包括 15 次插入6 次删除
  1. +10
    -5
      frappe/commands/site.py
  2. +5
    -1
      frappe/model/meta.py

+ 10
- 5
frappe/commands/site.py 查看文件

@@ -813,7 +813,7 @@ def get_standard_tables():

@click.command('trim-tables')
@click.option('--dry-run', is_flag=True, default=False, help='Show what would be deleted')
@click.option('--format', default='table', type=click.Choice(['json', 'table']), help='Output format')
@click.option('--format', '-f', default='table', type=click.Choice(['json', 'table']), help='Output format')
@click.option('--no-backup', is_flag=True, default=False, help='Do not backup the site')
@pass_context
def trim_tables(context, dry_run, format, no_backup):
@@ -833,7 +833,11 @@ def trim_tables(context, dry_run, format, no_backup):
odb.print_summary()

try:
trimmed_data = trim_tables(dry_run=dry_run)
trimmed_data = trim_tables(dry_run=dry_run, quiet=format == 'json')

if format == 'table' and not dry_run:
click.secho(f"The following data have been removed from {frappe.local.site}", fg='green')

handle_data(trimmed_data, format=format)
finally:
frappe.destroy()
@@ -843,9 +847,10 @@ def handle_data(data: dict, format='json'):
import json
print(json.dumps({frappe.local.site: data}, indent=1, sort_keys=True))
else:
click.secho(f"Site {frappe.local.site}", fg='green')
for table, columns in data.items():
print(f"{table}: {', '.join(columns)}")
from frappe.utils.commands import render_table
data = [["DocType", "Fields"]] + [[table, ", ".join(columns)] for table, columns in data.items()]
render_table(data)


commands = [
add_system_manager,


+ 5
- 1
frappe/model/meta.py 查看文件

@@ -659,7 +659,7 @@ def get_default_df(fieldname):
fieldtype = "Data"
)

def trim_tables(doctype=None, dry_run=False):
def trim_tables(doctype=None, dry_run=False, quiet=False):
"""
Removes database fields that don't exist in the doctype (json or custom field). This may be needed
as maintenance since removing a field in a DocType doesn't automatically
@@ -676,9 +676,13 @@ def trim_tables(doctype=None, dry_run=False):
if dropped_columns:
UPDATED_TABLES[doctype] = dropped_columns
except frappe.db.TableMissingError:
if quiet:
continue
click.secho(f"Ignoring missing table for DocType: {doctype}", fg="yellow", err=True)
click.secho(f"Consider removing record in the DocType table for {doctype}", fg="yellow", err=True)
except Exception as e:
if quiet:
continue
click.echo(e, err=True)

return UPDATED_TABLES


正在加载...
取消
保存