diff --git a/attached_assets/Pasted-GET-api-users-200-in-33ms-Error-deleting-user-error-update-or-delete-on-table-users-violates-1754935124372_1754935124372.txt b/attached_assets/Pasted-GET-api-users-200-in-33ms-Error-deleting-user-error-update-or-delete-on-table-users-violates-1754935124372_1754935124372.txt new file mode 100644 index 0000000..48b8c49 --- /dev/null +++ b/attached_assets/Pasted-GET-api-users-200-in-33ms-Error-deleting-user-error-update-or-delete-on-table-users-violates-1754935124372_1754935124372.txt @@ -0,0 +1,108 @@ +GET /api/users 200 in 33ms + +Error deleting user: error: update or delete on table "users" violates foreign key constraint "user_roles_assigned_by_fkey" on table "user_roles" + + at /app/node_modules/pg/lib/client.js:545:17 + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async file:///app/dist/index.js:1108:11 + + at async NodePgSession.transaction (file:///app/node_modules/drizzle-orm/node-postgres/session.js:142:22) + + at async DatabaseStorage.deleteUser (file:///app/dist/index.js:1090:9) + + at async file:///app/dist/index.js:4094:7 { + + length: 299, + + severity: 'ERROR', + + code: '23503', + + detail: 'Key (id)=(system) is still referenced from table "user_roles".', + + hint: undefined, + + position: undefined, + + internalPosition: undefined, + + internalQuery: undefined, + + where: undefined, + + schema: 'public', + + table: 'user_roles', + + column: undefined, + + dataType: undefined, + + constraint: 'user_roles_assigned_by_fkey', + + file: 'ri_triggers.c', + + line: '2609', + + routine: 'ri_ReportViolation' + +} + +DELETE /api/users/system 500 in 29ms + +HEAD /api/health 200 in 1ms + +Error deleting user: error: update or delete on table "users" violates foreign key constraint "user_roles_assigned_by_fkey" on table "user_roles" + + at /app/node_modules/pg/lib/client.js:545:17 + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async file:///app/dist/index.js:1108:11 + + at async NodePgSession.transaction (file:///app/node_modules/drizzle-orm/node-postgres/session.js:142:22) + + at async DatabaseStorage.deleteUser (file:///app/dist/index.js:1090:9) + + at async file:///app/dist/index.js:4094:7 { + + length: 299, + + severity: 'ERROR', + + code: '23503', + + detail: 'Key (id)=(system) is still referenced from table "user_roles".', + + hint: undefined, + + position: undefined, + + internalPosition: undefined, + + internalQuery: undefined, + + where: undefined, + + schema: 'public', + + table: 'user_roles', + + column: undefined, + + dataType: undefined, + + constraint: 'user_roles_assigned_by_fkey', + + file: 'ri_triggers.c', + + line: '2609', + + routine: 'ri_ReportViolation' + +} + +DELETE /api/users/system 500 in 19ms + diff --git a/attached_assets/image_1754935107751.png b/attached_assets/image_1754935107751.png new file mode 100644 index 0000000..d5884af Binary files /dev/null and b/attached_assets/image_1754935107751.png differ diff --git a/server/storage.ts b/server/storage.ts index a03e74b..e7757d3 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -420,10 +420,16 @@ export class DatabaseStorage implements IStorage { .set({ createdBy: adminUserId }) .where(eq(nocodbConfig.createdBy, id)); + // Update role assignments made BY this user (assignedBy field) + await tx + .update(userRoles) + .set({ assignedBy: adminUserId }) + .where(eq(userRoles.assignedBy, id)); + // Delete user-group assignments await tx.delete(userGroups).where(eq(userGroups.userId, id)); - // Delete user-role assignments + // Delete user-role assignments TO this user await tx.delete(userRoles).where(eq(userRoles.userId, id)); // Finally delete the user