Address issue where users cannot be assigned to groups in production

Add error handling to the user group assignment to gracefully handle missing `created_at` column in production environments, and document the fix.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: a8a78c07-e900-425c-a577-5b4c5894379d
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/a8a78c07-e900-425c-a577-5b4c5894379d/yj7Yt4E
This commit is contained in:
michaelschal committed 2025-08-11 19:46:22 +00:00
1 parent 469880b6fe
commit 28b60b6bca
4 files changed
+73 -2

No files matched your search

+17 -2
View File
@@ -689,8 +689,23 @@ export class DatabaseStorage implements IStorage {
}
async assignUserToGroup(userGroup: InsertUserGroup): Promise<UserGroup> {
const [newUserGroup] = await db.insert(userGroups).values(userGroup).returning();
return newUserGroup;
try {
// Try with full schema first (development)
const [newUserGroup] = await db.insert(userGroups).values(userGroup).returning();
return newUserGroup;
} catch (error: any) {
// If created_at column doesn't exist (production), insert without it
if (error?.code === '42703' && error?.message?.includes('created_at')) {
console.log('⚠️ Production mode: user_groups table missing created_at column, inserting without it');
const userGroupWithoutCreatedAt = {
userId: userGroup.userId,
groupId: userGroup.groupId
};
const [newUserGroup] = await db.insert(userGroups).values(userGroupWithoutCreatedAt).returning();
return { ...newUserGroup, createdAt: null };
}
throw error;
}
}
async removeUserFromGroup(userId: string, groupId: number): Promise<void> {