]> Nutra Git (v2) - nutratech/nt-sqlite.git/commitdiff
ADD COL weight,height. PRAGMA user_version = 9;
authorShane Jaroch <chown_tee@proton.me>
Wed, 21 Jan 2026 22:25:27 +0000 (17:25 -0500)
committerShane Jaroch <chown_tee@proton.me>
Thu, 22 Jan 2026 03:42:32 +0000 (22:42 -0500)
sql/__init__.py
sql/data/version.csv [deleted file]
sql/tables.sql

index eca7adb429d2a11ec544a5a6404dc0b380369b5b..65679c002a119970aafd90a02371cd7c88ce923b 100755 (executable)
@@ -55,11 +55,52 @@ def build_ntsqlite(verbose: bool = False) -> bool:
 
     cur.close()
     con.commit()
+
+    if verbose:
+        print_stats(con)
+
     con.close()
     if verbose:
         print("\nDone!")
     return True
 
 
+def print_stats(con: sqlite3.Connection) -> None:
+    """Prints database statistics"""
+    cur = con.cursor()
+    print("-" * 40)
+    print(f"Database: {NT_DB_NAME}")
+
+    if os.path.exists(NT_DB_NAME):
+        size_bytes = os.path.getsize(NT_DB_NAME)
+        print(f"Size:     {size_bytes / 1024:.2f} KB")
+
+    cur.execute("PRAGMA user_version")
+    version = cur.fetchone()[0]
+    print(f"Version:  {version}")
+    print("-" * 40)
+    print("Table Statistics:")
+    print("-" * 40)
+    print(f"{'Table':<20} | {'Rows':>10}")
+    print("-" * 40)
+
+    cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")
+    tables = cur.fetchall()
+
+    total_rows = 0
+    for (table,) in tables:
+        if table == "sqlite_sequence":
+            continue
+        cur.execute(f"SELECT COUNT(*) FROM {table}")
+        count = cur.fetchone()[0]
+        total_rows += count
+        print(f"{table:<20} | {count:>10,}")
+
+    print("-" * 40)
+    print(f"{'TOTAL':<20} | {total_rows:>10,}")
+    print("-" * 40)
+    cur.close()
+
+
 if __name__ == "__main__":
     build_ntsqlite(verbose=True)  # pragma: no cover
diff --git a/sql/data/version.csv b/sql/data/version.csv
deleted file mode 100644 (file)
index eb5797b..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-id,version,created,notes
-1,0.0.0,2020-09-22,initial release
-2,0.0.1,2021-05-21,bump version
-3,0.0.2,2021-05-24,remove guids
-4,0.0.3,2021-05-24,general cleanup
-5,0.0.4,2021-06-17,"add custom foods tables (custom_foods, cf_dat)"
-6,0.0.5,2022-07-11,remove biometrics
-7,0.0.6,2022-07-14,"rename tables, start to organize for plugins"
-8,0.0.7,2024-02-25,"add bug table"
index fd60abdd52146557f709c311fa3276861daaa02e..38091f2aa04d1291fe50583220f12ccbb75931e4 100644 (file)
 -- You should have received a copy of the GNU General Public License
 -- along with this program.  If not, see <https://www.gnu.org/licenses/>.
 --
-CREATE TABLE `version` (
-  id integer PRIMARY KEY AUTOINCREMENT,
-  `version` text NOT NULL UNIQUE,
-  created date NOT NULL,
-  notes text
-);
+PRAGMA user_version = 9;
 
 -- NOTE: INSERT INTO statements for version, bmr_eq, bf_eq? Don't maintain as CSV?
 -- TODO: enforce FK constraint across two DBs?
@@ -50,6 +45,8 @@ CREATE TABLE profile (
   gender text,
   dob date,
   act_lvl int DEFAULT 2, -- [1, 2, 3, 4, 5]
+  height real, -- cm
+  weight real, -- kg
   goal_wt real,
   goal_bf real DEFAULT 18,
   bmr_eq_id int DEFAULT 1,