From 9aeeb8a03694fcc70e697c04f112794b26a9a94c Mon Sep 17 00:00:00 2001
From: Petr Stribny <petr@stribny.name>
Date: Wed, 29 Nov 2023 10:47:16 +0000
Subject: [PATCH] Add model.info() for debugging

---
 backend/requirements/base.in                  |  1 +
 backend/requirements/base.txt                 |  8 ++++
 .../baserow/contrib/database/table/models.py  | 43 +++++++++++++++++++
 3 files changed, 52 insertions(+)

diff --git a/backend/requirements/base.in b/backend/requirements/base.in
index 3e19123af..94817cb95 100644
--- a/backend/requirements/base.in
+++ b/backend/requirements/base.in
@@ -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
\ No newline at end of file
diff --git a/backend/requirements/base.txt b/backend/requirements/base.txt
index 8e6f39602..e8c488f50 100644
--- a/backend/requirements/base.txt
+++ b/backend/requirements/base.txt
@@ -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
diff --git a/backend/src/baserow/contrib/database/table/models.py b/backend/src/baserow/contrib/database/table/models.py
index daa9e68c6..ea3513ca6 100644
--- a/backend/src/baserow/contrib/database/table/models.py
+++ b/backend/src/baserow/contrib/database/table/models.py
@@ -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