Files
orangecat/scripts/db/fix-participants-script.js
T
Your Name 38cc4669d8 chore: comprehensive codebase cleanup and organization
- Move 100+ files from root to proper directories
  - Migration scripts → scripts/db/
  - SQL files → supabase/sql/archive/
  - Test/debug scripts → scripts/test/
  - Documentation → docs/archive/ (organized by category)
  - Shell scripts → scripts/ (organized by category)

- Fix test organization
  - Remove nested tests/unit/tests/unit/ structure
  - Consolidate test files to proper locations

- Update documentation references
  - Update migration script paths in workflow docs
  - Update scripts/README.md with moved file notes

- Delete placeholder files
  - Remove empty placeholder.ipynb

- Result: Root directory now contains only essential config files
- Result: Professional, organized codebase structure
- Result: All files in proper locations per project standards

See docs/CLEANUP_COMPLETE.md for full details.
2025-12-21 22:57:54 +01:00

96 lines
1.9 KiB
JavaScript

const { createClient } = require('@supabase/supabase-js');
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.SUPABASE_SERVICE_ROLE_KEY
);
async function fixParticipants() {
try {
console.log('Fixing messaging participants...');
const maoUserId = 'cec88bc9-557f-452b-92f1-e093092fecd6';
// Get all conversations
const { data: conversations, error: convError } = await supabase
.from('conversations')
.select('id, title');
if (convError) {
console.error('Error fetching conversations:', convError);
return;
}
console.log(`Found ${conversations.length} conversations`);
let addedCount = 0;
// For each conversation, add mao if not already a participant
for (const conv of conversations) {
const { data: existingParticipant, error: partError } = await supabase
.from('conversation_participants')
.select('*')
.eq('conversation_id', conv.id)
.eq('user_id', maoUserId)
.maybeSingle();
if (partError && partError.code !== 'PGRST116') { // PGRST116 is "not found" which is expected
console.error('Error checking participant:', partError);
continue;
}
if (!existingParticipant) {
console.log(`Adding mao to conversation: ${conv.title || 'Untitled'}`);
const { error: insertError } = await supabase
.from('conversation_participants')
.insert({
conversation_id: conv.id,
user_id: maoUserId,
role: 'member',
is_active: true
});
if (insertError) {
console.error('Error adding participant:', insertError);
} else {
addedCount++;
}
}
}
console.log(`Successfully added mao as participant to ${addedCount} conversations`);
} catch (error) {
console.error('Script error:', error);
}
}
fixParticipants();