Schema: add running_balance column to vault table

This commit is contained in:
Keith Solomon
2026-08-03 21:47:46 -05:00
parent 908e2c50ab
commit 2e1bd050e1
+9 -1
View File
@@ -34,7 +34,8 @@ function getDatabaseConnection() {
user TEXT NOT NULL,
timestamp INTEGER NOT NULL,
description TEXT NOT NULL,
amount REAL NOT NULL
amount REAL NOT NULL,
running_balance INTEGER
);";
if ($pdo === null) {
@@ -43,6 +44,13 @@ function getDatabaseConnection() {
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec($createTableSQL);
// Add the running_balance column for databases created before the
// column was added. Idempotent: skip if it already exists.
$columns = $pdo->query("PRAGMA table_info(vault)")->fetchAll(PDO::FETCH_COLUMN, 1);
if (!in_array('running_balance', $columns, true)) {
$pdo->exec('ALTER TABLE vault ADD COLUMN running_balance INTEGER');
}
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}