mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 16:31:12 -05:00
Fix: Correct Novu migration utility query
This commit is contained in:
@@ -28,16 +28,25 @@ export function NovuMigrationUtility() {
|
|||||||
setProgress(0);
|
setProgress(0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch users without Novu subscriber IDs
|
// First, fetch user IDs that already have Novu subscriber IDs
|
||||||
const { data: users, error: fetchError } = await supabase
|
const { data: existingPrefs, error: prefsError } = await supabase
|
||||||
.from('profiles')
|
|
||||||
.select('user_id, users:user_id(email)')
|
|
||||||
.not('user_id', 'in',
|
|
||||||
supabase
|
|
||||||
.from('user_notification_preferences')
|
.from('user_notification_preferences')
|
||||||
.select('user_id')
|
.select('user_id')
|
||||||
.not('novu_subscriber_id', 'is', null)
|
.not('novu_subscriber_id', 'is', null);
|
||||||
);
|
|
||||||
|
if (prefsError) throw prefsError;
|
||||||
|
|
||||||
|
const existingUserIds = existingPrefs?.map(p => p.user_id) || [];
|
||||||
|
|
||||||
|
// Fetch users without Novu subscriber IDs
|
||||||
|
const query = supabase
|
||||||
|
.from('profiles')
|
||||||
|
.select('user_id, users:user_id(email)');
|
||||||
|
|
||||||
|
// Only add the not filter if there are existing user IDs
|
||||||
|
const { data: users, error: fetchError } = existingUserIds.length > 0
|
||||||
|
? await query.not('user_id', 'in', `(${existingUserIds.join(',')})`)
|
||||||
|
: await query;
|
||||||
|
|
||||||
if (fetchError) throw fetchError;
|
if (fetchError) throw fetchError;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user