import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm'; /** * Per-backoffice-user trade-direction scope (import / export / intercity). * A user with no row (or all three directions) is unrestricted. Admins * (super_admin / organization_admin) bypass the scope entirely. */ export class CreateUserTradeAccess3150000000000 implements MigrationInterface { name = 'CreateUserTradeAccess3150000000000'; public async up(queryRunner: QueryRunner): Promise { await queryRunner.createTable( new Table({ schema: 'freight', name: 'user_trade_access', columns: [ { name: 'id', type: 'uuid', isPrimary: true, generationStrategy: 'uuid', default: 'gen_random_uuid()' }, // IAM user id (iam.users) — no FK, iam schema is externally owned. { name: 'user_id', type: 'uuid', isUnique: true }, // Comma-separated subset of IMPORT,EXPORT,DOMESTIC (simple-array). { name: 'directions', type: 'text', default: "''" }, { 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.createIndex( 'freight.user_trade_access', new TableIndex({ name: 'idx_user_trade_access_user_id', columnNames: ['user_id'], }), ); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.dropTable('freight.user_trade_access', true); } }