update doc and optimize

This commit is contained in:
thanhnv
2026-07-06 17:47:12 +09:00
parent ace442da0e
commit 4419cd9eae
95 changed files with 2951 additions and 1353 deletions
+8
View File
@@ -0,0 +1,8 @@
# Generated at test time from schema.prisma (single source of truth)
prisma/schema.sqlite.prisma
# Local SQLite test database
prisma/test.db
prisma/test.db-journal
test.db
test.db-journal
+6 -4
View File
@@ -5,10 +5,12 @@
"type": "module",
"scripts": {
"build": "prisma generate && tsc -p tsconfig.build.json",
"db:setup": "prisma generate && node scripts/setup-sqlite.mjs",
"gen:sqlite-schema": "node scripts/make-sqlite-schema.mjs",
"db:setup": "npm run gen:sqlite-schema && prisma generate --schema prisma/schema.sqlite.prisma && cross-env DATABASE_URL=file:./test.db prisma db push --schema prisma/schema.sqlite.prisma --force-reset --skip-generate --accept-data-loss",
"dev": "prisma generate && tsx watch src/main.ts",
"seed": "prisma db seed",
"test": "export DATABASE_URL='file:./test.db' JWT_SECRET='test-secret'; npm run db:setup && prisma db seed && node --import tsx --test test/**/*.test.ts"
"seed:test": "cross-env DATABASE_URL=file:./test.db JWT_SECRET=test-secret node --import tsx prisma/seed.ts",
"test": "npm run db:setup && npm run seed:test && cross-env DATABASE_URL=file:./test.db JWT_SECRET=test-secret node --import tsx --test test/services.test.ts test/e2e.test.ts test/llm-judge.test.ts"
},
"dependencies": {
"@nestjs/common": "^10.4.20",
@@ -16,7 +18,7 @@
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.4.20",
"@prisma/client": "^6.19.3",
"bcrypt": "^5.1.1",
"bcryptjs": "^3.0.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.2",
"reflect-metadata": "^0.2.2",
@@ -24,10 +26,10 @@
},
"devDependencies": {
"@nestjs/testing": "^10.4.22",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.21",
"@types/node": "^24.0.8",
"@types/supertest": "^6.0.3",
"cross-env": "^7.0.3",
"prisma": "^6.19.3",
"supertest": "^7.1.1",
"tsx": "^4.20.3",
+1 -1
View File
@@ -1,5 +1,5 @@
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcrypt';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient();
@@ -0,0 +1,18 @@
// Generates prisma/schema.sqlite.prisma from the canonical schema.prisma by
// swapping only the datasource provider to sqlite. Keeping a single source of
// truth for the models avoids drift; the sqlite schema is used for local tests
// (PrismaClient with a mysql provider cannot use a `file:` URL).
import { readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
const src = resolve('prisma/schema.prisma');
const dest = resolve('prisma/schema.sqlite.prisma');
const original = readFileSync(src, 'utf8');
if (!/provider\s*=\s*"mysql"/.test(original)) {
throw new Error('Expected datasource provider "mysql" in schema.prisma');
}
const sqlite = original.replace(/provider\s*=\s*"mysql"/, 'provider = "sqlite"');
const banner = '// AUTO-GENERATED from schema.prisma by scripts/make-sqlite-schema.mjs — do not edit.\n';
writeFileSync(dest, banner + sqlite);
console.log(`Wrote ${dest} (sqlite provider) from schema.prisma`);
@@ -1,27 +0,0 @@
import { mkdirSync, readFileSync, rmSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { DatabaseSync } from 'node:sqlite';
function databasePathFromUrl(url) {
if (!url?.startsWith('file:')) {
throw new Error('DATABASE_URL must use SQLite file: URL');
}
const rawPath = url.slice('file:'.length);
if (rawPath.startsWith('/')) {
return rawPath;
}
return resolve('prisma', rawPath);
}
const databasePath = databasePathFromUrl(process.env.DATABASE_URL ?? 'file:./dev.db');
mkdirSync(dirname(databasePath), { recursive: true });
rmSync(databasePath, { force: true });
rmSync(`${databasePath}-journal`, { force: true });
const sql = readFileSync(resolve('prisma/migrations/202606280001_init/migration.sql'), 'utf8');
const db = new DatabaseSync(databasePath);
db.exec('PRAGMA foreign_keys = ON;');
db.exec(sql);
db.close();
console.log(`SQLite schema applied to ${databasePath}`);
@@ -1,6 +1,6 @@
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import bcrypt from 'bcrypt';
import bcrypt from 'bcryptjs';
import { PrismaService } from '../prisma/prisma.service.js';
export interface LoginResult {