MCPcopy Create free account
hub / github.com/HKUDS/AgentSpace / readPostgresStatusWithClient

Function readPostgresStatusWithClient

packages/db/src/postgres.ts:532–564  ·  view source on GitHub ↗
(client: Client, databaseUrl: string)

Source from the content-addressed store, hash-verified

530}
531
532async function readPostgresStatusWithClient(client: Client, databaseUrl: string): Promise<PostgresStatus> {
533 const appMetadataExists = await client.query<{ exists: string | null }>(
534 `SELECT to_regclass('public.app_metadata') AS exists`,
535 );
536 const hasSchema = Boolean(appMetadataExists.rows[0]?.exists);
537 if (!hasSchema) {
538 return {
539 engine: "postgres",
540 databaseUrl: redactPostgresDatabaseUrl(databaseUrl),
541 schemaVersion: "uninitialized",
542 tables: POSTGRES_TABLE_NAMES.map((tableName) => ({ tableName, rowCount: 0 })),
543 };
544 }
545
546 const schemaVersionResult = await client.query<{ value: string }>(
547 "SELECT value FROM app_metadata WHERE key = 'schema_version' LIMIT 1",
548 );
549 const tables: Array<{ tableName: PostgresTableName; rowCount: number }> = [];
550 for (const tableName of POSTGRES_TABLE_NAMES) {
551 const countResult = await client.query<{ count: string }>(`SELECT COUNT(*)::text AS count FROM ${tableName}`);
552 tables.push({
553 tableName,
554 rowCount: Number(countResult.rows[0]?.count ?? "0"),
555 });
556 }
557
558 return {
559 engine: "postgres",
560 databaseUrl: redactPostgresDatabaseUrl(databaseUrl),
561 schemaVersion: schemaVersionResult.rows[0]?.value ?? "unknown",
562 tables,
563 };
564}
565
566function shouldUsePostgresSsl(databaseUrl: string): boolean {
567 try {

Callers 2

ensurePostgresSchemaFunction · 0.85
getPostgresStatusFunction · 0.85

Calls 1

Tested by

no test coverage detected