● Zion Boggan
repos/Stepping App/packages/db/src/seed.ts
zionboggan.com ↗
58 lines · typescript
History for this file →
1
import "dotenv/config";
2
import { randomBytes, scryptSync } from "node:crypto";
3
import { DEV_USER_ID } from "@stepping/config";
4
import { getDb } from "./index";
5
import { cities, users } from "./schema";
6
 
7
function hashPassword(pw: string): string {
8
  const salt = randomBytes(16).toString("hex");
9
  return `scrypt$${salt}$${scryptSync(pw, salt, 64).toString("hex")}`;
10
}
11
 
12
const LAUNCH_CITIES = [
13
  { slug: "chicago", name: "Chicago", metroLabel: "Chicago, IL", state: "IL", lat: 41.8781, lng: -87.6298 },
14
  { slug: "atlanta", name: "Atlanta", metroLabel: "Atlanta, GA", state: "GA", lat: 33.749, lng: -84.388 },
15
  { slug: "detroit", name: "Detroit", metroLabel: "Detroit, MI", state: "MI", lat: 42.3314, lng: -83.0458 },
16
  { slug: "houston", name: "Houston", metroLabel: "Houston, TX", state: "TX", lat: 29.7604, lng: -95.3698 },
17
  { slug: "charlotte", name: "Charlotte", metroLabel: "Charlotte, NC", state: "NC", lat: 35.2271, lng: -80.8431 },
18
  { slug: "washington-dc", name: "Washington", metroLabel: "Washington, DC (DMV)", state: "DC", lat: 38.9072, lng: -77.0369 },
19
];
20
 
21
async function main() {
22
  const db = getDb();
23
 
24
  console.log("Seeding system member user...");
25
  await db
26
    .insert(users)
27
    .values({ id: DEV_USER_ID, handle: "community", displayName: "Community", role: "member" })
28
    .onConflictDoNothing();
29
 
30
  const adminEmail = (process.env.STEPPING_ADMIN_EMAIL || "admin@steppingapp.com").toLowerCase();
31
  const adminPw = process.env.STEPPING_ADMIN_PASSWORD || "St3pp!n_Cr0wn#2026$kX9qVz7m";
32
  console.log("Seeding admin account...");
33
  await db
34
    .insert(users)
35
    .values({
36
      email: adminEmail,
37
      passwordHash: hashPassword(adminPw),
38
      handle: "admin",
39
      displayName: "Admin",
40
      role: "admin",
41
    })
42
    .onConflictDoNothing();
43
 
44
  console.log("Seeding launch cities (Chicago flagship + 5)...");
45
  await db
46
    .insert(cities)
47
    .values(LAUNCH_CITIES.map((c) => ({ ...c, tier: 1, isLaunched: true })))
48
    .onConflictDoNothing();
49
 
50
  console.log("Seed complete.");
51
  console.log(`ADMIN LOGIN -> ${adminEmail} / ${adminPw}`);
52
  process.exit(0);
53
}
54
 
55
main().catch((err) => {
56
  console.error(err);
57
  process.exit(1);
58
});