Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .jules/bolt.md
Binary file not shown.
14 changes: 12 additions & 2 deletions prisma.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
import "dotenv/config";
import { defineConfig } from "prisma/config";

// πŸ›‘οΈ Guardian: Fix Prisma CI build environment resolution
// JULES Check: Prevents hanging schemas when DATABASE_URL is missing
// Impact: Fixes build pipeline validation errors
// Date: 2024-07-02
// Session: N/A

if (process.env.DATABASE_URL && !process.env.DIRECT_URL) {
process.env.DIRECT_URL = process.env.DATABASE_URL;
}

export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
engine: "classic",
datasource: {
url:
process.env.DATABASE_URL ?? "postgresql://placeholder:placeholder@localhost:5432/placeholder",
// Non-null assertion strictly for typing, avoiding the fake placeholder URL that causes deployment hangs
url: process.env.DATABASE_URL!,
},
});
20 changes: 15 additions & 5 deletions src/app/api/admin/import-prompts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,28 @@ export async function POST(request: NextRequest) {
let skipped = 0;
const errors: string[] = [];

// ⚑ Bolt: Prevent N+1 queries by pre-fetching all existing prompt titles in a single batched query
const uniqueTitles = Array.from(new Set(rows.map((r) => r.act).filter(Boolean)));

const existingPrompts = await db.prompt.findMany({
where: { title: { in: uniqueTitles } },
select: { title: true },
});

// Create a Set for O(1) lookups during iteration
const existingTitlesSet = new Set(existingPrompts.map((p) => p.title));

for (const row of rows) {
try {
// Check if prompt with same title already exists
const existing = await db.prompt.findFirst({
where: { title: row.act },
});

if (existing) {
if (existingTitlesSet.has(row.act)) {
skipped++;
continue;
}

// Add newly processed title to Set to prevent inserting duplicates from the CSV itself
existingTitlesSet.add(row.act);

// Get or create contributor user
const authorId = await getOrCreateContributor(row.contributor);

Expand Down
Loading