feat(01-01): define DB schema, configure Drizzle Kit, write seed script
- Created src/lib/db/schema.ts with users table (id, email, password_hash, created_at) - Created src/lib/db/index.ts exporting db singleton via Drizzle + Neon HTTP driver - Created drizzle.config.ts pointing to schema.ts with postgresql dialect - Created scripts/seed.ts reading AGENT_EMAIL/AGENT_PASSWORD to create hashed user row - Generated drizzle/0000_milky_black_cat.sql migration (committed per user decision) - db:migrate and db:seed pending user Neon database setup
This commit is contained in:
29
teressa-copeland-homes/scripts/seed.ts
Normal file
29
teressa-copeland-homes/scripts/seed.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import "dotenv/config";
|
||||
import { drizzle } from "drizzle-orm/neon-http";
|
||||
import { neon } from "@neondatabase/serverless";
|
||||
import { users } from "../src/lib/db/schema";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
const sql = neon(process.env.DATABASE_URL!);
|
||||
const db = drizzle({ client: sql });
|
||||
|
||||
async function seed() {
|
||||
const email = process.env.AGENT_EMAIL;
|
||||
const password = process.env.AGENT_PASSWORD;
|
||||
|
||||
if (!email || !password) {
|
||||
throw new Error("AGENT_EMAIL and AGENT_PASSWORD env vars are required");
|
||||
}
|
||||
|
||||
const passwordHash = await bcrypt.hash(password, 12);
|
||||
|
||||
await db.insert(users).values({ email, passwordHash }).onConflictDoNothing();
|
||||
|
||||
console.log(`Seeded agent account: ${email}`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
seed().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user