fix(admin): migration Subscription/BYOK et repli getUsers
La table Subscription était dans le schéma sans migration SQL, ce qui cassait le rendu Server Components de /admin. Migration idempotente + fallback getUsers si la jointure échoue encore. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -23,9 +23,31 @@ async function checkAdmin() {
|
||||
return session
|
||||
}
|
||||
|
||||
const userListSelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
role: true,
|
||||
createdAt: true,
|
||||
subscription: {
|
||||
select: {
|
||||
tier: true,
|
||||
status: true,
|
||||
currentPeriodEnd: true,
|
||||
},
|
||||
},
|
||||
} as const
|
||||
|
||||
export async function getUsers() {
|
||||
await checkAdmin()
|
||||
try {
|
||||
return await prisma.user.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: userListSelect,
|
||||
})
|
||||
} catch (error) {
|
||||
// Prod DB parfois en retard sur les migrations (ex. table Subscription absente).
|
||||
console.error('getUsers with subscription failed, fallback without:', error)
|
||||
const users = await prisma.user.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: {
|
||||
@@ -34,19 +56,9 @@ export async function getUsers() {
|
||||
email: true,
|
||||
role: true,
|
||||
createdAt: true,
|
||||
subscription: {
|
||||
select: {
|
||||
tier: true,
|
||||
status: true,
|
||||
currentPeriodEnd: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
return users
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch users:', error)
|
||||
throw new Error('Failed to fetch users')
|
||||
return users.map((u) => ({ ...u, subscription: null }))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user