mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-21 22:18:17 +02:00
Resolve issue with assigning users to groups in production environments
Adjust `server/storage.ts` to use raw SQL for inserting into `user_groups` when the `created_at` column is missing in production, and add a test script `test-user-groups.js` to verify this functionality. 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/pp1SgYO
This commit is contained in:
1 parent
28b60b6bca
commit
f705fb4b1c
3 files changed
+50
-6
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 266 KiB |
+14
-6
@@ -694,15 +694,23 @@ export class DatabaseStorage implements IStorage {
|
|||||||
const [newUserGroup] = await db.insert(userGroups).values(userGroup).returning();
|
const [newUserGroup] = await db.insert(userGroups).values(userGroup).returning();
|
||||||
return newUserGroup;
|
return newUserGroup;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// If created_at column doesn't exist (production), insert without it
|
// If created_at column doesn't exist (production), use raw SQL
|
||||||
if (error?.code === '42703' && error?.message?.includes('created_at')) {
|
if (error?.code === '42703' && error?.message?.includes('created_at')) {
|
||||||
console.log('⚠️ Production mode: user_groups table missing created_at column, inserting without it');
|
console.log('⚠️ Production mode: user_groups table missing created_at column, using raw SQL');
|
||||||
const userGroupWithoutCreatedAt = {
|
|
||||||
|
// Use raw SQL to insert without created_at column
|
||||||
|
await db.execute(sql`
|
||||||
|
INSERT INTO user_groups (user_id, group_id)
|
||||||
|
VALUES (${userGroup.userId}, ${userGroup.groupId})
|
||||||
|
ON CONFLICT DO NOTHING
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Return a UserGroup object with null created_at
|
||||||
|
return {
|
||||||
userId: userGroup.userId,
|
userId: userGroup.userId,
|
||||||
groupId: userGroup.groupId
|
groupId: userGroup.groupId,
|
||||||
|
createdAt: null
|
||||||
};
|
};
|
||||||
const [newUserGroup] = await db.insert(userGroups).values(userGroupWithoutCreatedAt).returning();
|
|
||||||
return { ...newUserGroup, createdAt: null };
|
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Test script pour vérifier l'attribution des groupes en production
|
||||||
|
// À exécuter avec: node test-user-groups.js
|
||||||
|
|
||||||
|
import { storage } from './server/storage.js';
|
||||||
|
|
||||||
|
async function testUserGroups() {
|
||||||
|
try {
|
||||||
|
console.log('🧪 Test d\'attribution des groupes...');
|
||||||
|
|
||||||
|
// Test data
|
||||||
|
const testUserGroup = {
|
||||||
|
userId: 'test_user_123',
|
||||||
|
groupId: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('📝 Tentative d\'attribution du groupe:', testUserGroup);
|
||||||
|
|
||||||
|
const result = await storage.assignUserToGroup(testUserGroup);
|
||||||
|
|
||||||
|
console.log('✅ Attribution réussie:', result);
|
||||||
|
console.log('🎉 Le problème d\'attribution des groupes est résolu !');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Erreur lors du test:', error);
|
||||||
|
console.error('Code d\'erreur:', error?.code);
|
||||||
|
console.error('Message:', error?.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
console.log('🏭 Exécution en mode production');
|
||||||
|
testUserGroups();
|
||||||
|
} else {
|
||||||
|
console.log('🛠️ Ce test est conçu pour la production');
|
||||||
|
console.log('Pour tester localement, définissez NODE_ENV=production');
|
||||||
|
}
|
||||||
Reference in new issue
Block a user