瀏覽代碼

[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 月之前
父節點
當前提交
20f03d75fe
共有 1 個文件被更改,包括 26 次插入0 次删除
  1. 26 0
      tools/migrations/20260601160305_unset_stripe_subscription_id_from_recurly_field.mjs

+ 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,
+}