From: Shane Jaroch Date: Wed, 21 Jan 2026 22:25:27 +0000 (-0500) Subject: ADD COL weight,height. PRAGMA user_version = 9; X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=54d75cdfa5844563dddea6c5bc411bf0ee458740;p=nutratech%2Fnt-sqlite.git ADD COL weight,height. PRAGMA user_version = 9; --- diff --git a/sql/__init__.py b/sql/__init__.py index eca7adb..65679c0 100755 --- a/sql/__init__.py +++ b/sql/__init__.py @@ -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 index eb5797b..0000000 --- a/sql/data/version.csv +++ /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" diff --git a/sql/tables.sql b/sql/tables.sql index fd60abd..38091f2 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -14,12 +14,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- -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,