This commit is contained in:
shafi54 2026-10-25 19:38:18 +05:30
parent 612728761d
commit 2d73068f7b
10 changed files with 235 additions and 36 deletions

View file

@ -0,0 +1,83 @@
-- ============================================================
-- delete-orders-before-2026-02-10.sql
--
-- DESTRUCTIVE. Deletes every order created before 2026-02-10 (midnight,
-- exclusive -- anything on/after 2026-02-10 00:00 is kept) and the rows that
-- hang off those orders.
--
-- Cutoff: `created_at < '2026-02-10'` compares correctly for the timestamp
-- shapes the app writes ('2026-02-09T23:00:00.000Z' and '2026-02-09 23:00:00').
--
-- Schema: this targets the post-0006 database (applied to the remote now).
-- 0006 removed online payments, so `payments`, `refunds` and `payment_info` no
-- longer exist and `orders.payment_info_id` is gone -- none are referenced here.
-- (The same statements also run on a pre-0006 copy; they just leave the dropped
-- payment tables alone.)
--
-- Per order it:
-- 1. detaches coupon_usage / complaints / user_incidents (rows kept, order
-- references set to NULL, so coupon limits and complaint history survive)
-- 2. deletes its order_items and order_status rows
-- 3. deletes the order
--
-- Post-0006 orders whose items were archived into `orders.items_json` have no
-- `order_items` rows, so only the order/status row is removed for them.
--
-- Counts from the local dump at time of writing (pre-0006 copy):
-- 110 of 2548 orders (oldest 2025-12-24), 194 order_items, 110 order_status,
-- 23 coupon_usage detached, 1 complaint detached, 0 user_incidents.
-- Counts will differ on the target database.
--
-- Apply from apps/backend:
-- wrangler d1 execute freshyo-backend-dev --file=../../address_util/delete-orders-before-2026-02-10.sql --config wrangler.dev.toml --remote
--
-- Dry run (counts only):
-- SELECT COUNT(*) FROM orders WHERE created_at < '2026-02-10';
-- ============================================================
-- 1. Preserve cross-cutting history; drop only the order references.
UPDATE coupon_usage
SET order_id = NULL,
order_item_id = NULL
WHERE order_id IN (SELECT id FROM orders WHERE created_at < '2026-02-10')
OR order_item_id IN (
SELECT oi.id FROM order_items oi
JOIN orders o ON o.id = oi.order_id
WHERE o.created_at < '2026-02-10'
);
UPDATE complaints
SET order_id = NULL
WHERE order_id IN (SELECT id FROM orders WHERE created_at < '2026-02-10');
UPDATE user_incidents
SET order_id = NULL
WHERE order_id IN (SELECT id FROM orders WHERE created_at < '2026-02-10');
-- 2. Delete the order-owned item/status rows.
DELETE FROM order_items
WHERE order_id IN (SELECT id FROM orders WHERE created_at < '2026-02-10');
DELETE FROM order_status
WHERE order_id IN (SELECT id FROM orders WHERE created_at < '2026-02-10');
-- 3. Delete the orders themselves.
DELETE FROM orders
WHERE created_at < '2026-02-10';
-- Verification (run after applying):
-- SELECT COUNT(*) FROM orders WHERE created_at < '2026-02-10'; -- expect 0
-- SELECT COUNT(*) FROM order_items
-- WHERE order_id NOT IN (SELECT id FROM orders); -- expect 0
-- SELECT COUNT(*) FROM order_status
-- WHERE order_id NOT IN (SELECT id FROM orders); -- expect 0
-- SELECT COUNT(*) FROM coupon_usage
-- WHERE order_id IS NOT NULL
-- AND order_id NOT IN (SELECT id FROM orders); -- expect 0
-- SELECT COUNT(*) FROM complaints
-- WHERE order_id IS NOT NULL
-- AND order_id NOT IN (SELECT id FROM orders); -- expect 0
-- SELECT COUNT(*) FROM user_incidents
-- WHERE order_id IS NOT NULL
-- AND order_id NOT IN (SELECT id FROM orders); -- expect 0
-- PRAGMA foreign_key_check; -- expect no rows

View file

