-
Notifications
You must be signed in to change notification settings - Fork 2
/
hotfix_in_production.ts
44 lines (40 loc) · 1.12 KB
/
hotfix_in_production.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import logger from "./logger";
logger.info("HOTFIX script started");
import * as db from "./db";
import { downloadPicture } from "./helpers";
export const fix = async () => {
const client = await db.retry();
logger.info("connected to postgres.");
try {
// await client.query("BEGIN");
const result = await client.query(
`SELECT id, name, picture FROM users WHERE picture != ''`
);
await Promise.all(
result.rows.map(async row => {
if (row.picture.indexOf("http") !== 0) {
return;
}
try {
const picture = await downloadPicture(row.id, row.picture);
logger.debug(`would update ${row.id} ${row.picture} -> ${picture}`);
await db.updateUser(row.id, {
name: null,
email: null,
picture,
});
} catch (e) {
logger.error(`can't download ${row.picture}`, e);
await db.updateUser(row.id, {
name: row.name,
email: null,
picture: "",
});
}
})
);
} catch (err) {
logger.error("fix", err);
}
process.exit(0);
};