Files
deckyvault/lib/db/seed.ts
T
adrianbonpin 65d13933bf feat(db): add hardware seed script, db:seed command, and initial migration
- Create lib/db/seed.ts with idempotent hardware seeding
- Add db:seed script and fix db:* scripts to load .env.local via bun --env-file
- Generate initial Drizzle migration (0000_crazy_nick_fury)
- Apply migration and seed 3 hardware devices (steamdeck-oled, steamdeck-lcd, steam-machine)
2026-04-25 11:53:10 +08:00

48 lines
987 B
TypeScript

import "dotenv/config"
import { drizzle } from "drizzle-orm/node-postgres"
import { Pool } from "pg"
import { hardware } from "./schema/hardware"
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
})
const db = drizzle(pool)
async function seed() {
console.log("Seeding hardware table...")
const devices = [
{
slug: "steamdeck-oled",
name: "Steam Deck OLED",
deviceType: "handled" as const,
},
{
slug: "steamdeck-lcd",
name: "Steam Deck LCD",
deviceType: "handled" as const,
},
{
slug: "steam-machine",
name: "Steam Machine",
deviceType: "console" as const,
},
]
for (const device of devices) {
await db
.insert(hardware)
.values(device)
.onConflictDoNothing({ target: hardware.slug })
}
console.log(`Seeded ${devices.length} hardware devices.`)
await pool.end()
}
seed().catch((err) => {
console.error("Seed failed:", err)
process.exit(1)
})