GRV-BackEnd/scripts/dev-db.mjs
kirukib 7b3b9c5943 Scaffold GRV backend: applications, inquiries, tickets, discounts, merch, QR game
NestJS + Prisma/Postgres API shared by the site, admin and attendee app.
Ports the site's D1 application flow and review, stores every inquiry form,
sells tickets with discount codes (manual payment confirmation), and runs
booth/startup/mystery-investee QR scans with derived points and raffles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 21:24:36 +03:00

32 lines
981 B
JavaScript

// Local Postgres without Docker: PGlite (real Postgres 17 in WASM) behind the wire protocol.
// Usage: pnpm db:dev → postgresql://postgres:postgres@127.0.0.1:5433/postgres
// Use Docker Compose Postgres instead whenever Docker is available.
import { mkdirSync } from 'node:fs';
import { PGlite } from '@electric-sql/pglite';
import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
const dataDir = process.env.PGLITE_DIR ?? '.data/pglite';
const port = Number(process.env.PGLITE_PORT ?? 5433);
mkdirSync(dataDir, { recursive: true });
const db = await PGlite.create({ dataDir });
const server = new PGLiteSocketServer({
db,
port,
host: '127.0.0.1',
maxConnections: 20,
});
await server.start();
console.log(
`PGlite listening on postgresql://postgres:postgres@127.0.0.1:${port}/postgres (${dataDir})`,
);
const stop = async () => {
await server.stop();
await db.close();
process.exit(0);
};
process.on('SIGINT', stop);
process.on('SIGTERM', stop);