mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 19:58:11 +00:00
Add migration to widen window_duration_hours precision and update related components for duration handling
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
/**
|
||||
* Widen train_scheduling_global_rules.window_duration_hours from numeric(4,2)
|
||||
* to numeric(6,4). The UI now lets staff enter the booking-window duration in
|
||||
* minutes / hours / days and converts to the column's native hours unit; a
|
||||
* 4-minute window is 0.0667h, which numeric(4,2) rounds to 0.07 (≈3.96 min).
|
||||
* Four decimals store sub-minute durations exactly (0.0667h → 4.00 min).
|
||||
*/
|
||||
export class WidenWindowDurationHoursPrecision1910000000000
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = "WidenWindowDurationHoursPrecision1910000000000";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.train_scheduling_global_rules
|
||||
ALTER COLUMN window_duration_hours TYPE numeric(6, 4);
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.train_scheduling_global_rules
|
||||
ALTER COLUMN window_duration_hours TYPE numeric(4, 2);
|
||||
`);
|
||||
}
|
||||
}
|
||||
@@ -60,11 +60,13 @@ export class UpdateTrainSchedulingGlobalRulesDto {
|
||||
@Max(23)
|
||||
windowOpenHour?: number;
|
||||
|
||||
// Stored in hours. The UI enters this in minutes/hours/days and converts to
|
||||
// hours before sending, so the floor is 1 minute (0.0166h) — not 15 min.
|
||||
@ApiPropertyOptional({ example: 3 })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0.25)
|
||||
@Min(0.0166)
|
||||
@Max(12)
|
||||
windowDurationHours?: number;
|
||||
|
||||
|
||||
@@ -54,11 +54,13 @@ export class TrainSchedulingGlobalRules extends BaseEntity {
|
||||
@Column({ name: 'window_open_hour', type: 'int', default: 8 })
|
||||
windowOpenHour!: number;
|
||||
|
||||
// Stored in hours; 4 decimals so sub-minute UI durations (4 min = 0.0667h)
|
||||
// are exact. See WidenWindowDurationHoursPrecision migration.
|
||||
@Column({
|
||||
name: 'window_duration_hours',
|
||||
type: 'numeric',
|
||||
precision: 4,
|
||||
scale: 2,
|
||||
precision: 6,
|
||||
scale: 4,
|
||||
default: 3,
|
||||
})
|
||||
windowDurationHours!: number;
|
||||
|
||||
Reference in New Issue
Block a user