diff --git a/packages/neo4j/src/conceptGraphIndexes.ts b/packages/neo4j/src/conceptGraphIndexes.ts index e3ff522..120d4d0 100644 --- a/packages/neo4j/src/conceptGraphIndexes.ts +++ b/packages/neo4j/src/conceptGraphIndexes.ts @@ -22,16 +22,22 @@ const FULLTEXT_INDEXES = [ ]; export async function ensureConceptGraphIndexes(): Promise { - for (const cypher of [...CONSTRAINTS, ...FULLTEXT_INDEXES]) { - try { - await _runCypher(cypher); - } catch (cause: unknown) { - const msg = cause instanceof Error ? cause.message : String(cause); - if (msg.includes("already exists") || msg.includes("EquivalentSchemaRuleAlreadyExists")) { - process.stderr.write(`[neo4j] concept-graph schema already present, skipping: ${cypher.slice(0, 60)}…\n`); - continue; - } - throw cause; + const results = await Promise.allSettled( + [...CONSTRAINTS, ...FULLTEXT_INDEXES].map((cypher) => + _runCypher(cypher).catch((cause: unknown) => { + const msg = cause instanceof Error ? cause.message : String(cause); + if (msg.includes("already exists") || msg.includes("EquivalentSchemaRuleAlreadyExists")) { + process.stderr.write(`[neo4j] concept-graph schema already present, skipping: ${cypher.slice(0, 60)}…\n`); + return; + } + throw cause; + }), + ), + ); + + for (const result of results) { + if (result.status === "rejected") { + throw result.reason; } } } diff --git a/packages/neo4j/src/flatFolderIndexes.ts b/packages/neo4j/src/flatFolderIndexes.ts index 1eef2ba..47deea5 100644 --- a/packages/neo4j/src/flatFolderIndexes.ts +++ b/packages/neo4j/src/flatFolderIndexes.ts @@ -23,16 +23,22 @@ const FULLTEXT_INDEXES = [ ]; export async function ensureFlatFolderIndexes(): Promise { - for (const cypher of [...CONSTRAINTS, ...FULLTEXT_INDEXES]) { - try { - await _runCypher(cypher); - } catch (cause: unknown) { - const msg = cause instanceof Error ? cause.message : String(cause); - if (msg.includes("already exists") || msg.includes("EquivalentSchemaRuleAlreadyExists")) { - process.stderr.write(`[neo4j] flat-folder schema already present, skipping: ${cypher.slice(0, 60)}…\n`); - continue; - } - throw cause; + const results = await Promise.allSettled( + [...CONSTRAINTS, ...FULLTEXT_INDEXES].map((cypher) => + _runCypher(cypher).catch((cause: unknown) => { + const msg = cause instanceof Error ? cause.message : String(cause); + if (msg.includes("already exists") || msg.includes("EquivalentSchemaRuleAlreadyExists")) { + process.stderr.write(`[neo4j] flat-folder schema already present, skipping: ${cypher.slice(0, 60)}…\n`); + return; + } + throw cause; + }), + ), + ); + + for (const result of results) { + if (result.status === "rejected") { + throw result.reason; } } } diff --git a/packages/neo4j/src/indexes.ts b/packages/neo4j/src/indexes.ts index 735ee58..c588e4d 100644 --- a/packages/neo4j/src/indexes.ts +++ b/packages/neo4j/src/indexes.ts @@ -18,16 +18,22 @@ const FULLTEXT_INDEXES = [ ]; export async function ensureKnowledgeIndexes(): Promise { - for (const cypher of [...CONSTRAINTS, ...FULLTEXT_INDEXES]) { - try { - await _runCypher(cypher); - } catch (cause: unknown) { - const msg = cause instanceof Error ? cause.message : String(cause); - if (msg.includes("already exists") || msg.includes("EquivalentSchemaRuleAlreadyExists")) { - process.stderr.write(`[neo4j] schema already present, skipping: ${cypher.slice(0, 60)}…\n`); - continue; - } - throw cause; + const results = await Promise.allSettled( + [...CONSTRAINTS, ...FULLTEXT_INDEXES].map((cypher) => + _runCypher(cypher).catch((cause: unknown) => { + const msg = cause instanceof Error ? cause.message : String(cause); + if (msg.includes("already exists") || msg.includes("EquivalentSchemaRuleAlreadyExists")) { + process.stderr.write(`[neo4j] schema already present, skipping: ${cypher.slice(0, 60)}…\n`); + return; + } + throw cause; + }), + ), + ); + + for (const result of results) { + if (result.status === "rejected") { + throw result.reason; } } }