remove migrate-token-pool.js (#8931)

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
chris48s
2023-02-26 21:50:27 +00:00
committed by GitHub
parent 78f0e38d57
commit cd91caf484

View File

@@ -1,42 +0,0 @@
import pg from 'pg'
import RedisTokenPersistence from '../core/token-pooling/redis-token-persistence.js'
let redisUrl, postgresUrl
try {
redisUrl = process.argv[2]
postgresUrl = process.argv[3]
if (
!redisUrl.startsWith('rediss://') ||
!postgresUrl.startsWith('postgresql://')
) {
throw new Error()
}
} catch (e) {
process.stdout.write(
'Usage: migrate-token-pool.js [redis-url] [postgres-url]\n'
)
process.exit(1)
}
;(async () => {
const redis = new RedisTokenPersistence({
url: redisUrl,
key: 'githubUserTokens',
})
const tokens = await redis.initialize()
await redis.stop()
console.log(`${tokens.length} tokens in redis source`)
const pool = new pg.Pool({ connectionString: postgresUrl })
let bulkInsert = 'INSERT INTO github_user_tokens (token) VALUES '
bulkInsert += tokens.map(token => `('${token}')`).join(',')
bulkInsert += ' ON CONFLICT (token) DO NOTHING;'
await pool.query(bulkInsert)
const result = await pool.query('SELECT COUNT(*) FROM github_user_tokens;')
console.log(`${result.rows[0].count} tokens in postgres dest`)
await pool.end()
})()