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)
This commit is contained in:
2026-04-25 11:53:10 +08:00
parent 50f737f686
commit 65d13933bf
5 changed files with 696 additions and 4 deletions
+47
View File
@@ -0,0 +1,47 @@
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)
})