Schema: add running_balance column to vault table
This commit is contained in:
+9
-1
@@ -34,7 +34,8 @@ function getDatabaseConnection() {
|
|||||||
user TEXT NOT NULL,
|
user TEXT NOT NULL,
|
||||||
timestamp INTEGER NOT NULL,
|
timestamp INTEGER NOT NULL,
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
amount REAL NOT NULL
|
amount REAL NOT NULL,
|
||||||
|
running_balance INTEGER
|
||||||
);";
|
);";
|
||||||
|
|
||||||
if ($pdo === null) {
|
if ($pdo === null) {
|
||||||
@@ -43,6 +44,13 @@ function getDatabaseConnection() {
|
|||||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
$pdo->exec($createTableSQL);
|
$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) {
|
} catch (PDOException $e) {
|
||||||
die("Database connection failed: " . $e->getMessage());
|
die("Database connection failed: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user