@ -7,16 +7,16 @@
cd apps/backend
# 1. Admin coords (idempotent)
wrangler d1 execute freshyo-backend-dev --file=../../address_util/backfill-admin-coords.sql --config wrangler.dev.toml --remote
wrangler d1 execute freshyo-dev --file=../../address_util/backfill-admin-coords.sql --config wrangler.prod.toml --remote
# 2. Computed bounds for the 466 non-vague addresses
wrangler d1 execute freshyo-backend-dev --file=../../address_util/computed-bounds-466.sql --config wrangler.dev.toml --remote
wrangler d1 execute freshyo-dev --file=../../address_util/computed-bounds-466.sql --config wrangler.prod.toml --remote
# 3. Manual bounds + coords for the 416 vague addresses
wrangler d1 execute freshyo-backend-dev --file=../../address_util/address-bound-coord-updates.sql --config wrangler.dev.toml --remote
wrangler d1 execute freshyo-dev --file=../../address_util/address-bound-coord-updates.sql --config wrangler.prod.toml --remote
# 4. Delete the 23 selected addresses (run last)
wrangler d1 execute freshyo-backend-dev --file=../../address_util/delete-outside-bound-addresses.sql --config wrangler.dev.toml --remote
wrangler d1 execute freshyo-dev --file=../../address_util/delete-outside-bound-addresses.sql --config wrangler.prod.toml --remote
# Optional verification
wrangler d1 execute freshyo-backend-dev --config wrangler.dev.toml --command="SELECT bound_id, COUNT(*) AS n FROM addresses GROUP BY bound_id ORDER BY bound_id" --remote

View file

@ -593,7 +593,7 @@ Covered comprehensively by section 4 (CACHE-01..24); add procedure-level cases:
| ID | Type | Case | Assert |
| --- | --- | --- | --- |
| COMMON-74 | edge | missing `boundId` input | BAD_REQUEST |
| COMMON-74 | edge | missing `boundId` input (legacy no-arg call) | falls back to bound 1 / region 1 |
| COMMON-75 | edge | boundId 0/negative/float | BAD_REQUEST |
| COMMON-76 | edge | no token | succeeds |
| COMMON-77 | edge | response shape flat (no nesting) | all keys at root |
@ -1945,7 +1945,8 @@ These are intentionally written as “current” cases until the underlying defe
14. Cache rebuilds are non-atomic and eventual; every cache test must poll, never sleep once.
15. `cacheVersion`/`slotsVersionNum`/`availabilityVersionNum` are old names; use
`products_version_num`/`slots_version_num`/`availability_version_num`.
16. `common.essentialConsts` requires `boundId`; the old suite’s no-arg call no longer compiles.
16. `common.essentialConsts` accepts an optional `boundId`; a missing input is a temporary
backwards-compatibility path that falls back to bound 1 (region 1).
---

View file

