Skip to content

Create a seeding script for laps and telemetry packets (development/test only) #282

@justin-phxm

Description

@justin-phxm

Overview

Create a TypeORM seeding script for the database, focused on development and test environments, to populate the Lap and TelemetryPacket tables. This script should:

  • Reference the generateFakeTelemetryData() from packages/shared/src/functions.ts to generate 1,000 packets and 100 lap packets.
  • Generate and persist related entity records as required by foreign keys (i.e., Lap, Driver, TelemetryPacket, etc. – see schemas below).
  • Clear all relevant tables (Lap, TelemetryPacket, and referenced entities) before seeding, ensuring idempotency.
  • Be runnable as a CLI script, and registered as a script entry in package.json (e.g., npm run seed).
  • Assist dev/test only; not intended for production data.

Implementation Plan

  1. Analyze Entity Schemas: Review entity definitions for Lap, TelemetryPacket, Driver, etc.:
  2. Set Up Script Structure: Create a new script (e.g., seed.ts or seed.js) in a logical place (e.g., scripts/ or top-level)
    • Connect to the database using TypeORM config.
  3. Data Generation:
    • Use generateFakeTelemetryData() for fake packet data.
    • Define constants for 1,000 TelemetryPacket objects and 100 Lap entries, referencing each other as appropriate.
    • Create related entities if required (e.g., create fake Driver records if required by Lap/Packet FK).
  4. Clear Existing Data:
    • Before inserting new records, delete data from Lap, TelemetryPacket, and all related tables (dependency order!).
    • Goal: script must be idempotent and avoid duplicating data on repeated runs.
  5. Seed Data:
    • Insert related entities (parents first), 100 Laps, and 1,000 TelemetryPackets.
  6. Script Integration:
    • Add an entry (e.g., "seed": "ts-node scripts/seed.ts") to package.json.
  7. Testing:
    • Test script on a local development DB.

Questions

  • Please confirm if the Lap and Packet seeds should have any specific relationship or if random assignment is OK? refer to the LapController.ts file in how the RFID and Timestamp of the lapData packet to see the relationship of data. typically we would create the packets first, then derive the lapData from the packets. We might have 1 lap packet for every 10 telemetry packets or something like that.

  • Confirm: create at least the referenced Driver (or other FK) entities if not present?
    Yes.

References


Copilot will proceed to implementation details after your confirmation, or if you answer the above questions.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions