diff --git a/apps/edr-passenger-api/prisma/migrations/20260608090000_rename_auditlog_userid_drop_fayda_userid/migration.sql b/apps/edr-passenger-api/prisma/migrations/20260608090000_rename_auditlog_userid_drop_fayda_userid/migration.sql new file mode 100644 index 000000000..52914b220 --- /dev/null +++ b/apps/edr-passenger-api/prisma/migrations/20260608090000_rename_auditlog_userid_drop_fayda_userid/migration.sql @@ -0,0 +1,10 @@ +-- AuditLog: drop FK, rename column, update index +ALTER TABLE passenger."AuditLog" DROP CONSTRAINT IF EXISTS "AuditLog_userId_fkey"; +ALTER TABLE passenger."AuditLog" RENAME COLUMN "userId" TO "iamUserId"; +DROP INDEX IF EXISTS passenger."AuditLog_userId_createdAt_idx"; +CREATE INDEX IF NOT EXISTS "AuditLog_iamUserId_createdAt_idx" ON passenger."AuditLog"("iamUserId", "createdAt"); + +-- FaydaVerificationSession: drop userId column and FK (iamUserId already carries this data) +ALTER TABLE passenger."FaydaVerificationSession" DROP CONSTRAINT IF EXISTS "FaydaVerificationSession_userId_fkey"; +ALTER TABLE passenger."FaydaVerificationSession" DROP COLUMN IF EXISTS "userId"; +DROP INDEX IF EXISTS passenger."FaydaVerificationSession_userId_idx"; diff --git a/apps/edr-passenger-api/prisma/schema.prisma b/apps/edr-passenger-api/prisma/schema.prisma index bcf96954b..04b431961 100644 --- a/apps/edr-passenger-api/prisma/schema.prisma +++ b/apps/edr-passenger-api/prisma/schema.prisma @@ -232,9 +232,6 @@ model User { passenger Passenger? agent Agent? sessions Session[] - auditLogs AuditLog[] - - faydaVerificationSessions FaydaVerificationSession[] @@schema("passenger") } @@ -1148,7 +1145,7 @@ model BaggageBooking { model AuditLog { id String @id @default(uuid()) - userId String? + iamUserId String? action String entityType String entityId String? @@ -1157,8 +1154,7 @@ model AuditLog { ipAddress String? userAgent String? createdAt DateTime @default(now()) - user User? @relation(fields: [userId], references: [id]) - @@index([userId, createdAt]) + @@index([iamUserId, createdAt]) @@index([entityType, entityId]) @@schema("passenger") @@ -1295,13 +1291,9 @@ model FaydaVerificationSession { expiresAt DateTime completedAt DateTime? - userId String? iamUserId String? bookingId String? - user User? @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@index([userId]) @@index([iamUserId]) @@index([bookingId]) @@index([state]) diff --git a/apps/edr-passenger-api/src/modules/auth/passenger-auth.service.ts b/apps/edr-passenger-api/src/modules/auth/passenger-auth.service.ts index e78e814e0..759ba4a95 100644 --- a/apps/edr-passenger-api/src/modules/auth/passenger-auth.service.ts +++ b/apps/edr-passenger-api/src/modules/auth/passenger-auth.service.ts @@ -195,10 +195,10 @@ export class PassengerAuthService { await tx.userPreferences.create({ data: { iamUserId: data.iamUserId } }); await tx.auditLog.create({ data: { - userId: user.id, + iamUserId: data.iamUserId, action: data.auditAction, entityType: 'User', - entityId: user.id, + entityId: data.iamUserId, newData: { email: data.email, iamUserId: data.iamUserId }, }, }); diff --git a/apps/edr-passenger-api/src/modules/verifayda/verifayda.service.ts b/apps/edr-passenger-api/src/modules/verifayda/verifayda.service.ts index f088de8bd..db4a61abb 100644 --- a/apps/edr-passenger-api/src/modules/verifayda/verifayda.service.ts +++ b/apps/edr-passenger-api/src/modules/verifayda/verifayda.service.ts @@ -141,7 +141,6 @@ export class VerifaydaService { platform: input.platform ?? 'WEB', saveToAccount: input.saveToAccount ?? false, iamUserId: input.userId ?? null, - userId: null, bookingId: input.bookingId ?? null, expiresAt, }, @@ -421,7 +420,6 @@ export class VerifaydaService { session: { id: string; iamUserId: string | null; - userId: string | null; bookingId: string | null; saveToAccount: boolean; },