-
Notifications
You must be signed in to change notification settings - Fork 0
Move to timescale #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to timescale #271
Changes from 6 commits
f457f6b
1bf9bf7
b3380be
c04a648
1d7040f
f527161
2f4cc16
22a2484
4f26037
83a9f30
9e80ead
e51a7ef
7a9b5f7
8400abd
b495b47
4cc03aa
b54991b
d0ccc49
4a6704d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,110 +19,110 @@ import { Hypertable, TimeColumn } from "@timescaledb/typeorm"; | |
| export class Battery { | ||
| @TimeColumn() | ||
| @PrimaryColumn({ type: "timestamptz" }) | ||
| timestamp!: Date; | ||
| Timestamp!: Date; | ||
|
|
||
| @PrimaryColumn({ type: "text" }) | ||
| rfid!: string; | ||
| Rfid!: string; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| always_on_signal_status!: boolean; | ||
| AlwaysOnSignalStatus!: boolean; | ||
|
|
||
| @Column({ type: "float" }) | ||
| average_cell_voltage!: number; | ||
| AverageCellVoltage!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| average_temperature!: number; | ||
| AverageTemperature!: number; | ||
|
|
||
| @Column({ type: "integer" }) | ||
| bmu_alive!: number; | ||
| BmuAlive!: number; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| charge_relay_enabled!: boolean; | ||
| ChargeRelayEnabled!: boolean; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| charger_safety_enabled!: boolean; | ||
| ChargerSafetyEnabled!: boolean; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| discharge_relay_enabled!: boolean; | ||
| DischargeRelayEnabled!: boolean; | ||
|
|
||
| @Column({ type: "float" }) | ||
| fan_speed!: number; | ||
| FanSpeed!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| fan_voltage!: number; | ||
| FanVoltage!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| high_cell_voltage!: number; | ||
| HighCellVoltage!: number; | ||
|
|
||
| @Column({ type: "integer" }) | ||
| high_cell_voltage_id!: number; | ||
| HighCellVoltageId!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| high_temperature!: number; | ||
| HighTemperature!: number; | ||
|
|
||
| @Column({ type: "integer" }) | ||
| high_thermistor_id!: number; | ||
| HighThermistorId!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| input_12v!: number; | ||
| Input12v!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| internal_temperature!: number; | ||
| InternalTemperature!: number; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| is_charging_signal_status!: boolean; | ||
| IsChargingSignalStatus!: boolean; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| is_ready_signal_status!: boolean; | ||
| IsReadySignalStatus!: boolean; | ||
|
|
||
| @Column({ type: "float" }) | ||
| low_cell_voltage!: number; | ||
| LowCellVoltage!: number; | ||
|
|
||
| @Column({ type: "integer" }) | ||
| low_cell_voltage_id!: number; | ||
| LowCellVoltageId!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| low_temperature!: number; | ||
| LowTemperature!: number; | ||
|
|
||
| @Column({ type: "integer" }) | ||
| low_thermistor_id!: number; | ||
| LowThermistorId!: number; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| malfunction_indicator_active!: boolean; | ||
| MalfunctionIndicatorActive!: boolean; | ||
|
|
||
| @Column({ type: "float" }) | ||
| maximum_cell_voltage!: number; | ||
| MaximumCellVoltage!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| maximum_pack_voltage!: number; | ||
| MaximumPackVoltage!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| minimum_cell_voltage!: number; | ||
| MinimumCellVoltage!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| minimum_pack_voltage!: number; | ||
| MinimumPackVoltage!: number; | ||
|
|
||
| @Column({ type: "boolean" }) | ||
| multi_purpose_input_signal_status!: boolean; | ||
| MultiPurposeInputSignalStatus!: boolean; | ||
|
|
||
| @Column({ type: "float" }) | ||
| pack_amphours!: number; | ||
| PackAmphours!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| pack_current!: number; | ||
| PackCurrent!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| pack_depth_of_discharge!: number; | ||
| PackDepthOfDischarge!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| pack_state_of_charge!: number; | ||
| PackStateOfCharge!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| pack_voltage!: number; | ||
| PackVoltage!: number; | ||
|
|
||
| @Column({ type: "integer" }) | ||
| populated_cells!: number; | ||
| PopulatedCells!: number; | ||
|
|
||
| @Column({ type: "float" }) | ||
| requested_fan_speed!: number; | ||
| RequestedFanSpeed!: number; | ||
|
Comment on lines
+22
to
+127
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find migration files related to battery table renaming
find . -type f \( -name "*migration*" -o -name "*migrate*" \) -path "*/db/*" | head -20Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 57 🏁 Script executed: #!/bin/bash
# Check Battery entity for explicit column name mappings
rg '@Column' packages/db/src/entities/Battery.entity.ts -A 1 -B 0 | head -40Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 936 🏁 Script executed: #!/bin/bash
# Get full Battery entity file to see complete structure
wc -l packages/db/src/entities/Battery.entity.tsRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 121 🏁 Script executed: #!/bin/bash
# Read full Battery.entity.ts file
cat -n packages/db/src/entities/Battery.entity.tsRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 3778 🏁 Script executed: #!/bin/bash
# Search for migration files more broadly
find . -type f \( -name "*.ts" -o -name "*.js" \) | grep -i migrat | head -20Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 57 🏁 Script executed: #!/bin/bash
# Check for TypeORM migrations directory
fd -t d migrationRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 57 🏁 Script executed: #!/bin/bash
# Search for TypeORM DataSource or Connection configuration
rg -l "DataSource|createConnection|getConnection" packages/db/src --type ts | head -10Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 174 🏁 Script executed: #!/bin/bash
# Search for naming strategy configuration
rg "namingStrategy|NamingStrategy" packages/db/src --type ts -B 2 -A 2Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 57 🏁 Script executed: #!/bin/bash
# Check package.json for TypeORM version and configuration
cat packages/db/package.json 2>/dev/null || cat package.json | grep -A 20 '"typeorm"'Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 1367 🏁 Script executed: #!/bin/bash
# Search for any database configuration files
find . -name "*.env*" -o -name "*config*" -o -name "*ormconfig*" | grep -v node_modules | head -20Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 615 🏁 Script executed: #!/bin/bash
# Read the TypeORM data source configuration
cat packages/db/src/data-source.tsRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 787 🏁 Script executed: #!/bin/bash
# Check for migrations directory and any migration files
find packages/db -type d -name migrations -o -name migrationRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 57 🏁 Script executed: #!/bin/bash
# Look for any naming strategy usage or imports
rg "snake|pascal|kebab|naming" packages/db/src --type ts -iRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 57 🏁 Script executed: #!/bin/bash
# Check if Battery entity is imported or used anywhere else
rg "Battery" packages/db/src --type ts -lRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 539 🏁 Script executed: #!/bin/bash
# Check if Battery entity is referenced in any migration or services
rg "Battery" packages/ --type ts | head -20Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 1487 🏁 Script executed: #!/bin/bash
# List all entity files in the entities directory
ls -la packages/db/src/entities/Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 1167 🏁 Script executed: #!/bin/bash
# Check if there's a migrations directory
ls -la packages/db/src/migrations 2>/dev/null || echo "No migrations directory found"Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 104 🏁 Script executed: #!/bin/bash
# Check if Battery is used in TelemetryPacket or other entities
rg "Battery" packages/db/src/entities --type ts -B 2 -A 2Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 10165 🏁 Script executed: #!/bin/bash
# Check if Battery is used in repositories or services
cat packages/db/src/repositories/BatteryRepository.tsRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 470 🏁 Script executed: #!/bin/bash
# Check if Battery is imported or exported from index
cat packages/db/src/index.tsRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 363 🏁 Script executed: #!/bin/bash
# Check TypeORM version and how it handles naming strategy by default
npm list typeorm 2>/dev/null || rg '"typeorm"' packages/db/package.jsonRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 137 🏁 Script executed: #!/bin/bash
# Check if other entities also use PascalCase properties
head -50 packages/db/src/entities/MBMS.entity.tsRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 1294 🏁 Script executed: #!/bin/bash
# Check the BatteryFaults entity for comparison
head -50 packages/db/src/entities/BatteryFaults.entity.tsRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 1380 🏁 Script executed: #!/bin/bash
# Verify TypeORM's default naming strategy behavior
web_search "TypeORM 0.3 default naming strategy column names"Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 125 🌐 Web query:
💡 Result: Yes — in TypeORM 0.3.x you set a namingStrategy on the DataSource. Two common approaches to convert PascalCase / camelCase → snake_case:
Where to configure: DataSourceOptions includes namingStrategy — pass the instance when creating new DataSource. [2] References:
🏁 Script executed: #!/bin/bash
# Verify that data-source.ts doesn't have a namingStrategy
grep -i "namingstrategy" packages/db/src/data-source.ts || echo "No namingStrategy found in data-source.ts"Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 116 🏁 Script executed: #!/bin/bash
# Check if any other entity files have explicit name mappings in @Column
rg '@Column.*name:' packages/db/src/entities --type ts -cRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 57 Add explicit column name mappings to align properties with database schema. TypeORM 0.3.20 does not automatically convert property names to snake_case—it uses property names as column names by default. Your Battery entity uses PascalCase properties without explicit However, your Add explicit column name mappings to preserve compatibility with your database schema: Example fix for first few columns@Column({ name: "timestamp", type: "timestamptz" })
Timestamp!: Date;
@Column({ name: "rfid", type: "text" })
Rfid!: string;
@Column({ name: "always_on_signal_status", type: "boolean" })
AlwaysOnSignalStatus!: boolean;
@Column({ name: "average_cell_voltage", type: "float" })
AverageCellVoltage!: number;Apply this pattern to all 37 properties in the Battery entity, or configure a global 🤖 Prompt for AI Agents |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disable synchronize when using TimescaleDB hypertables.
TypeORM's
synchronize: truecan interfere with TimescaleDB hypertables because it doesn't understand TimescaleDB-specific features likecreate_hypertable(). When synchronize runs, it may recreate the TelemetryPacket table without the hypertable configuration, breaking time-series functionality even in development.🔧 Recommended fix
Always use migrations for schema changes with TimescaleDB to ensure hypertable configuration is properly applied.
📝 Committable suggestion
🤖 Prompt for AI Agents