mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 04:08:11 +00:00
feat(wagons): audited maintenance/availability toggle
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Audit trail for wagon status flips (Available ⇄ Maintenance and any other
|
||||
* bulk-status change): who moved which wagon from what to what, when, and why.
|
||||
* Written inside the same transaction as the status update itself.
|
||||
*/
|
||||
export class WagonStatusLogs3310000000000 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS freight.wagon_status_logs (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
wagon_id uuid NOT NULL REFERENCES freight.wagons(id),
|
||||
from_status varchar(30) NOT NULL,
|
||||
to_status varchar(30) NOT NULL,
|
||||
changed_by_user_id uuid,
|
||||
note text,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
deleted_at timestamptz
|
||||
)
|
||||
`);
|
||||
await queryRunner.query(`
|
||||
CREATE INDEX IF NOT EXISTS idx_wagon_status_logs_wagon
|
||||
ON freight.wagon_status_logs (wagon_id, created_at DESC)
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS freight.wagon_status_logs`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user