@@ -4,17 +4,20 @@ import { StatusCodes } from "http-status-codes";
44import { TransactionDB } from "../../../shared/db/transactions/db" ;
55import { standardResponseSchema } from "../../schemas/shared-api-schemas" ;
66
7- const requestBodySchema = Type . Object ( {
7+ const loadRequestBodySchema = Type . Object ( {
88 entries : Type . Array (
99 Type . Object ( {
1010 queueId : Type . String ( { description : "Queue ID (UUID)" } ) ,
1111 transactionHash : Type . String ( { description : "Transaction hash (0x...)" } ) ,
1212 } ) ,
13- { description : "Array of queueId to transactionHash mappings" , maxItems : 10000 } ,
13+ {
14+ description : "Array of queueId to transactionHash mappings" ,
15+ maxItems : 10000 ,
16+ } ,
1417 ) ,
1518} ) ;
1619
17- const responseBodySchema = Type . Object ( {
20+ const loadResponseBodySchema = Type . Object ( {
1821 result : Type . Object ( {
1922 inserted : Type . Integer ( { description : "Number of entries inserted" } ) ,
2023 skipped : Type . Integer ( {
@@ -23,10 +26,16 @@ const responseBodySchema = Type.Object({
2326 } ) ,
2427} ) ;
2528
29+ const clearResponseBodySchema = Type . Object ( {
30+ result : Type . Object ( {
31+ deleted : Type . Integer ( { description : "Number of entries deleted" } ) ,
32+ } ) ,
33+ } ) ;
34+
2635export async function loadBackfillRoute ( fastify : FastifyInstance ) {
2736 fastify . route < {
28- Body : Static < typeof requestBodySchema > ;
29- Reply : Static < typeof responseBodySchema > ;
37+ Body : Static < typeof loadRequestBodySchema > ;
38+ Reply : Static < typeof loadResponseBodySchema > ;
3039 } > ( {
3140 method : "POST" ,
3241 url : "/admin/backfill" ,
@@ -36,10 +45,10 @@ export async function loadBackfillRoute(fastify: FastifyInstance) {
3645 "Load queueId to transactionHash mappings into the backfill table. Uses SETNX to never overwrite existing entries." ,
3746 tags : [ "Admin" ] ,
3847 operationId : "loadBackfill" ,
39- body : requestBodySchema ,
48+ body : loadRequestBodySchema ,
4049 response : {
4150 ...standardResponseSchema ,
42- [ StatusCodes . OK ] : responseBodySchema ,
51+ [ StatusCodes . OK ] : loadResponseBodySchema ,
4352 } ,
4453 hide : true ,
4554 } ,
@@ -55,3 +64,31 @@ export async function loadBackfillRoute(fastify: FastifyInstance) {
5564 } ,
5665 } ) ;
5766}
67+
68+ export async function clearBackfillRoute ( fastify : FastifyInstance ) {
69+ fastify . route < {
70+ Reply : Static < typeof clearResponseBodySchema > ;
71+ } > ( {
72+ method : "DELETE" ,
73+ url : "/admin/backfill" ,
74+ schema : {
75+ summary : "Clear backfill table" ,
76+ description :
77+ "Delete all entries from the backfill table. This action cannot be undone." ,
78+ tags : [ "Admin" ] ,
79+ operationId : "clearBackfill" ,
80+ response : {
81+ ...standardResponseSchema ,
82+ [ StatusCodes . OK ] : clearResponseBodySchema ,
83+ } ,
84+ hide : true ,
85+ } ,
86+ handler : async ( _request , reply ) => {
87+ const deleted = await TransactionDB . clearBackfill ( ) ;
88+
89+ reply . status ( StatusCodes . OK ) . send ( {
90+ result : { deleted } ,
91+ } ) ;
92+ } ,
93+ } ) ;
94+ }
0 commit comments