Add cost history to the Costs page: what it cost each month, and what changed
Each cost item's name, amount, currency, period and kind are kept as versions (cost_item_versions), and Hetzner's estimate is written down once a day (cost_snapshots), so a past month's figure and the changes between can be worked out. History card with monthly bars per currency, month-by-month figures and a list of added, changed and removed items. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b29c0b7d04
commit
9f366c37de
15 files changed
+9716
-3
No files matched your search
@@ -1299,6 +1299,39 @@ export const costItems = sqliteTable("cost_items", {
|
||||
updatedAt: text("updated_at").notNull(), // ISO
|
||||
});
|
||||
|
||||
// What an item on the Costs page was at each time: one row for each stretch in which its name, amount, currency, period and kind were what they are, opened when it is added or changed and closed (validTo)
|
||||
// when it is changed again or removed. It is what lets the Costs page say what the homelab cost in a past month, and what changed. `itemId` is a soft reference: the row stays when the item is removed.
|
||||
// Kept in step with cost_items by services/costHistory.ts, which also fills it in for items that were there before it existed (from the day each was added).
|
||||
export const costItemVersions = sqliteTable(
|
||||
"cost_item_versions",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
itemId: integer("item_id").notNull(),
|
||||
name: text("name").notNull(),
|
||||
amount: real("amount").notNull(), // per period, including VAT
|
||||
currency: text("currency").notNull(),
|
||||
period: text("period").notNull(), // month | year
|
||||
category: text("category").notNull(),
|
||||
validFrom: text("valid_from").notNull(), // ISO
|
||||
validTo: text("valid_to"), // ISO; null: still in force
|
||||
},
|
||||
(t) => [index("cost_item_versions_item_idx").on(t.itemId)],
|
||||
);
|
||||
|
||||
// What can be read rather than typed (a Hetzner project's monthly estimate) as it was on each day, one row for each day and source, written once a day: the estimate moves with the servers, and the
|
||||
// estimate of a past month cannot be worked out afterwards. `key` is the source ("hetzner:3"). Read by services/costHistory.ts.
|
||||
export const costSnapshots = sqliteTable(
|
||||
"cost_snapshots",
|
||||
{
|
||||
day: text("day").notNull(), // YYYY-MM-DD (UTC)
|
||||
key: text("key").notNull(),
|
||||
name: text("name").notNull(),
|
||||
currency: text("currency").notNull(),
|
||||
monthly: real("monthly").notNull(), // per month, including VAT, at list prices
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.day, t.key] })],
|
||||
);
|
||||
|
||||
// ─── Speedtest Tracker ──────────────────────────────────────────────────────
|
||||
|
||||
// The speed tests a Speedtest Tracker (an integration of type "speedtest") has made, one row for each, kept for 90 days: when, how fast down and up (bits per second) and the ping (ms).
|
||||
|
||||
Reference in new issue
Block a user