mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 16:28:12 +00:00
implement exchange settings management and fallback rate handling
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Single-row store for the USD→ETB fallback used when the CBE exchange-rate
|
||||
* endpoint is unreachable. The live CBE rate always wins; every successful
|
||||
* fetch overwrites this row, so it holds the last known good rate rather than
|
||||
* a constant that drifts. Operators can also set it by hand during an outage.
|
||||
*
|
||||
* Seeded with the CBE USD transactional selling rate on 2026-08-04, so the
|
||||
* fallback is usable before the first successful fetch.
|
||||
*/
|
||||
export class CreateExchangeSettings3240000000000 implements MigrationInterface {
|
||||
name = 'CreateExchangeSettings3240000000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
schema: 'freight',
|
||||
name: 'exchange_settings',
|
||||
columns: [
|
||||
{ name: 'id', type: 'uuid', isPrimary: true, generationStrategy: 'uuid', default: 'gen_random_uuid()' },
|
||||
{ name: 'fallback_rate', type: 'numeric', precision: 18, scale: 6 },
|
||||
// AUTO when written by the CBE sync, MANUAL when set in the backoffice.
|
||||
{ name: 'fallback_source', type: 'varchar', length: '16', default: "'AUTO'" },
|
||||
{ name: 'last_synced_at', type: 'timestamptz', isNullable: true },
|
||||
// IAM user id (iam.users) — no FK, iam schema is externally owned.
|
||||
{ name: 'updated_by_id', type: 'uuid', isNullable: true },
|
||||
{ name: 'created_at', type: 'timestamptz', default: 'now()' },
|
||||
{ name: 'updated_at', type: 'timestamptz', default: 'now()' },
|
||||
{ name: 'deleted_at', type: 'timestamptz', isNullable: true },
|
||||
],
|
||||
}),
|
||||
true,
|
||||
);
|
||||
|
||||
await queryRunner.query(`
|
||||
INSERT INTO freight.exchange_settings (fallback_rate, fallback_source)
|
||||
VALUES (162.416500, 'AUTO')
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('freight.exchange_settings', true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user