-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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()frompackages/shared/src/functions.tsto 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
- Analyze Entity Schemas: Review entity definitions for Lap, TelemetryPacket, Driver, etc.:
- Set Up Script Structure: Create a new script (e.g.,
seed.tsorseed.js) in a logical place (e.g.,scripts/or top-level)- Connect to the database using TypeORM config.
- 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).
- Use
- 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.
- Seed Data:
- Insert related entities (parents first), 100 Laps, and 1,000 TelemetryPackets.
- Script Integration:
- Add an entry (e.g.,
"seed": "ts-node scripts/seed.ts") topackage.json.
- Add an entry (e.g.,
- 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
- Data generation:
generateFakeTelemetryData() - DB Schemas: Lap, Packet, Driver
Copilot will proceed to implementation details after your confirmation, or if you answer the above questions.