-
Notifications
You must be signed in to change notification settings - Fork 1
/
migr.ts
43 lines (36 loc) · 1.19 KB
/
migr.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
import { Database } from "bun:sqlite";
import postgres from "postgres";
const sql = postgres();
const db = new Database("db.sqlite");
// Humans -> devs
console.log("Migrating devs")
const humans = db.query("SELECT * FROM humans").all();
await sql`insert into devs ${sql(humans)}`;
await sql`SELECT SETVAL('public."devs_id_seq"', COALESCE(MAX(id), 1)) FROM "devs"`;
// Bots
console.log("Migrating bots")
const bots = db.query("SELECT * FROM bots").all();
for (const b of bots) {
b.dev_id = b.human_id;
delete b.human_id;
}
await sql`insert into bots ${sql(bots)}`;
await sql`SELECT SETVAL('public."bots_id_seq"', COALESCE(MAX(id), 1)) FROM "bots"`;
// Default elo updates
console.log("Mkaing empty elo updates")
for (const b of bots) {
await sql`insert into elo_updates (game_id, bot_id, change) VALUES (null, ${b.id}, 1000)`;
}
// Games
// console.log("Migrating games")
// const games = db.query("SELECT * FROM games").all();
// for (const g of games) {
// await sql`insert into games ${sql(g)}`;
// }
// Moves
// console.log("Migrating moves")
// const moves = db.query("SELECT * FROM moves").all();
// for (const m of moves) {
// await sql`insert into moves ${sql(m)}`;
// }
console.log("done");