Add balance adjustments (M8)
- New balance_adjustments table with CRUD store, sync logging, and service methods
- SQL migrations restructured: embed fs.FS from internal/store/migrations/, apply in order via user_version
- WeekService.Balance combines closed-weeks delta + adjustments delta; BalanceSummary breakdown
- Four REST routes: GET/POST /api/balance/adjustments, PUT/DELETE /api/balance/adjustments/{id}
- Dexie schema v2 + sync apply cases for balance_adjustments
- API client: BalanceAdjustment type, balance namespace (list/create/update/delete)
- utils: composeDeltaMs / decomposeDeltaMs helpers + 8 new Vitest tests (19 total, all passing)
- History page: balance card breakdown line + full adjustments section with inline add/edit/delete
This commit is contained in:
61
internal/store/migrations/001_initial.sql
Normal file
61
internal/store/migrations/001_initial.sql
Normal file
@@ -0,0 +1,61 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE entries (
|
||||
id TEXT PRIMARY KEY,
|
||||
start_time INTEGER NOT NULL,
|
||||
end_time INTEGER,
|
||||
auto_stopped INTEGER NOT NULL DEFAULT 0,
|
||||
note TEXT,
|
||||
day_key TEXT NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
deleted_at INTEGER
|
||||
);
|
||||
CREATE INDEX idx_entries_day ON entries(day_key);
|
||||
|
||||
CREATE TABLE closed_days (
|
||||
day_key TEXT PRIMARY KEY,
|
||||
start_time INTEGER,
|
||||
end_time INTEGER,
|
||||
worked_ms INTEGER NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
closed_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE closed_weeks (
|
||||
week_key TEXT PRIMARY KEY,
|
||||
expected_ms INTEGER NOT NULL,
|
||||
worked_ms INTEGER NOT NULL,
|
||||
delta_ms INTEGER NOT NULL,
|
||||
closed_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE settings_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
effective_from TEXT NOT NULL,
|
||||
hours_per_week REAL NOT NULL,
|
||||
workdays_mask INTEGER NOT NULL DEFAULT 31,
|
||||
timezone TEXT NOT NULL DEFAULT 'UTC',
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE sync_log (
|
||||
entity TEXT NOT NULL,
|
||||
entity_id TEXT NOT NULL,
|
||||
op TEXT NOT NULL,
|
||||
version INTEGER NOT NULL,
|
||||
payload TEXT NOT NULL,
|
||||
PRIMARY KEY (entity, entity_id, version)
|
||||
);
|
||||
|
||||
-- seed default settings
|
||||
INSERT INTO settings_history (effective_from, hours_per_week, workdays_mask, timezone, created_at)
|
||||
VALUES ('2000-01-01', 40.0, 31, 'UTC', unixepoch() * 1000);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS sync_log;
|
||||
DROP TABLE IF EXISTS settings_history;
|
||||
DROP TABLE IF EXISTS closed_weeks;
|
||||
DROP TABLE IF EXISTS closed_days;
|
||||
DROP INDEX IF EXISTS idx_entries_day;
|
||||
DROP TABLE IF EXISTS entries;
|
||||
14
internal/store/migrations/002_balance_adjustments.sql
Normal file
14
internal/store/migrations/002_balance_adjustments.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE balance_adjustments (
|
||||
id TEXT PRIMARY KEY,
|
||||
delta_ms INTEGER NOT NULL,
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
effective_at INTEGER NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
CREATE INDEX idx_balance_adjustments_effective_at ON balance_adjustments(effective_at);
|
||||
|
||||
-- +migrate Down
|
||||
DROP INDEX IF EXISTS idx_balance_adjustments_effective_at;
|
||||
DROP TABLE IF EXISTS balance_adjustments;
|
||||
Reference in New Issue
Block a user