Adiciona endpoint de arquivamento e ajustes de infra
- Adiciona rota API para arquivar tickets por ID - Atualiza configuracao do Prisma para PostgreSQL - Simplifica workflow CI/CD - Adiciona src/generated ao gitignore - Atualiza documentacao e dependencias 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
33a59634e7
commit
2682b6e8ac
13 changed files with 253 additions and 165 deletions
|
|
@ -1,52 +1,22 @@
|
|||
import "dotenv/config"
|
||||
import dotenv from "dotenv"
|
||||
import path from "node:path"
|
||||
|
||||
import { defineConfig } from "prisma/config"
|
||||
|
||||
const PROJECT_ROOT = process.cwd()
|
||||
const PRISMA_DIR = path.join(PROJECT_ROOT, "prisma")
|
||||
// Carrega .env e .env.local (local tem prioridade)
|
||||
dotenv.config({ path: ".env" })
|
||||
dotenv.config({ path: ".env.local", override: true })
|
||||
|
||||
function resolveFileUrl(url: string) {
|
||||
if (!url.startsWith("file:")) {
|
||||
return url
|
||||
function getDatabaseUrl() {
|
||||
const url = process.env.DATABASE_URL?.trim()
|
||||
|
||||
if (!url) {
|
||||
throw new Error(
|
||||
"DATABASE_URL is required. Set it to a PostgreSQL connection string."
|
||||
)
|
||||
}
|
||||
|
||||
const filePath = url.slice("file:".length)
|
||||
|
||||
if (filePath.startsWith("//")) {
|
||||
return url
|
||||
}
|
||||
|
||||
if (path.isAbsolute(filePath)) {
|
||||
return `file:${path.normalize(filePath)}`
|
||||
}
|
||||
|
||||
const normalized = path.normalize(filePath)
|
||||
const prismaPrefix = `prisma${path.sep}`
|
||||
const relativeToPrisma = normalized.startsWith(prismaPrefix)
|
||||
? normalized.slice(prismaPrefix.length)
|
||||
: normalized
|
||||
|
||||
const absolutePath = path.resolve(PRISMA_DIR, relativeToPrisma)
|
||||
|
||||
if (!absolutePath.startsWith(PROJECT_ROOT)) {
|
||||
throw new Error(`DATABASE_URL path escapes project directory: ${filePath}`)
|
||||
}
|
||||
|
||||
return `file:${absolutePath}`
|
||||
}
|
||||
|
||||
function normalizeDatasourceUrl(envUrl?: string | null) {
|
||||
const trimmed = envUrl?.trim()
|
||||
if (trimmed) {
|
||||
return resolveFileUrl(trimmed)
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
return "file:/app/data/db.sqlite"
|
||||
}
|
||||
|
||||
return resolveFileUrl("file:./db.dev.sqlite")
|
||||
return url
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
|
|
@ -55,6 +25,6 @@ export default defineConfig({
|
|||
path: path.join("prisma", "migrations"),
|
||||
},
|
||||
datasource: {
|
||||
url: normalizeDatasourceUrl(process.env.DATABASE_URL),
|
||||
url: getDatabaseUrl(),
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue