1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-07 06:15:36 +00:00

Add model.info() for debugging

This commit is contained in:
Petr Stribny 2023-11-29 10:47:16 +00:00
parent 7c8de3a46d
commit 9aeeb8a036
3 changed files with 52 additions and 0 deletions
backend
requirements
src/baserow/contrib/database/table

View file

@ -63,3 +63,4 @@ django-cachalot==2.5.3
celery-singleton==0.3.1
posthog==3.0.1
https://github.com/fellowapp/prosemirror-py/archive/refs/tags/v0.3.5.zip
rich==13.7.0

View file

@ -213,6 +213,10 @@ kombu==5.2.4
# via celery
loguru==0.6.0
# via -r base.in
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
monotonic==1.6
# via posthog
msgpack==1.0.4
@ -347,6 +351,8 @@ pyasn1-modules==0.2.8
# service-identity
pycparser==2.21
# via cffi
pygments==2.17.2
# via rich
pyjwt==2.5.0
# via djangorestframework-simplejwt
pyopenssl==23.2.0
@ -405,6 +411,8 @@ requests==2.31.0
# requests-oauthlib
requests-oauthlib==1.3.1
# via -r base.in
rich==13.7.0
# via -r base.in
rsa==4.9
# via google-auth
s3transfer==0.6.0

View file

@ -515,6 +515,49 @@ class GeneratedTableModel(HierarchicalModelMixin, models.Model):
like `isinstance(possible_baserow_model, GeneratedTableModel)`.
"""
@classmethod
def info(cls):
"""
Print basic information about the generated table.
Use only in development.
"""
from rich import box
from rich.console import Console
from rich.table import Table
table = Table(
title=f"{cls.baserow_table.name} ({cls.baserow_table.id})", box=box.ROUNDED
)
table.add_column("Name", justify="right", style="cyan", no_wrap=True)
table.add_column("Column", justify="right", style="cyan", no_wrap=True)
table.add_column("Type", style="magenta")
table.add_column("Order", style="grey84")
table.add_column("Trashed", justify="center", style="green")
table.add_column("TS vector column", style="yellow")
field_objects = cls.get_field_objects(include_trash=True)
for field_obj in field_objects:
primary = "(primary) " if field_obj["field"].primary else ""
name = f"{primary}{field_obj['field'].name}"
ts_vector_created = (
"" if field_obj["field"].tsvector_column_created else ""
)
ts_vector = f"{field_obj['field'].tsv_db_column} {ts_vector_created}"
trashed = "🗑️" if field_obj["field"].trashed else ""
table.add_row(
name,
field_obj["field"].db_column,
field_obj["type"].type,
str(field_obj["field"].order),
trashed,
ts_vector,
)
console = Console()
console.print(table)
def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
"""
We override this method to prevent safe and bulk save queries from setting