Hi! I get an error trying to bulk upsert in to the...
# help
j
Hi! I get an error trying to bulk upsert in to the following table. Error message says: All object keys must match The array I'm trying to upsert looks like this:
Copy code
[
  {
    id: 'si_KFtDgimqIKkY6q',
    subscription_id: 'sub_1JbNQoEXkCyWFmfFwTxz6Ewu',
    user_id: '8f6cb53b-4a97-4297-a722-727cb2e6f335'
  },
  {
    id: 'si_KFtDSFw9pGCr6G',
    subscription_id: 'sub_1JbNQoEXkCyWFmfFwTxz6Ewu',
    user_id: '8f6cb53b-4a97-4297-a722-727cb2e6f335'
  }
]
Anyone has a clue?
The upsert is happening directly after i created the subscription, which is referenced to with subscription_id. Is it maybe a race condition? That the subscription hasen't been inserted into the db yet? The code looks like this:
Copy code
const { data: subData, error: subError } = await supabaseAdmin
    .from('subscriptions')
    .upsert([subscriptionData]);

  const { data: subItemsData, error: subItemsError } = await supabaseAdmin
    .from('subscription_items')
    .insert([subscriptionItemsData]);
I switched from upsert to insert, and then I got this error message: message: 'column "0" of relation "subscription_items" does not exist',
But that dosen't make sense either. Because if i make a select from the subscriptions table, just before I'm trying to insert the subscription_items, I can see that the subscription has been created and should be able to make a reference to.
s
I’m not sure, but could this be a row level security thing? Your schema has RLS enabled and is blocking everything except for SELECT queries where the user_id matches
j
Shouldn’t be that because I’m calling it from server side code and using the service key and not the anon key 🙄
Anyone else got a clue? 😟
gash I'm stupid 🤦🏻‍♂️ I was passing in ([array]) instead of (array) in to the .upsert-function. Now it's working as excepted