Skip to content

Commit 58e80e3

Browse files
committed
clean test databases script
1 parent 809e310 commit 58e80e3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/clean.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* clean.test.ts - clean test databases
3+
*/
4+
5+
import { describe, it } from '@jest/globals'
6+
import { getChinookDatabase } from './shared'
7+
8+
describe.skip('clean test suite', () => {
9+
it('should remove test databases from the project', async () => {
10+
let chinook
11+
try {
12+
chinook = getChinookDatabase()
13+
// Use the connect utility to execute SQL statements on the selected database
14+
const result = await chinook.sql(`LIST DATABASES`)
15+
const limit = 1000
16+
let removed = []
17+
let dbname = ''
18+
for (let i = 0; i < result.length; i++) {
19+
dbname = result[i].name
20+
if ((dbname.startsWith('1brc') && dbname.includes('-2025')) || dbname.startsWith('testing-2025')) {
21+
removed.push(dbname)
22+
// console.log("remove ${dbname}")
23+
const r = await chinook.sql(`REMOVE DATABASE ${dbname}`)
24+
if (removed.length >= limit) {
25+
break
26+
}
27+
}
28+
}
29+
30+
// Build the object to be returned by your edge function
31+
const message = `Number of databases: ${result.length}, removed ${removed.length}`
32+
33+
// Return the object from your edge function
34+
35+
console.debug({ message, removed })
36+
} finally {
37+
chinook?.close()
38+
}
39+
})
40+
})

0 commit comments

Comments
 (0)