Skip to content

Team Operations Database

In plain English

Tracks team budgets, staff payroll, cloud software bills, and support incidents in a clean SQLite database without double-counting totals.

A Python 3.12 and SQLite 3 library and CLI for engineering department budgets, employee transfers, cloud spend, and incident recovery metrics.

1. Why I built it

Built to connect raw relational DDL constraints with transactional Python context management, MTTR edge cases, and regression-tested reporting.

Problem being solvedFlat joins across multiple 1:N child tables multiply aggregate totals, and naive `AVG(duration_minutes)` includes open unresolved incidents (`0` min), understating MTTR.

2. How it works

Defined tables and CHECK constraints in `src/company_db/schema.sql`, implemented `CompanyDatabaseManager` in `src/company_db/manager.py`, and exposed CLI commands in `src/company_db/cli.py`.

Joining `departments` directly to both `employees` and `cloud_services` in one SELECT silently multiplies payroll whenever a department owns multiple services. Engineering Ops DB enforces 3NF separation and pre-aggregates payroll and annualised cloud costs in independent Common Table Expressions (`emp_totals` and `svc_totals`) before joining back to `departments`.

Built around a context-managed `CompanyDatabaseManager`, the module activates `PRAGMA foreign_keys = ON`, validates non-blank parameters with `_require_non_blank`, checks query limit bounds, and appends `audit_log` rows inside the same atomic SQLite transaction as mutations.

`export_snapshot()` computes exact record totals with `SELECT COUNT(*) AS cnt FROM audit_log` independently of display pagination, while the CLI demo seeder detects existing department codes to stay idempotent across reruns.

3. Output & Source Specimen

Schema Constraints & Multi-CTE Query Plan

EntityPrimary / Foreign KeysEnforced Invariants
departmentsid PK, code UNIQUEannual_budget_gbp >= 0
employeesdepartment_id -> departments(id)ON DELETE RESTRICT, salary_gbp > 0
cloud_servicesdepartment_id -> departments(id)monthly_cost_gbp >= 0 (12x rollup CTE)
incidentsservice_id -> cloud_services(id)MTTR ignores resolved = 0 via CASE NULL
audit_logid PK, created_at DEFAULT CURRENT_TIMESTAMPWritten inside same transaction block
Core relational entities and fan-out-safe CTE aggregation design in schema.sql / manager.pyRun checks: pytest -v tests/test_manager.py

4. Design Decisions & Challenges

Key Design Decisions

  • 01.Isolated payroll (`emp_totals`) and annualised cloud spend (`svc_totals`) in separate CTEs before left-joining onto `departments`.
  • 02.Used `SELECT COUNT(*) AS cnt FROM audit_log` inside `export_snapshot()` instead of measuring a bounded fetch slice.
  • 03.Validated blank strings upfront via `_require_non_blank()` and checked positive bounds on audit query limits.

Edge Cases Handled

  • Excluding open incidents (`resolved = 0`) cleanly via `AVG(CASE WHEN i.resolved = 1 THEN i.duration_minutes END)` so SQL ignores unresolved rows while preserving open counts.
  • Keeping CLI demo seeding idempotent across repeated executions.

5. Testing & Limits

Automated Checks

Verified with 9 pytest checks in `tests/test_manager.py` and Ruff lint checks covering CTE accuracy, MTTR recalculation, transfers, employee deactivation, `--dept`/`--role`/`--audit-limit` CLI options, negative-limit validation, and JSON output.

Current Limits & Next Steps

  • Salaries store integer GBP while cloud spend uses NUMERIC; migrating all currency fields to integer pence would unify precision.

6. Key Takeaways

What building Team Operations Database reinforced

Pre-aggregating independent branches in CTEs keeps multi-table reports honest, and engine-level FOREIGN KEY and CHECK rules catch domain errors immediately on write.

  • — 9 pytest suites and Ruff pass cleanly in GitHub Actions CI.
  • — Source hosted at github.com/16lv/engineering-ops-db.

Recent Activity

Latest repository updates

All changes for 16lv/engineering-ops-db

feat: add --role CLI filter and strict negative limit validation

Exposed search_employees() role filtering in the engineering-ops-db CLI with exit code 2 handling for invalid arguments.

2026-11-249f2b6db

feat: add department filter and audit-limit CLI options

Added --dept and --audit-limit flags to engineering-ops-db CLI output with matching test coverage.

2026-11-2397384f2

Add python -m company_db runner and verify editable install in CI

Committed directly to engineering-ops-db (main) · Tracks team budgets, staff payroll, cloud software bills, and support incidents in a clean SQLite database without double-counting totals.

2026-11-212cf919d