use bun sql instead of postgres.js

This commit is contained in:
2026-03-12 23:40:44 +01:00
parent aaef31254b
commit be19e26d1b
10 changed files with 31 additions and 41 deletions

View File

@@ -5,16 +5,14 @@
* Usage: bun scripts/backfill-personal-team-names.ts
*/
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { eq, and } from 'drizzle-orm';
import { pgTable, text, uuid, boolean, timestamp } from 'drizzle-orm/pg-core';
import { drizzle } from 'drizzle-orm/bun-sql';
import { eq } from 'drizzle-orm';
import { pgTable, text, uuid, boolean } from 'drizzle-orm/pg-core';
const DATABASE_URL = process.env.DATABASE_URL;
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
const client = postgres(DATABASE_URL);
const db = drizzle(client);
const db = drizzle(DATABASE_URL);
const team = pgTable('team', {
id: uuid('id').primaryKey(),

View File

@@ -11,8 +11,7 @@
* then run this script to populate them.
*/
import postgres from 'postgres';
import { S3Client } from 'bun';
import { SQL, S3Client } from 'bun';
// ── Config ─────────────────────────────────────────────────────────────
@@ -130,7 +129,7 @@ async function getBeatmap(beatmapId: string): Promise<BeatmapData | null> {
// ── Main ───────────────────────────────────────────────────────────────
const sql = postgres(DATABASE_URL);
const sql = new SQL(DATABASE_URL);
// ════════════════════════════════════════════════════════════════════════
// 1. MAPPOOL SLOTS — backfill title/artist/version/coverUrl/listCoverUrl
@@ -263,4 +262,4 @@ console.log(` Mappool slots: ${slotOk} backfilled, ${slotFail} failed`);
console.log(` User avatars: ${avatarOk} re-proxied, ${avatarSkip} already R2`);
console.log(` Team avatars: ${teamOk} re-proxied, ${teamSkip} already R2`);
await sql.end();
await sql.close();

View File

@@ -4,15 +4,13 @@
* Usage: bun scripts/cancel-matches.ts
*/
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { drizzle } from 'drizzle-orm/bun-sql';
import { sql } from 'drizzle-orm';
const DATABASE_URL = process.env.DATABASE_URL;
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
const client = postgres(DATABASE_URL);
const db = drizzle(client);
const db = drizzle(DATABASE_URL);
async function main() {
const result = await db.execute(sql`

View File

@@ -7,15 +7,13 @@
* --full Nuclear: clear everything except users and personal teams
*/
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { drizzle } from 'drizzle-orm/bun-sql';
import { sql } from 'drizzle-orm';
const DATABASE_URL = process.env.DATABASE_URL;
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
const client = postgres(DATABASE_URL);
const db = drizzle(client);
const db = drizzle(DATABASE_URL);
const flag = process.argv[2];

View File

@@ -7,7 +7,7 @@
* Run with: bun run scripts/reseed-ratings.ts
*/
import postgres from 'postgres';
import { SQL } from 'bun';
const DATABASE_URL = process.env.DATABASE_URL!;
const OSU_CLIENT_ID = process.env.OSU_CLIENT_ID!;
@@ -20,7 +20,7 @@ for (const [k, v] of Object.entries({ DATABASE_URL, OSU_CLIENT_ID, OSU_CLIENT_SE
}
}
const sql = postgres(DATABASE_URL);
const sql = new SQL(DATABASE_URL);
// ── osu! API ───────────────────────────────────────────────────────────
@@ -119,7 +119,7 @@ async function main() {
}
console.log(`\nDone: ${updated} updated, ${skipped} skipped`);
await sql.end();
await sql.close();
}
main().catch((err) => {

View File

@@ -5,16 +5,14 @@
* Usage: bun scripts/seed-db.ts
*/
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { drizzle } from 'drizzle-orm/bun-sql';
import { sql } from 'drizzle-orm';
import { pgTable, text, uuid, boolean, timestamp, integer, real, jsonb } from 'drizzle-orm/pg-core';
const DATABASE_URL = process.env.DATABASE_URL;
if (!DATABASE_URL) throw new Error('DATABASE_URL not set');
const client = postgres(DATABASE_URL);
const db = drizzle(client);
const db = drizzle(DATABASE_URL);
const mappool = pgTable('mappool', {
id: uuid('id').primaryKey().defaultRandom(),