fix: resolve system user ID in backup restore for projects
The restore service hardcoded ownerId as the literal string 'system' instead of looking up the actual system user ID. This caused FK constraint violations when restoring projects to a fresh database. Now resolves the system user by email, falling back to the first available user. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -270,10 +270,20 @@ export class RestoreService {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resolve a valid owner — prefer system user, fall back to first user
|
||||
let ownerId = '';
|
||||
if (this.userRepo) {
|
||||
const allUsers = await this.userRepo.findAll();
|
||||
for (const u of allUsers) {
|
||||
if (u.email === 'system@mcpctl.local') { ownerId = u.id; break; }
|
||||
if (!ownerId) ownerId = u.id;
|
||||
}
|
||||
}
|
||||
|
||||
const projectCreateData: { name: string; description: string; ownerId: string; proxyModel?: string; llmProvider?: string; llmModel?: string } = {
|
||||
name: project.name,
|
||||
description: project.description,
|
||||
ownerId: 'system',
|
||||
ownerId,
|
||||
};
|
||||
if (project.proxyModel) projectCreateData.proxyModel = project.proxyModel;
|
||||
if (project.llmProvider != null) projectCreateData.llmProvider = project.llmProvider;
|
||||
|
||||
Reference in New Issue
Block a user