- Pass FastifyRequest/FastifyReply directly to yoga.handleNodeRequestAndResponse per the official graphql-yoga Fastify integration docs. Yoga v5 uses req.body (already parsed by Fastify) when available, avoiding the dead raw stream issue. - Add proper TypeScript generics for server context including db and redis - Wrap sendVerification/sendPasswordReset in try/catch so missing SMTP does not crash register/requestPasswordReset mutations - Fix migrate.ts path resolution to work with both tsx (src/) and compiled (dist/) - Expose postgres:5432 and redis:6379 ports in compose.yml for local dev Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
923 B
TypeScript
28 lines
923 B
TypeScript
import { Pool } from "pg";
|
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
|
import path from "path";
|
|
|
|
const pool = new Pool({
|
|
connectionString: process.env.DATABASE_URL || "postgresql://sexy:sexy@localhost:5432/sexy",
|
|
});
|
|
|
|
const db = drizzle(pool);
|
|
|
|
async function main() {
|
|
console.log("Running schema migrations...");
|
|
// In dev (tsx): __dirname = src/scripts → migrations are at src/migrations
|
|
// In prod (node dist): __dirname = dist/scripts → migrations are at ../../migrations (package root)
|
|
const migrationsFolder = __dirname.includes("/src/")
|
|
? path.join(__dirname, "../migrations")
|
|
: path.join(__dirname, "../../migrations");
|
|
await migrate(db, { migrationsFolder });
|
|
console.log("Schema migrations complete.");
|
|
await pool.end();
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error("Migration failed:", err);
|
|
process.exit(1);
|
|
});
|