From 9459fdecdf4ab7ed95015f93ded83d1ac809b464 Mon Sep 17 00:00:00 2001
From: Alexey Zinoviev <alexey.zinoviev@xored.com>
Date: Tue, 17 Sep 2024 14:33:39 +0400
Subject: [PATCH] uberf-8149: reset workspace attempts counter tool (#6604)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
---
 dev/tool/src/index.ts | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts
index 655292ffb1..90d5e97aaa 100644
--- a/dev/tool/src/index.ts
+++ b/dev/tool/src/index.ts
@@ -524,7 +524,8 @@ export function devTool (
         await updateWorkspace(db, info, {
           mode: 'active',
           progress: 100,
-          version
+          version,
+          attempts: 0
         })
 
         console.log(metricsToString(measureCtx.metrics, 'upgrade', 60))
@@ -572,7 +573,8 @@ export function devTool (
             await updateWorkspace(db, ws, {
               mode: 'active',
               progress: 100,
-              version
+              version,
+              attempts: 0
             })
           } catch (err: any) {
             console.error(err)
@@ -1589,6 +1591,25 @@ export function devTool (
       })
     })
 
+  program
+    .command('reset-ws-attempts <name>')
+    .description('Reset workspace creation/upgrade attempts counter')
+    .action(async (workspace) => {
+      const { mongodbUri } = prepareTools()
+      await withDatabase(mongodbUri, async (db) => {
+        const info = await getWorkspaceById(db, workspace)
+        if (info === null) {
+          throw new Error(`workspace ${workspace} not found`)
+        }
+
+        await updateWorkspace(db, info, {
+          attempts: 0
+        })
+
+        console.log('Attempts counter for workspace', workspace, 'has been reset')
+      })
+    })
+
   extendProgram?.(program)
 
   program.parse(process.argv)