Просмотр исходного кода

[web] Fix Stripe Subscription ID being saved to wrong field in admin panel (#34157)

* [web] Fix Stripe Subscription ID being saved to wrong field in admin panel

* add migration for unsetting recurlySubscription_id

GitOrigin-RevId: ccae470897690a8cdc8a8bce883983808a963d24
Simon Gardner 2 месяцев назад
Родитель
Сommit
20f03d75fe

+ 26 - 0
tools/migrations/20260601160305_unset_stripe_subscription_id_from_recurly_field.mjs

@@ -0,0 +1,26 @@
+import { db } from './lib/mongodb.mjs'
+
+const tags = ['saas']
+
+const migrate = async () => {
+  const result = await db.subscriptions.updateMany(
+    {
+      recurlySubscription_id: /^sub_/,
+      $expr: {
+        $eq: ['$recurlySubscription_id', '$paymentProvider.subscriptionId'],
+      },
+    },
+    { $unset: { recurlySubscription_id: '' } }
+  )
+  console.log(
+    `Updated ${result.modifiedCount} subscriptions (matched ${result.matchedCount}).`
+  )
+}
+
+const rollback = async () => {}
+
+export default {
+  tags,
+  migrate,
+  rollback,
+}