merge conflict

This commit is contained in:
marshal
2026-06-29 12:45:40 +03:00
202 changed files with 16895 additions and 3799 deletions

View File

@@ -78,6 +78,7 @@ export class CreateWarehouseModule1790000000000 implements MigrationInterface {
weight NUMERIC(14,3) NOT NULL DEFAULT 0,
volume NUMERIC(12,3) NULL,
status VARCHAR(32) NOT NULL DEFAULT 'ARRIVED_AT_WAREHOUSE',
inspection_status VARCHAR(20) NULL,
arrived_at TIMESTAMPTZ NULL,
inspected_at TIMESTAMPTZ NULL,
ready_for_loading_at TIMESTAMPTZ NULL,

View File

@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
/**
* Fix for fresh deployments: AddWarehouseInspection1750000000003 runs before
* the warehouse_inventory table exists, so it cannot add inspection_status.
*/
export class AddWarehouseInventoryInspectionStatusFix1791000000005 implements MigrationInterface {
private readonly table = 'freight.warehouse_inventory';
public async up(queryRunner: QueryRunner): Promise<void> {
if ((await queryRunner.hasTable(this.table)) && !(await queryRunner.hasColumn(this.table, 'inspection_status'))) {
await queryRunner.addColumn(
this.table,
new TableColumn({ name: 'inspection_status', type: 'varchar', length: '20', isNullable: true }),
);
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
if ((await queryRunner.hasTable(this.table)) && (await queryRunner.hasColumn(this.table, 'inspection_status'))) {
await queryRunner.dropColumn(this.table, 'inspection_status');
}
}
}

View File

@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
/**
* Catch-up for environments where AddWarehouseInspection ran before the
* warehouse module table existed. Production needs this column for unload and
* inspection flows because the WarehouseInventory entity maps inspectionStatus.
*/
export class EnsureWarehouseInventoryInspectionStatus1821000000001 implements MigrationInterface {
private readonly table = 'freight.warehouse_inventory';
public async up(queryRunner: QueryRunner): Promise<void> {
if (!(await queryRunner.hasColumn(this.table, 'inspection_status'))) {
await queryRunner.addColumn(
this.table,
new TableColumn({
name: 'inspection_status',
type: 'varchar',
length: '20',
isNullable: true,
}),
);
}
await queryRunner.query(`
CREATE INDEX IF NOT EXISTS idx_warehouse_inventory_inspection_status
ON freight.warehouse_inventory(inspection_status)
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX IF EXISTS freight.idx_warehouse_inventory_inspection_status
`);
if (await queryRunner.hasColumn(this.table, 'inspection_status')) {
await queryRunner.dropColumn(this.table, 'inspection_status');
}
}
}

View File

@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddDistanceColumnsToVehicles1821000000002 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE freight.vehicles
ADD COLUMN IF NOT EXISTS estimated_distance_km NUMERIC,
ADD COLUMN IF NOT EXISTS actual_distance_km NUMERIC;
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE freight.vehicles
DROP COLUMN IF EXISTS estimated_distance_km,
DROP COLUMN IF EXISTS actual_distance_km;
`);
}
}

View File

@@ -0,0 +1,53 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from 'typeorm';
export class CreateImportDjiboutiOperations1822000000000 implements MigrationInterface {
name = 'CreateImportDjiboutiOperations1822000000000';
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
schema: 'freight',
name: 'import_djibouti_operations',
columns: [
{ name: 'id', type: 'uuid', isPrimary: true, generationStrategy: 'uuid', default: 'uuid_generate_v4()' },
{ name: 'train_schedule_id', type: 'uuid', isUnique: true },
{ name: 'documents', type: 'jsonb', default: "'{}'::jsonb" },
{ name: 'gatepass_granted_at', type: 'timestamptz', isNullable: true },
{ name: 'ready_for_loading_at', type: 'timestamptz', isNullable: true },
{ name: 'loaded_on_train_at', type: 'timestamptz', isNullable: true },
{ name: 'departed_from_djibouti_at', type: 'timestamptz', isNullable: true },
{ name: 'load_list_generated_at', type: 'timestamptz', isNullable: true },
{ name: 'performed_by', type: 'varchar', length: '120', isNullable: true },
{ name: 'notes', type: 'text', 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.createIndex(
'freight.import_djibouti_operations',
new TableIndex({
name: 'idx_import_djibouti_operations_schedule',
columnNames: ['train_schedule_id'],
}),
);
await queryRunner.createForeignKey(
'freight.import_djibouti_operations',
new TableForeignKey({
columnNames: ['train_schedule_id'],
referencedTableName: 'train_schedules',
referencedSchema: 'freight',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('freight.import_djibouti_operations', true);
}
}

View File

@@ -0,0 +1,95 @@
import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm';
export class CreateImportOperationsTables1823000000000 implements MigrationInterface {
name = 'CreateImportOperationsTables1823000000000';
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
schema: 'freight',
name: 'djibouti_import_incidents',
columns: [
{ name: 'id', type: 'uuid', isPrimary: true, generationStrategy: 'uuid', default: 'uuid_generate_v4()' },
{ name: 'booking_id', type: 'uuid' },
{ name: 'container_number', type: 'varchar', length: '80', isNullable: true },
{ name: 'cargo_id', type: 'uuid', isNullable: true },
{ name: 'facility', type: 'varchar', length: '120', isNullable: true },
{ name: 'station', type: 'varchar', length: '120', isNullable: true },
{ name: 'incident_type', type: 'varchar', length: '40' },
{ name: 'description', type: 'text' },
{ name: 'photos', type: 'jsonb', default: "'[]'::jsonb" },
{ name: 'reported_by', type: 'varchar', length: '120', isNullable: true },
{ name: 'reported_at', type: 'timestamptz' },
{ name: 'created_at', type: 'timestamptz', default: 'now()' },
{ name: 'updated_at', type: 'timestamptz', default: 'now()' },
{ name: 'deleted_at', type: 'timestamptz', isNullable: true },
],
}),
true,
);
await queryRunner.createIndex('freight.djibouti_import_incidents', new TableIndex({ name: 'idx_djibouti_incidents_booking', columnNames: ['booking_id'] }));
await queryRunner.createIndex('freight.djibouti_import_incidents', new TableIndex({ name: 'idx_djibouti_incidents_container', columnNames: ['container_number'] }));
await queryRunner.createIndex('freight.djibouti_import_incidents', new TableIndex({ name: 'idx_djibouti_incidents_type', columnNames: ['incident_type'] }));
await queryRunner.createTable(
new Table({
schema: 'freight',
name: 'import_customs_finalizations',
columns: [
{ name: 'id', type: 'uuid', isPrimary: true, generationStrategy: 'uuid', default: 'uuid_generate_v4()' },
{ name: 'booking_id', type: 'uuid', isUnique: true },
{ name: 'documents', type: 'jsonb', default: "'{}'::jsonb" },
{ name: 'declaration_serial_number', type: 'varchar', length: '120', isNullable: true },
{ name: 'duties_taxes_notified_at', type: 'timestamptz', isNullable: true },
{ name: 'duties_taxes_paid_at', type: 'timestamptz', isNullable: true },
{ name: 'customs_risk', type: 'varchar', length: '12', isNullable: true },
{ name: 'import_release_permitted_at', type: 'timestamptz', isNullable: true },
{ name: 'completed_at', type: 'timestamptz', isNullable: true },
{ name: 'performed_by', type: 'varchar', length: '120', isNullable: true },
{ name: 'notes', type: 'text', 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.createIndex('freight.import_customs_finalizations', new TableIndex({ name: 'idx_import_customs_booking', columnNames: ['booking_id'] }));
await queryRunner.createIndex('freight.import_customs_finalizations', new TableIndex({ name: 'idx_import_customs_risk', columnNames: ['customs_risk'] }));
await queryRunner.createTable(
new Table({
schema: 'freight',
name: 'empty_container_returns',
columns: [
{ name: 'id', type: 'uuid', isPrimary: true, generationStrategy: 'uuid', default: 'uuid_generate_v4()' },
{ name: 'container_number', type: 'varchar', length: '80' },
{ name: 'booking_id', type: 'uuid', isNullable: true },
{ name: 'customer_id', type: 'uuid', isNullable: true },
{ name: 'return_date', type: 'timestamptz' },
{ name: 'facility', type: 'varchar', length: '120', isNullable: true },
{ name: 'yard', type: 'varchar', length: '120', isNullable: true },
{ name: 'zone', type: 'varchar', length: '120', isNullable: true },
{ name: 'condition', type: 'text', isNullable: true },
{ name: 'handover_note', type: 'text', isNullable: true },
{ name: 'status', type: 'varchar', length: '40', default: "'RETURNED'" },
{ name: 'wagon_allocation_reference', type: 'varchar', length: '120', isNullable: true },
{ name: 'performed_by', type: 'varchar', length: '120', 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.createIndex('freight.empty_container_returns', new TableIndex({ name: 'idx_empty_returns_container', columnNames: ['container_number'] }));
await queryRunner.createIndex('freight.empty_container_returns', new TableIndex({ name: 'idx_empty_returns_booking', columnNames: ['booking_id'] }));
await queryRunner.createIndex('freight.empty_container_returns', new TableIndex({ name: 'idx_empty_returns_status', columnNames: ['status'] }));
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('freight.empty_container_returns', true);
await queryRunner.dropTable('freight.import_customs_finalizations', true);
await queryRunner.dropTable('freight.djibouti_import_incidents', true);
}
}