chore: add back describe-database-table command
Partial revert of b169f8780a
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
fdd39b6a18
commit
b7fcafcaf1
1 changed files with 39 additions and 1 deletions
|
|
@ -590,6 +590,44 @@ def add_db_index(context: CliCtxObj, doctype, column):
|
|||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command("describe-database-table")
|
||||
@click.option("--doctype", help="DocType to describe")
|
||||
@click.option(
|
||||
"--column",
|
||||
multiple=True,
|
||||
help="Explicitly fetch accurate cardinality from table data. This can be quite slow on large tables.",
|
||||
)
|
||||
@pass_context
|
||||
def describe_database_table(context, doctype, column):
|
||||
"""Describes various statistics about the table.
|
||||
This is useful to build integration like
|
||||
This includes:
|
||||
1. Schema
|
||||
2. Indexes
|
||||
3. stats - total count of records
|
||||
4. if column is specified then extra stats are generated for column:
|
||||
Distinct values count in column
|
||||
"""
|
||||
if doctype is None:
|
||||
raise click.UsageError("--doctype <doctype> is required")
|
||||
import json
|
||||
|
||||
from frappe.core.doctype.recorder.recorder import _fetch_table_stats
|
||||
|
||||
for site in context.sites:
|
||||
frappe.init(site=site)
|
||||
frappe.connect()
|
||||
try:
|
||||
data = _fetch_table_stats(doctype, column)
|
||||
# NOTE: Do not print anything else in this to avoid clobbering the output.
|
||||
print(json.dumps(data, indent=2))
|
||||
finally:
|
||||
frappe.destroy()
|
||||
|
||||
if not context.sites:
|
||||
raise SiteNotSpecifiedError
|
||||
|
||||
|
||||
@click.command("add-system-manager")
|
||||
@click.argument("email")
|
||||
@click.option("--first-name")
|
||||
|
|
@ -660,7 +698,6 @@ def disable_user(context: CliCtxObj, email):
|
|||
@pass_context
|
||||
def migrate(context: CliCtxObj, skip_failing=False, skip_search_index=False):
|
||||
"Run patches, sync schema and rebuild files/translations"
|
||||
from traceback_with_variables import activate_by_import
|
||||
|
||||
from frappe.migrate import SiteMigration
|
||||
|
||||
|
|
@ -1541,6 +1578,7 @@ commands = [
|
|||
add_system_manager,
|
||||
add_user_for_sites,
|
||||
add_db_index,
|
||||
describe_database_table,
|
||||
backup,
|
||||
drop_site,
|
||||
install_app,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue