()
| 75 | } |
| 76 | |
| 77 | async function deleteAllData() { |
| 78 | const auth = resolveTinybirdAuth(); |
| 79 | const client = createTinybirdClient(auth); |
| 80 | |
| 81 | const datasources = await getAllDatasources(client); |
| 82 | |
| 83 | await doubleConfirm({ |
| 84 | workspaceName: client.workspaceName, |
| 85 | workspaceId: client.workspaceId, |
| 86 | host: client.host, |
| 87 | datasources, |
| 88 | }); |
| 89 | |
| 90 | console.log("\nDeleting all data from Tinybird datasources...\n"); |
| 91 | |
| 92 | const successes = []; |
| 93 | const failures = []; |
| 94 | for (const datasource of datasources) { |
| 95 | try { |
| 96 | console.log(`Deleting data from ${datasource}...`); |
| 97 | let ok = false; |
| 98 | try { |
| 99 | await client.request( |
| 100 | `/v0/datasources/${encodeURIComponent(datasource)}/truncate`, |
| 101 | { |
| 102 | method: "POST", |
| 103 | }, |
| 104 | ); |
| 105 | ok = true; |
| 106 | } catch (_e1) { |
| 107 | try { |
| 108 | await client.request( |
| 109 | `/v0/datasources/${encodeURIComponent(datasource)}/data`, |
| 110 | { |
| 111 | method: "DELETE", |
| 112 | }, |
| 113 | ); |
| 114 | ok = true; |
| 115 | } catch (_e2) { |
| 116 | await client.request( |
| 117 | `/v0/datasources/${encodeURIComponent(datasource)}`, |
| 118 | { |
| 119 | method: "DELETE", |
| 120 | }, |
| 121 | ); |
| 122 | ok = true; |
| 123 | } |
| 124 | } |
| 125 | if (ok) { |
| 126 | console.log(`✅ Deleted data from ${datasource}`); |
| 127 | successes.push(datasource); |
| 128 | } else { |
| 129 | failures.push(datasource); |
| 130 | } |
| 131 | } catch (error) { |
| 132 | console.error( |
| 133 | `❌ Failed to delete data from ${datasource}:`, |
| 134 | error.message, |
no test coverage detected