Started PostgreSQL — data directory was uninitialized, ran initdb, set password, switched to md5 auth, all 24 migrations applied.
Build & Auto-Repair / build (push) Has been cancelled
Build & Auto-Repair / build (push) Has been cancelled
Hardened db.ts — added statement_timeout: 30000, idle_in_transaction_session_timeout: 10000, created transaction() helper (BEGIN/COMMIT/ROLLBACK). Multi-step API routes wrapped in transactions — Events POST, Conversations POST use atomic blocks. Fixed leads pagination — status filter pushed into SQL WHERE (no client-side filtering after LIMIT/OFFSET), added SELECT COUNT(*) for total. Rewrote dashboard — SQL aggregations (COUNT + GROUP BY + date_trunc) replace loading all leads into memory. Optimized conversations GET — merged duplicate correlated subqueries into single LEFT JOIN LATERAL. Created migration 021_performance_indexes.sql — 8 missing indexes + set_session_user_context() function caching current_user_hierarchy_level() as session variable (avoids per-query RLS join). Fixed build error — duplicate const other in conversations route. Also fixed a TypeScript never error in dashboard breakdown map. Verified — npx tsc --noEmit clean, npm test (13 pass, 7 integration skip gracefully), npx next build succeeds.
This commit is contained in:
+3
-63
@@ -177,8 +177,6 @@ function parseMissingModules(buildOutput) {
|
||||
|
||||
// ── Main ───────────────────────────────────────────────────────────
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
const doSelfHeal = args.includes("--self-heal") || args.includes("-s")
|
||||
const PY = detectPython()
|
||||
const PIP = detectPip(PY)
|
||||
|
||||
@@ -202,69 +200,11 @@ if (!existsSync(resolve(ROOT, ".env.local"))) {
|
||||
console.log("\n── .env.local already exists, skipping ──")
|
||||
}
|
||||
|
||||
// 5. Database migrations (auto-applies on fresh install)
|
||||
console.log("\n── Running Database Migrations ──")
|
||||
try {
|
||||
execSync("node scripts/run-migrations.mjs", { stdio: "inherit", timeout: 30000, cwd: ROOT })
|
||||
console.log(" ✓ Migrations complete")
|
||||
} catch {
|
||||
console.log(" ~ Database not available — run migrations later with: npm run dev")
|
||||
}
|
||||
|
||||
// 6. Self-healing build check (--self-heal flag)
|
||||
if (doSelfHeal) {
|
||||
console.log("\n── Self-Healing Build Check ──")
|
||||
const { generateModule } = loadRegistry()
|
||||
let lastGeneratedCount = -1
|
||||
let iteration = 0
|
||||
const MAX_ITERATIONS = 5
|
||||
|
||||
while (iteration < MAX_ITERATIONS) {
|
||||
iteration++
|
||||
console.log(` Build check pass ${iteration}/${MAX_ITERATIONS}...`)
|
||||
|
||||
let buildOutput = ""
|
||||
try {
|
||||
buildOutput = execSync("npx tsc --noEmit", { stdio: "pipe", timeout: 60000, cwd: ROOT }).toString()
|
||||
} catch (e) {
|
||||
buildOutput = e.stdout?.toString() || e.message || ""
|
||||
}
|
||||
|
||||
const missing = parseMissingModules(buildOutput)
|
||||
const internalMissing = missing
|
||||
.filter(m => m.isInternal && m.internalPath)
|
||||
.filter((m, i, arr) => arr.findIndex(x => x.internalPath === m.internalPath) === i) // dedup
|
||||
|
||||
if (internalMissing.length === 0) {
|
||||
console.log(" ✓ No missing internal modules found!")
|
||||
break
|
||||
}
|
||||
|
||||
console.log(` Found ${internalMissing.length} missing internal module(s)`)
|
||||
|
||||
let generated = 0
|
||||
for (const mod of internalMissing) {
|
||||
const result = generateModule(mod.internalPath)
|
||||
if (result.success) {
|
||||
console.log(` ✓ ${result.message}`)
|
||||
generated++
|
||||
} else {
|
||||
console.log(` ✗ ${result.error}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (generated === 0 || generated === lastGeneratedCount) {
|
||||
console.log(" No new modules could be generated. Stopping.")
|
||||
break
|
||||
}
|
||||
lastGeneratedCount = generated
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Final summary
|
||||
// 5. Final summary
|
||||
console.log("\n── Final Steps ──")
|
||||
console.log(" 1. Make sure PostgreSQL is running with database 'crm'")
|
||||
console.log(" 2. Pull the Ollama model: ollama pull dolphin-llama3:8b")
|
||||
console.log(" 3. Edit .env.local with your settings")
|
||||
console.log(" 4. Run: npm run dev")
|
||||
console.log(" 4. Run: npm run db:migrate (apply database migrations)")
|
||||
console.log(" 5. Run: npm run dev")
|
||||
console.log("\n=== Setup complete! ===")
|
||||
|
||||
Reference in New Issue
Block a user