Files
mahmoodandCursor 15adbb7fe1 fix(api): survive existing-schema boots without DB shell
Nginx 502 Host-not-found meant the API never stayed listening. Stamp all
migrations when tracking is empty but a late table exists, apply DDL
statement-by-statement skipping already-exists, harden remaining CREATE
TYPE/TABLE files, and never let seed crash the process.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-27 17:35:25 +03:30

34 lines
1.4 KiB
SQL

-- Revocable app sessions (customer app and sales-expert app).
--
-- The admin panel got this in 20260925120000_admin_session; the app token family
-- had the same gap: a 30-day self-contained token that nothing could end early.
-- That matters more here, because the app's login is OTP-only — there is no
-- password an operator could change to cut access.
--
-- No foreign key on purpose: an app token's subject is a Customer for a customer
-- and an AdminUser for a sales expert (D21), which one FK cannot express.
CREATE TABLE IF NOT EXISTS "AppSession" (
"id" TEXT NOT NULL,
"jti" TEXT NOT NULL,
"subjectId" TEXT NOT NULL,
"subjectType" TEXT NOT NULL,
"mobile" TEXT,
"iamSessionId" TEXT,
"iamSub" TEXT,
"ipAddress" TEXT,
"userAgent" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"expiresAt" TIMESTAMP(3),
"lastSeenAt" TIMESTAMP(3),
"revokedAt" TIMESTAMP(3),
"revokedReason" TEXT,
CONSTRAINT "AppSession_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX IF NOT EXISTS "AppSession_jti_key" ON "AppSession"("jti");
CREATE INDEX IF NOT EXISTS "AppSession_subjectId_idx" ON "AppSession"("subjectId");
CREATE INDEX IF NOT EXISTS "AppSession_iamSessionId_idx" ON "AppSession"("iamSessionId");
CREATE INDEX IF NOT EXISTS "AppSession_iamSub_idx" ON "AppSession"("iamSub");
CREATE INDEX IF NOT EXISTS "AppSession_expiresAt_idx" ON "AppSession"("expiresAt");