Skip to content

Timescaledb#262

Merged
burtonjong merged 19 commits intomainfrom
timescaledb
Nov 15, 2025
Merged

Timescaledb#262
burtonjong merged 19 commits intomainfrom
timescaledb

Conversation

@burtonjong
Copy link
Member

@burtonjong burtonjong commented Nov 15, 2025

Summary by CodeRabbit

  • New Features

    • Added database management system with PostgreSQL support
    • New API endpoints for test entry management (create, read, update, delete, search operations)
    • Implemented graceful server shutdown handling
  • Documentation

    • Added SSM instance connection guidelines
  • Chores

    • Updated dependencies and build scripts for database support
    • Updated database infrastructure image to latest stable version

@burtonjong burtonjong requested a review from a team as a code owner November 15, 2025 18:26
@vercel
Copy link

vercel bot commented Nov 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
helios-telemetry Building Building Preview Comment Nov 15, 2025 6:26pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a new packages/db package with TypeORM configuration for PostgreSQL/TimescaleDB, including entities, repositories, services, and DTOs. Integrates the database layer into the server via a DatabaseManager singleton pattern, adds database lifecycle management (initialization and graceful shutdown), and updates build tooling and dependencies accordingly.

Changes

Cohort / File(s) Summary
Configuration & Tooling
.eslintignore, .gitignore, package.json, test.ts
Added ESLint ignore pattern for TypeScript entities; updated gitignore for db env files and dist; added Lerna-scoped npm scripts for db lifecycle (build, start, migrations, schema management); added new unused test file.
Database Package Setup
packages/db/.env.example, packages/db/README.md, packages/db/docker-compose.yml, packages/db/package.json, packages/db/tsconfig.json
Established new db package with environment configuration template, documentation, Docker Compose configuration for TimescaleDB (updated from HA to latest non-HA variant), package manifest with TypeORM/PostgreSQL dependencies, and TypeScript compiler settings with decorator support.
TypeORM Data Source & Configuration
packages/db/src/data-source.ts
Configured TypeORM DataSource for PostgreSQL, loads environment variables from .db.env, exports AppDataSource with database, host, port, credentials, entities, migrations, and synchronization settings.
Database Entities
packages/db/src/entities/TestTable.entity.ts
Defined TestTable entity mapped to TimescaleDB hypertable with UUID primary key, timestamp, name, optional description, status/value fields, and automatic timestamps; enabled compression by timestamp DESC.
Repository Layer
packages/db/src/interfaces/repositories.interface.ts, packages/db/src/repositories/BaseRepository.ts, packages/db/src/repositories/TestTableRepository.ts
Introduced generic IBaseRepository interface with CRUD operations; implemented abstract BaseRepository class with find/create/update/delete methods; created TestTableRepository with domain-specific queries (findByName, findActiveRecords, findByValueRange).
Service Layer
packages/db/src/services/DatabaseService.ts, packages/db/src/services/TestTableService.ts
Added DatabaseService for DataSource lifecycle (initialize/close) and repository access; created TestTableService with complete CRUD operations, input validation, field trimming, and default values for TestTable entries.
Database Package Exports
packages/db/src/types.ts, packages/db/src/index.ts
Added PageViewStats type interface; created barrel export exposing AppDataSource, entities, repositories, services, DTOs, and all public types from the db package.
Server Integration & Database Management
packages/server/src/database/DatabaseManager.ts, packages/server/src/controllers/BackendController/BackendController.ts, packages/server/src/controllers/TestTableController.ts
Introduced DatabaseManager singleton for encapsulating database service and lazy-loading test table service; integrated DatabaseManager into BackendController with initialization and cleanup lifecycle methods; created TestTableController with endpoints for CRUD operations and search on test entries.
Server Configuration & Lifecycle
packages/server/package.json, packages/server/tsconfig.json, packages/server/src/index.ts, packages/server/src/server.ts
Added "db" package dependency and TimescaleDB dev dependencies; enabled decorator metadata in TypeScript; added getBackendController accessor; implemented graceful shutdown handlers (SIGTERM/SIGINT) that cleanup database connections and close HTTP server.
Minor Updates
packages/server/src/datasources/SolarMQTTClient/SolarMQTTClient.types.ts
Corrected mqtt type import path from "mqtt/*" to "mqtt".

Sequence Diagrams