@ -2914,7 +2914,7 @@ INSERT INTO "key_val_store" ("key","value") VALUES('deliveryCharge','15');
INSERT INTO "key_val_store" ("key","value") VALUES('flashDeliveryCharge','39.0');
INSERT INTO "key_val_store" ("key","value") VALUES('flashFreeDeliveryThreshold','399');
INSERT INTO "key_val_store" ("key","value") VALUES('freeDeliveryThreshold','249');
INSERT INTO "key_val_store" ("key","value") VALUES('isFlashDeliveryEnabled','true');
INSERT INTO "key_val_store" ("key","value") VALUES('isFlashDeliveryEnabled','false');
INSERT INTO "key_val_store" ("key","value") VALUES('minRegularOrderValue','249');
INSERT INTO "key_val_store" ("key","value") VALUES('playStoreUrl','https://info.freshyo.in/qr-based-download');
INSERT INTO "key_val_store" ("key","value") VALUES('popularItems','40,109,9,75,98,6,24,59');
@ -2949,7 +2949,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(24,'ExponentPushToken[B2zWnHNaumIgbeFFKO-15D]','2026-02-09T19:53:37.594Z',113,'2026-02-10T07:43:48.632Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(25,'ExponentPushToken[wIhrdlAmwj0Eytvz3W3TTZ]','2026-02-10T11:09:24.848Z',127,'2026-04-18T06:53:49.329Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(26,'ExponentPushToken[hFUlPFOKMdAUgtDP7EtSzM]','2026-02-10T11:33:43.821Z',3,'2026-02-24T11:16:46.799Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(27,'ExponentPushToken[NymZTEED3G7YCyDg7ihgBA]','2026-02-11T03:16:04.540Z',2,'2026-10-25T03:19:14.196Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(27,'ExponentPushToken[NymZTEED3G7YCyDg7ihgBA]','2026-02-11T03:16:04.540Z',2,'2026-10-25T12:56:35.446Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(28,'ExponentPushToken[ARCT4KD7CJ_pFF_GkywepP]','2026-02-11T11:34:32.238Z',115,'2026-10-17T09:44:00.809Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(29,'ExponentPushToken[NN4v16BFslBX8ryVXDwQIg]','2026-02-12T08:46:42.421Z',128,'2026-02-17T19:04:12.936Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(30,'ExponentPushToken[qbteKBC1wbLMCe1ltpul7u]','2026-02-12T13:28:00.376Z',129,'2026-02-12T13:28:00.375Z');
@ -3270,7 +3270,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(377,'ExponentPushToken[OUHHZDAcdmpUwkHVo6sX1T]','2026-05-11 09:43:23',437,'2026-08-01T15:49:31.050Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(378,'ExponentPushToken[6GIZ9PGsRkWk9Vd4XtVoP0]','2026-05-12 04:54:49',438,'2026-05-12T05:41:19.561Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(379,'ExponentPushToken[VY1lpUFK2Fw6V6aJ5LokIt]','2026-05-12 06:03:32',439,'2026-06-10T04:33:08.668Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(380,'ExponentPushToken[GA8vDtGZGSLyXTIw8p73Z2]','2026-05-12 07:14:36',440,'2026-10-20T07:31:50.339Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(380,'ExponentPushToken[GA8vDtGZGSLyXTIw8p73Z2]','2026-05-12 07:14:36',440,'2026-10-25T11:11:07.903Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(381,'ExponentPushToken[nTI6kIOJyQjAEsl9kLdguv]','2026-05-12 08:40:29',441,'2026-05-15T17:29:56.071Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(382,'ExponentPushToken[BwD4IWC1zCruWA2ZZcRZ9n]','2026-05-13 02:12:47',444,'2026-10-13T05:27:00.418Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(383,'ExponentPushToken[89CRhTI7hACC4Z7qHwx0Ol]','2026-05-13 04:22:12',96,'2026-05-13T04:22:12.371Z');
@ -3370,7 +3370,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(477,'ExponentPushToken[xW60lBF5T8QZhcukLKWiLT]','2026-06-13 06:50:53',539,'2026-06-13T06:50:53.542Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(478,'ExponentPushToken[OcXxPHN4S6jSOcfUst66iz]','2026-06-13 13:05:48',541,'2026-06-13T13:05:47.880Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(479,'ExponentPushToken[MDMAekEhhWndpo2uBAD9Aa]','2026-06-14 08:02:34',542,'2026-06-14T08:02:34.279Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(480,'ExponentPushToken[-mWZEMNqDOXZj9ESRGhRuA]','2026-06-15 12:02:30',414,'2026-10-21T08:49:02.351Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(480,'ExponentPushToken[-mWZEMNqDOXZj9ESRGhRuA]','2026-06-15 12:02:30',414,'2026-10-25T09:29:14.781Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(481,'ExponentPushToken[C36i1zA_O5lmgPSe0H6GCS]','2026-06-17 06:17:53',544,'2026-09-06T15:30:50.969Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(482,'ExponentPushToken[Kl7RrWOFizANCgLbHBZDTO]','2026-06-17 11:56:17',545,'2026-06-21T08:01:57.256Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(483,'ExponentPushToken[3R26bUHCHaUtIoOnHLVbTX]','2026-06-17 13:50:26',121,'2026-06-17T13:53:22.079Z');
@ -3568,7 +3568,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(675,'ExponentPushToken[y9yrBKHPbgGnun6nnc5i1B]','2026-08-14 13:27:22',742,'2026-08-14T15:44:49.270Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(676,'ExponentPushToken[oQElZlIz-BmfNNc5K5d064]','2026-08-15 05:33:31',744,'2026-08-16T05:24:08.729Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(677,'ExponentPushToken[6Xwr72LnxNHJytsy7Cs5at]','2026-08-15 06:00:14',745,'2026-09-25T05:46:59.699Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(678,'ExponentPushToken[4I1Ye1NW8ORECiWtNz3qOn]','2026-08-15 08:37:53',747,'2026-10-18T07:18:12.838Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(678,'ExponentPushToken[4I1Ye1NW8ORECiWtNz3qOn]','2026-08-15 08:37:53',747,'2026-10-25T07:20:48.182Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(679,'ExponentPushToken[yuHQyvGAG_dBwAWTTQmKUA]','2026-08-15 11:54:37',282,'2026-08-15T11:54:37.722Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(680,'ExponentPushToken[MgtQoXCibg773i-imr3I8M]','2026-08-15 12:48:50',749,'2026-10-15T01:34:29.548Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(681,'ExponentPushToken[lcPixFOTlC_8ut1jmkvGcf]','2026-08-16 03:48:16',750,'2026-10-25T04:04:16.469Z');
@ -3975,7 +3975,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1085,'ExponentPushToken[WNFDt7O_XwLLi9o4Kzkxh1]','2026-09-16 17:05:05',1141,'2026-09-16T17:05:05.695Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1086,'ExponentPushToken[iy4keVDskW3UeguQ98IC18]','2026-09-16 18:28:01',1185,'2026-10-24T05:17:12.615Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1087,'ExponentPushToken[ztKEwrJShQuweUycnFsIEf]','2026-09-17 01:31:58',1186,'2026-09-17T01:57:18.495Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1088,'ExponentPushToken[sAd4YtJL7eNiyZYFLQ9RIS]','2026-09-17 03:54:31',1187,'2026-10-23T15:31:06.766Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1088,'ExponentPushToken[sAd4YtJL7eNiyZYFLQ9RIS]','2026-09-17 03:54:31',1187,'2026-10-25T09:01:57.753Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1089,'ExponentPushToken[LfAPs1IUnZSrW11L2P6Ljq]','2026-09-17 07:32:13',1188,'2026-10-21T06:43:54.928Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1090,'ExponentPushToken[FRvK5qOdOnOM3J_ewfgEVy]','2026-09-17 07:55:21',1078,'2026-10-24T14:25:40.537Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1091,'ExponentPushToken[QqPqRuL-HlsUOJkxoPiPCX]','2026-09-17 09:16:46',1011,'2026-09-17T11:40:10.585Z');
@ -4027,7 +4027,7 @@ INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VA
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1137,'ExponentPushToken[4nko9iNLxcniPOe9_HVD_L]','2026-09-23 19:46:36',1240,'2026-10-18T11:54:25.649Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1138,'ExponentPushToken[ROzLrXEV42b3SoLOlH1pTa]','2026-09-24 07:22:00',1242,'2026-09-24T07:22:00.760Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1139,'ExponentPushToken[m_CWoiJlWlpI5RBLEJLmyE]','2026-09-24 08:35:22',350,'2026-10-10T08:47:26.932Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1140,'ExponentPushToken[wF1z8fDeSMGHlPRBbETioe]','2026-09-24 09:29:15',1243,'2026-10-21T17:55:33.656Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1140,'ExponentPushToken[wF1z8fDeSMGHlPRBbETioe]','2026-09-24 09:29:15',1243,'2026-10-25T08:49:18.058Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1141,'ExponentPushToken[5CzesiC5I-3Qs5F0jCYAnS]','2026-09-24 12:43:25',776,'2026-09-24T12:43:25.667Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1142,'ExponentPushToken[CGgtzRDOVD5HEIxnDjnWzt]','2026-09-24 13:12:45',1245,'2026-09-24T13:19:02.736Z');
INSERT INTO "notif_creds" ("id","token","added_at","user_id","last_verified") VALUES(1143,'ExponentPushToken[8RCScPBEYU-s_L8TiYNsOE]','2026-09-24 13:55:59',1246,'2026-10-08T02:37:33.996Z');
@ -6683,9 +6683,9 @@ INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged"
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2702,'2026-10-25 04:10:05',1085,2708,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2703,'2026-10-25 04:11:39',493,2709,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2704,'2026-10-25 04:28:34',688,2710,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2705,'2026-10-25 04:33:49',82,2711,0,0,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2706,'2026-10-25 05:46:20',523,2712,0,0,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2707,'2026-10-25 06:24:32',1351,2713,0,0,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2705,'2026-10-25 04:33:49',82,2711,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2706,'2026-10-25 05:46:20',523,2712,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
INSERT INTO "order_status" ("id","order_time","user_id","order_id","is_packaged","is_delivered","is_cancelled","cancel_reason","payment_state","cancellation_user_notes","cancellation_admin_notes","cancellation_reviewed","cancellation_reviewed_at","refund_coupon_id","is_cancelled_by_admin") VALUES(2707,'2026-10-25 06:24:32',1351,2713,1,1,0,NULL,'cod',NULL,NULL,0,NULL,NULL,NULL);
CREATE TABLE IF NOT EXISTS "orders" ("id" INTEGER PRIMARY KEY, "user_id" INTEGER NOT NULL, "address_id" INTEGER NOT NULL, "slot_id" INTEGER, "total_amount" REAL NOT NULL, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "is_cod" INTEGER NOT NULL DEFAULT false, "is_online_payment" INTEGER NOT NULL DEFAULT false, "payment_info_id" INTEGER, "readable_id" INTEGER NOT NULL, "admin_notes" TEXT, "user_notes" TEXT, "delivery_charge" REAL NOT NULL DEFAULT '0', "order_group_id" TEXT, "order_group_proportion" REAL, "is_flash_delivery" INTEGER NOT NULL DEFAULT false, `delivered_at` text);
INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(105,22,31,9,7700,'2025-12-24T02:50:33.284Z',1,0,NULL,147,NULL,NULL,0,NULL,NULL,0,NULL);
INSERT INTO "orders" ("id","user_id","address_id","slot_id","total_amount","created_at","is_cod","is_online_payment","payment_info_id","readable_id","admin_notes","user_notes","delivery_charge","order_group_id","order_group_proportion","is_flash_delivery","delivered_at") VALUES(106,15,24,8,92,'2025-12-24T10:32:01.957Z',1,0,NULL,149,NULL,NULL,20,NULL,NULL,0,NULL);
@ -11409,7 +11409,7 @@ INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VAL
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1642,'ExponentPushToken[-KFqDsP-HC2Q-0s6Fc-Ipy]','2026-09-11 16:03:37','2026-09-15T14:32:12.599Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1645,'ExponentPushToken[dg-_wDCEwufWZx4CxFHRTG]','2026-09-11 16:05:59','2026-10-06T09:28:09.270Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1648,'ExponentPushToken[aS9CGuNtZQ6afSDXwTdbaU]','2026-09-11 16:07:09','2026-09-30T15:24:44.752Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1649,'ExponentPushToken[7K3X1gK_zFoLS7Wm3p9Hhl]','2026-09-11 16:07:41','2026-10-19T01:24:21.869Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1649,'ExponentPushToken[7K3X1gK_zFoLS7Wm3p9Hhl]','2026-09-11 16:07:41','2026-10-25T09:04:30.128Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1651,'ExponentPushToken[0wZ4INHRS_gGL4hTsgJ7C-]','2026-09-11 16:08:52','2026-09-11T16:08:52.838Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1652,'ExponentPushToken[RpD1OGLWPTJ36Lb_KCAlFa]','2026-09-11 16:08:59','2026-09-13T18:31:08.061Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(1653,'ExponentPushToken[02oH-mMJZFldfXVfqxOPE6]','2026-09-11 16:11:23','2026-09-14T06:17:42.788Z');
@ -11954,7 +11954,7 @@ INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VAL
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2353,'ExponentPushToken[aITcTXM3kUTvLkCku51RVY]','2026-10-13 01:09:38','2026-10-13T01:09:38.688Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2354,'ExponentPushToken[oVlx4lOzXHflUavRWxGcH4]','2026-10-14 01:27:54','2026-10-14T01:27:54.416Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2356,'ExponentPushToken[fx_Z4hJDBIhccI36Sd-7ZV]','2026-10-14 05:48:40','2026-10-20T12:35:06.658Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2357,'ExponentPushToken[uN7Q2SJXcDEsKhYeb2PeVF]','2026-10-14 11:33:41','2026-10-24T07:24:10.154Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2357,'ExponentPushToken[uN7Q2SJXcDEsKhYeb2PeVF]','2026-10-14 11:33:41','2026-10-25T07:30:22.335Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2358,'ExponentPushToken[T6VyuGAkKtOnyMGSwa1XuM]','2026-10-14 11:55:18','2026-10-23T06:21:10.776Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2359,'ExponentPushToken[d75jOiFseYEe8N39v2XSV-]','2026-10-14 13:44:19','2026-10-14T13:44:19.755Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2360,'ExponentPushToken[lig2boHMSviJFdVsR3j86H]','2026-10-14 16:28:32','2026-10-14T16:28:32.826Z');
@ -12003,6 +12003,8 @@ INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VAL
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2410,'ExponentPushToken[hWm-eGPbpHPjZaZ57hgsmC]','2026-10-24 13:32:58','2026-10-24T15:49:57.067Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2411,'ExponentPushToken[Kd6H6PA84cbHP1ixcjt8JU]','2026-10-24 19:15:04','2026-10-24T19:25:57.389Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2412,'ExponentPushToken[d6lbVHISTzXujRK8QTQUAY]','2026-10-25 01:18:56','2026-10-25T01:18:56.039Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2413,'ExponentPushToken[pfqXpQBHFC-S20jwotBFnN]','2026-10-25 06:39:13','2026-10-25T06:39:13.035Z');
INSERT INTO "unlogged_user_tokens" ("id","token","added_at","last_verified") VALUES(2414,'ExponentPushToken[q-Lmz6DuN8mvoHTG1u9odS]','2026-10-25 07:42:50','2026-10-25T07:42:50.356Z');
CREATE TABLE IF NOT EXISTS "upload_url_status" ("id" INTEGER PRIMARY KEY, "created_at" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, "key" TEXT NOT NULL, "status" TEXT NOT NULL DEFAULT 'pending');
INSERT INTO "upload_url_status" ("id","created_at","key","status") VALUES(35,'2025-12-07T08:58:13.136Z','review-images/1765097892914.jpg','pending');
INSERT INTO "upload_url_status" ("id","created_at","key","status") VALUES(36,'2025-12-07T08:58:13.347Z','review-images/1765097893129.png','pending');
@ -23279,12 +23281,12 @@ INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discount
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9125,2708,98,'1','449','449',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9126,2709,14,'1','449','449',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9127,2710,137,'1','305','305',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9128,2711,10,'2','299','299',0,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9129,2712,40,'2','153','153',0,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9130,2713,33,'2','15.0','15.0',0,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9131,2713,71,'1','15.0','15.0',0,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9132,2713,6,'1','109.0','109.0',0,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9133,2713,31,'2','16','16',0,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9128,2711,10,'2','299','299',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9129,2712,40,'2','153','153',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9130,2713,33,'2','15.0','15.0',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9131,2713,71,'1','15.0','15.0',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9132,2713,6,'1','109.0','109.0',1,0,NULL);
INSERT INTO "order_items" ("id","order_id","sku_id","quantity","price","discounted_price","is_packaged","is_package_verified","packaged_at") VALUES(9133,2713,31,'2','16','16',1,0,NULL);
CREATE TABLE IF NOT EXISTS "special_deals" (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`sku_id` integer NOT NULL,
@ -23724,7 +23726,7 @@ CREATE TABLE `staff_notif_creds` (
);
INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(1,'ExponentPushToken[HyU1kPNunSJaasQweODhvH]','2026-10-02 10:49:17',6,'2026-10-04T07:19:37.555Z');
INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(2,'ExponentPushToken[QydqxGMsUfzHuiqxel0nA9]','2026-10-02 10:49:27',4,'2026-10-20T07:30:34.519Z');
INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(3,'ExponentPushToken[bqqW02IeK4XcC4iuzpkQIG]','2026-10-05 01:28:42',4,'2026-10-25T05:50:41.894Z');
INSERT INTO "staff_notif_creds" ("id","token","added_at","staff_user_id","last_verified") VALUES(3,'ExponentPushToken[bqqW02IeK4XcC4iuzpkQIG]','2026-10-05 01:28:42',4,'2026-10-25T13:27:06.541Z');
DELETE FROM sqlite_sequence;
INSERT INTO "sqlite_sequence" ("name","seq") VALUES('product_skus',150);
INSERT INTO "sqlite_sequence" ("name","seq") VALUES('sku_features',183);

View file

@ -262,9 +262,14 @@ export const commonApiRouter = router({
}),
essentialConsts: publicProcedure
.input(z.object({ boundId: z.number().int().positive() }))
// TEMPORARY (backwards compatibility): older app builds call this procedure
// with no input. Every field is optional now; a missing bound falls back to
// bound 1 (region 1, Mahabubnagar). Remove this block once no shipped build
// relies on it.
.input(z.object({ boundId: z.number().int().positive().optional() }).optional())
.query(async ({ ctx, input }) => {
console.log({ boundId: input.boundId })
const boundId = input?.boundId ?? 1
console.log({ boundId })
const requestUrl = ctx.req.url
const host = new URL(requestUrl).host
const updateNotice = `<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
@ -272,7 +277,7 @@ export const commonApiRouter = router({
<h1 style="font-size: 36px; margin-top: 48px">With love, from Freshyo</h5>
</div>`
const response = await readEssentialConstsFromKv(input.boundId);
const response = await readEssentialConstsFromKv(boundId);
const shouldShowNotice = host.includes('raw') || host.includes('mf')
console.log('essentialConsts request', { host, url: requestUrl, ...response })

View file

@ -281,6 +281,16 @@ describe('common.essentialConsts resolution (CACHE-12..14)', () => {
})
})
describe('common.essentialConsts backwards compatibility (CACHE-25)', () => {
it('CACHE-25: no input falls back to bound 1 in region 1', async () => {
const { anonClient } = await import('../helpers/sessions')
const consts = await anonClient().common.essentialConsts.query()
expect(consts.boundId).toBe(1)
expect(consts.regionId).toBe(1)
})
})
describe('common.essentialConsts KV mirror (CACHE-15..16)', () => {
it('(current) CACHE-15: a KV miss is not forceable; the payload is complete and stable', async () => {
// Every const-write path rebuilds the mirror before returning and a fresh

View file

@ -8,10 +8,10 @@ routes = [
[[d1_databases]]
binding = "DB"
database_name = "freshyo-backend-dev"
database_id = "b2528bdb-0ec0-478e-8765-b118918153c0"
#database_name = "freshyo-dev"
#database_id = "3cad440f-dc14-4baa-ab05-04eb08e206de"
#database_name = "freshyo-backend-dev"
#database_id = "b2528bdb-0ec0-478e-8765-b118918153c0"
database_name = "freshyo-dev"
database_id = "3cad440f-dc14-4baa-ab05-04eb08e206de"
migrations_dir="../../packages/db_helper_sqlite/drizzle"
migrations_pattern="migration.sql"
[durable_objects]

View file

@ -7,10 +7,10 @@ const constants = {
// Web app used inside the app for the map-based address picker
// (web-ui /location-selector route). Replace with the live URL later.
// WEB_UI_BASE_URL: 'https://localuserweb.freshyo.in',
WEB_UI_BASE_URL: 'https://devwebui.freshyo.in',
WEB_UI_BASE_URL: 'https://www.freshyo.in',
// Bump this on every release. When it is lower than the backend's
// `internalAppVersion` constant, UpdateChecker prompts the user to restart.
INTERNAL_APP_VERSION: 2,
INTERNAL_APP_VERSION: 3,
}
export default constants;

View file

@ -10137,3 +10137,101 @@ handleSubmit and MyButton disabled.
--- apps/user-ui/JEST-TEST-CASES.md
Catalogue rows ADDRF-40/41 added.
[2026-10-25 19:10 IST] `common.essentialConsts`: made the input optional for backwards
compatibility, defaulting to bound 1 (region 1, Mahabubnagar).
--- apps/backend/src/trpc/apis/common-apis/common-trpc-index.ts
@@
essentialConsts: publicProcedure
- .input(z.object({ boundId: z.number().int().positive() }))
+ // TEMPORARY (backwards compatibility): older app builds call this procedure
+ // with no input. Every field is optional now; a missing bound falls back to
+ // bound 1 (region 1, Mahabubnagar). Remove this block once no shipped build
+ // relies on it.
+ .input(z.object({ boundId: z.number().int().positive().optional() }).optional())
.query(async ({ ctx, input }) => {
- console.log({ boundId: input.boundId })
+ const boundId = input?.boundId ?? 1
+ console.log({ boundId })
@@
- const response = await readEssentialConstsFromKv(input.boundId);
+ const response = await readEssentialConstsFromKv(boundId);
--- apps/backend/tests/api/cache-consts.test.ts
Added CACHE-25: calling common.essentialConsts with no input returns bound 1 (region 1).
Also updated `apps/backend/API-TEST-CASES.md`: COMMON-74 now documents the bound-1 fallback
for a missing input, and the known-issue note no longer says boundId is required.
Typecheck: backend src + tests clean.
[2026-10-25 19:33 IST] Added `address_util/delete-orders-before-2026-02-10.sql`.
Wipes every order whose `orders.created_at` is before 2026-02-10 (cutoff exclusive, works for the
ISO text timestamps the app writes) and removes its dependents:
- deletes order_items, order_status, payments, refunds
- detaches coupon_usage / complaints / user_incidents (order_id and order_item_id set to NULL,
rows kept so coupon-limit and complaint history survive)
- clears orders.payment_info_id for the doomed orders before deleting them (legacy FK), then
deletes the orders
- payment_info is left untouched (its `order_id` column is never populated and no current order
references it), noted in the file header
Local copy at time of writing: 110 of 2548 orders (min 2025-12-24), 194 order_items, 110
order_status, 0 payments, 28 refunds, 23 coupon_usage (detached), 1 complaint (detached),
0 user_incidents.
Apply from apps/backend:
wrangler d1 execute freshyo-backend-dev --file=../../address_util/delete-orders-before-2026-02-10.sql --config wrangler.dev.toml --remote
Validated `delete-orders-before-2026-02-10.sql` on a throwaway copy of the local D1:
orders 2548 -> 2438 (-110), order_items 8884 -> 8690 (-194), order_status 2542 -> 2432 (-110),
refunds 249 -> 221 (-28), coupon_usage 124 (23 detached, kept), complaints 102 (1 detached,
kept), payments 11 (none belonged to the old orders). New oldest order: 2026-02-10T11:34:04.471Z.
No orphan rows in any dependent table; PRAGMA foreign_key_check clean.
[2026-10-25 19:52 IST] Fixed `address_util/delete-orders-before-2026-02-10.sql` for the post-0006
(COD-only) schema: it failed with `no such table: payments` because 0006 drops `payments`,
`refunds` and `payment_info` and removes `orders.payment_info_id`.
--- address_util/delete-orders-before-2026-02-10.sql
@@
--- 3. deletes its payments and refunds rows
--- 4. clears orders.payment_info_id (legacy link) and deletes the order
---
--- `payment_info` rows are intentionally NOT deleted: `payment_info.order_id` is
--- never populated and the only link is `orders.payment_info_id`, which is
--- cleared above. Current data has no linked rows; delete manually if needed.
+-- 3. deletes the order
+--
+-- The post-0006 schema has no `payments` / `refunds` / `payment_info` tables and
+-- no `orders.payment_info_id` (online payments were removed; COD only), so the
+-- script does not reference them. It still works on a pre-0006 copy.
@@
-DELETE FROM payments
-WHERE order_id IN (SELECT id FROM orders WHERE created_at < '2026-02-10');
-
-DELETE FROM refunds
-WHERE order_id IN (SELECT id FROM orders WHERE created_at < '2026-02-10');
-
--- 4. Break the legacy payment_info link so the FK cannot block the delete.
-UPDATE orders
-SET payment_info_id = NULL
-WHERE created_at < '2026-02-10'
- AND payment_info_id IS NOT NULL;
-
--- 5. Delete the orders themselves.
+-- 4. Delete the orders themselves.
DELETE FROM orders
WHERE created_at < '2026-02-10';
@@
--- SELECT COUNT(*) FROM payments
--- WHERE order_id NOT IN (SELECT id FROM orders); -- expect 0
--- SELECT COUNT(*) FROM refunds
--- WHERE order_id NOT IN (SELECT id FROM orders); -- expect 0
Also updated the header counts note (pre-0006 dump had 28 refunds; that table no longer exists)
and reworded the dry run.
Re-validated the fixed file two ways:
1. Post-0006-shaped schema (FKs enforced) in a scratch DB: orders on 2026-02-09 and earlier are
removed, 2026-02-10 00:00 is kept, old coupon_usage/complaints/user_incidents rows survive with
NULL order refs, FK check clean.
2. Pre-0006 local dump copy: orders 2548 -> 2438 (-110), no orphan rows, FK check clean.

View file

@ -5,8 +5,8 @@ export * from './region-cache-urls'
* Base origin of the backend API, shared by every UI (React Native and web).
* Framework-agnostic: apps may override it (e.g. VITE_API_URL) at build time.
*/
// export const BASE_API_URL = 'https://worker.freshyo.in'
export const BASE_API_URL = 'https://devapi.freshyo.in'
export const BASE_API_URL = 'https://worker.freshyo.in'
// export const BASE_API_URL = 'https://devapi.freshyo.in'
// export const BASE_API_URL = 'https://devbackend.freshyo.in'
// export const BASE_API_URL = 'https://192.168.100.126.nip.io:8787'
// export const BASE_API_URL = 'http://192.168.1.5:8787'