refactor( iam ): rename AuditLog.userId to iamUserId; drop FaydaVerificationSession.userId

This commit is contained in:
Abubeker Yasin
2026-06-08 16:26:59 +03:00
parent 8c377e86d8
commit 32f2f4b917
4 changed files with 14 additions and 14 deletions

View File

@@ -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";

View File

@@ -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])

View File

@@ -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 },
},
});

View File

@@ -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;
},