Skip to content

Commit 1100681

Browse files
emmaling27Convex, Inc.
authored andcommitted
System UDF for reading schema validation progress (#40551)
Adds system table `_schema_validation_progress` and a system UDF for reading progress of pending schemas getting validated. GitOrigin-RevId: 23a6d7201590438f54742c67d350cc90877efae3
1 parent 2c86b1e commit 1100681

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

npm-packages/system-udfs/convex/_system/frontend/getSchemas.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,28 @@ export default queryPrivateSystem({
3434
};
3535
},
3636
});
37+
38+
export const schemaValidationProgress = queryPrivateSystem({
39+
args: { componentId: v.optional(v.union(v.string(), v.null())) },
40+
handler: async function ({
41+
db,
42+
}): Promise<{ numDocsValidated: number; totalDocs: number | null } | null> {
43+
const pending = await getSchemaByState(db, "pending");
44+
if (!pending) {
45+
return null;
46+
}
47+
const schemaValidationProgressDoc = await db
48+
.query("_schema_validation_progress")
49+
.withIndex("by_schema_id", (q) => q.eq("schemaId", pending._id))
50+
.unique();
51+
if (!schemaValidationProgressDoc) {
52+
return null;
53+
}
54+
return {
55+
numDocsValidated: Number(schemaValidationProgressDoc.numDocsValidated),
56+
totalDocs: schemaValidationProgressDoc.totalDocs
57+
? Number(schemaValidationProgressDoc.totalDocs)
58+
: null,
59+
};
60+
},
61+
});

npm-packages/system-udfs/convex/schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ export default defineSchema({
430430
}).index("by_name_and_ts", ["name", "ts"]),
431431
_udf_config: defineTable({ serverVersion: v.string() }),
432432
_schemas: defineTable(schemaMetadata).index("by_state", ["state"]),
433+
_schema_validation_progress: defineTable({
434+
schemaId: v.id("_schemas"),
435+
numDocsValidated: v.int64(),
436+
totalDocs: v.union(v.int64(), v.null()),
437+
}).index("by_schema_id", ["schemaId"]),
433438
_log_sinks: logSinksTable,
434439
_backend_state: backendStateTable,
435440
_snapshot_imports: snapshotImportsTable,

0 commit comments

Comments
 (0)