From 462da4b2c132c6774fcf32114ad7338eeb709cc8 Mon Sep 17 00:00:00 2001 From: Semih Yesilyurt Date: Tue, 11 Aug 2026 12:34:24 +0300 Subject: [PATCH] =?UTF-8?q?fix(internal-admin):=20founderId=20uuid=20?= =?UTF-8?q?=E2=86=92=20text=20(status=5Fchanged=5Fby,=20impersonated=5Fby)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Süper Panel lifecycle (suspend/ban/reactivate) ve readonly impersonation aksiyonları founderId olarak panelin Better Auth kullanıcı ID'sini (32 karakter nanoid) gönderiyor; users.status_changed_by ve sessions.impersonated_by uuid olduğu için Postgres "invalid input syntax for type uuid" ile 500 dönüyordu — panelden askıya alma hiç çalışmadı, impersonation da hiç başarılı olmamış (sessions.impersonated_by tümü NULL). İki alan da FK'sız salt audit → text. Migration 0038 (0035 numarası main'de dunning tarafından alınmıştı; eski PR #257 dalı rebase edildi). Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Ww3tfpuxBcettz81dDvyYt --- apps/api/drizzle/0038_founder_id_text.sql | 7 +++++++ apps/api/drizzle/meta/_journal.json | 9 ++++++++- apps/api/src/database/schema/core.ts | 7 +++++-- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 apps/api/drizzle/0038_founder_id_text.sql diff --git a/apps/api/drizzle/0038_founder_id_text.sql b/apps/api/drizzle/0038_founder_id_text.sql new file mode 100644 index 0000000..8ebd164 --- /dev/null +++ b/apps/api/drizzle/0038_founder_id_text.sql @@ -0,0 +1,7 @@ +-- Süper Panel admin aksiyonları founderId olarak panelin Better Auth +-- kullanıcı ID'sini (32 karakter nanoid, ör. d17M1M3S6c…) gönderiyor; uuid +-- kolonlar bunu reddedip suspend/ban'ı ve readonly impersonation'ı 500 ile +-- düşürüyordu ("invalid input syntax for type uuid"). İki alan da FK'sız salt +-- audit → text. Mevcut UUID değerleri USING ile aynen korunur. +ALTER TABLE "users" ALTER COLUMN "status_changed_by" TYPE text USING "status_changed_by"::text; +ALTER TABLE "sessions" ALTER COLUMN "impersonated_by" TYPE text USING "impersonated_by"::text; diff --git a/apps/api/drizzle/meta/_journal.json b/apps/api/drizzle/meta/_journal.json index 9b53e4a..1e50163 100644 --- a/apps/api/drizzle/meta/_journal.json +++ b/apps/api/drizzle/meta/_journal.json @@ -267,6 +267,13 @@ "when": 1790332800000, "tag": "0037_rpartstore_decodes", "breakpoints": true + }, + { + "idx": 38, + "version": "7", + "when": 1790415663270, + "tag": "0038_founder_id_text", + "breakpoints": true } ] -} +} \ No newline at end of file diff --git a/apps/api/src/database/schema/core.ts b/apps/api/src/database/schema/core.ts index 0c6409d..d6f8b0b 100644 --- a/apps/api/src/database/schema/core.ts +++ b/apps/api/src/database/schema/core.ts @@ -32,7 +32,9 @@ export const users = pgTable( status: varchar("status", { length: 20 }).default("active").notNull(), statusReason: text("status_reason"), statusChangedAt: timestamp("status_changed_at", { withTimezone: true }), - statusChangedBy: uuid("status_changed_by"), + // Süper Panel founder ID'si (Better Auth nanoid) — sase users.id UUID'si + // DEĞİL, o yüzden text. FK yok; salt audit alanı. + statusChangedBy: text("status_changed_by"), referralCode: varchar("referral_code", { length: 20 }), referredBy: uuid("referred_by"), // Reward days earned via referrals that couldn't be applied to a live @@ -68,7 +70,8 @@ export const sessions = pgTable( // Süper Panel impersonation: when set, this session was created by the // founder via /internal/admin/users/:id/impersonate-readonly. // ImpersonationReadonlyGuard enforces the readonly contract. - impersonatedBy: uuid("impersonated_by"), + // Süper Panel founder ID'si (Better Auth nanoid), sase users.id değil → text. + impersonatedBy: text("impersonated_by"), impersonationReadonly: boolean("impersonation_readonly").default(false).notNull(), createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(), updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),