diff --git a/packages/db/src/repository/subscription.repo.ts b/packages/db/src/repository/subscription.repo.ts index 021382c8..9d7ff9e7 100644 --- a/packages/db/src/repository/subscription.repo.ts +++ b/packages/db/src/repository/subscription.repo.ts @@ -113,17 +113,6 @@ export const upsertByPartnerLicenseKey = async ( referenceId?: string; }, ) => { - const existing = await getByPartnerLicenseKey(db, partnerLicenseKey); - - if (existing) { - const [result] = await db - .update(subscription) - .set({ ...data, updatedAt: new Date() }) - .where(eq(subscription.partnerLicenseKey, partnerLicenseKey)) - .returning(); - return result; - } - const [result] = await db .insert(subscription) .values({ @@ -131,6 +120,10 @@ export const upsertByPartnerLicenseKey = async ( ...data, referenceId: data.referenceId ?? null, }) + .onConflictDoUpdate({ + target: subscription.partnerLicenseKey, + set: { ...data, updatedAt: new Date() }, + }) .returning(); return result; };