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(),