sequenceDiagram
    participant Server as server.ts
    participant BC as BackendController
    participant DBM as DatabaseManager<br/>(singleton)
    participant DBS as DatabaseService
    participant DB as PostgreSQL

    rect rgba(100, 200, 150, 0.3)
    Note over Server,DB: Application Startup
    Server->>BC: new BackendController()
    BC->>DBM: getInstance()
    BC->>DBM: initialize()
    DBM->>DBS: initialize()
    DBS->>DB: DataSource.initialize()
    DB-->>DBS: connection established
    DBS-->>DBM: ✓ initialized
    DBM-->>BC: ✓ database ready
    end

    rect rgba(100, 150, 200, 0.3)
    Note over Server,DB: API Request (CRUD via TestTableController)
    Server->>BC: HTTP request
    BC->>DBM: getInstance()
    DBM->>DBM: testTableService getter
    DBM-->>BC: TestTableService
    BC->>DB: query/command
    DB-->>BC: data
    BC-->>Server: HTTP response
    end

    rect rgba(200, 150, 100, 0.3)
    Note over Server,DB: Graceful Shutdown (SIGTERM/SIGINT)
    Server->>Server: gracefulShutdown()
    Server->>BC: getBackendController()
    Server->>BC: cleanup()
    BC->>DBM: close() [implicit via service]
    DBM->>DBS: close()
    DBS->>DB: DataSource.destroy()
    DB-->>DBS: ✓ closed
    DBS-->>BC: ✓ cleaned up
    Server->>Server: close HTTP server
    Server->>Server: exit(0)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Areas requiring extra attention:

  • TypeORM entity & repository patterns — Verify entity decorators (Hypertable, compression settings), repository method implementations using query builders, and correct use of TypeORM options (FindManyOptions, DeepPartial).
  • Singleton pattern implementation — Review DatabaseManager singleton pattern correctness, lazy initialization of TestTableService, and thread-safety considerations.
  • Lifecycle management — Ensure database initialization and cleanup are properly wired in BackendController and server shutdown handlers; check for resource leaks or missing error handling.
  • Data validation & input sanitization — Review TestTableService input validation (field presence, length limits, trim operations) and error responses in TestTableController.
  • Environment configuration — Verify .db.env loading, sensible defaults in data-source.ts, and consistency with .env.example.
  • Dependencies & imports — Confirm new db package dependency in server/package.json is correctly scoped, and all cross-package imports resolve correctly.

Poem

🐰 A database burrow, deep and true,
With TypeORM wiring and schemas new!
Repositories nested, services aligned,
Graceful shutdown when it's time to wind—
From startup leap to safe goodbye,
Our data layer soars up high! 🚀

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch timescaledb

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 380cbd0 and adf0650.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (27)
  • .eslintignore (1 hunks)
  • .gitignore (2 hunks)
  • docs/AMPLIFY.md (1 hunks)
  • package.json (1 hunks)
  • packages/db/.env.example (1 hunks)
  • packages/db/README.md (1 hunks)
  • packages/db/docker-compose.yml (1 hunks)
  • packages/db/package.json (1 hunks)
  • packages/db/src/data-source.ts (1 hunks)
  • packages/db/src/entities/TestTable.entity.ts (1 hunks)
  • packages/db/src/index.ts (1 hunks)
  • packages/db/src/interfaces/repositories.interface.ts (1 hunks)
  • packages/db/src/repositories/BaseRepository.ts (1 hunks)
  • packages/db/src/repositories/TestTableRepository.ts (1 hunks)
  • packages/db/src/services/DatabaseService.ts (1 hunks)
  • packages/db/src/services/TestTableService.ts (1 hunks)
  • packages/db/src/types.ts (1 hunks)
  • packages/db/tsconfig.json (1 hunks)
  • packages/server/package.json (3 hunks)
  • packages/server/src/controllers/BackendController/BackendController.ts (4 hunks)
  • packages/server/src/controllers/TestTableController.ts (1 hunks)
  • packages/server/src/database/DatabaseManager.ts (1 hunks)
  • packages/server/src/datasources/SolarMQTTClient/SolarMQTTClient.types.ts (1 hunks)
  • packages/server/src/index.ts (2 hunks)
  • packages/server/src/server.ts (2 hunks)
  • packages/server/tsconfig.json (2 hunks)
  • test.ts (1 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

@burtonjong burtonjong merged commit 4eab761 into main Nov 15, 2025
3 of 6 checks passed
@burtonjong burtonjong deleted the timescaledb branch November 15, 2025 18:27
@coderabbitai coderabbitai bot mentioned this pull request Dec 13, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jan 10, 2026
@coderabbitai coderabbitai bot mentioned this pull request Jan 31, 2026
@coderabbitai coderabbitai bot mentioned this pull request Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant