Skip to content
Merged
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@libpg-query/parser": "^17.6.3",
"@opentelemetry/api": "^1.9.0",
"@pgsql/types": "^17.6.2",
"@query-doctor/core": "^0.10.3",
"@query-doctor/core": "^0.10.4",
"async-sema": "^3.1.1",
"capnweb": "^0.7.0",
"dedent": "^1.7.1",
Expand Down
19 changes: 19 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Remote } from "./remote/remote.ts";
import { ConnectionManager } from "./sync/connection-manager.ts";
import { PgbadgerSource } from "./sql/pgbadger.ts";
import type { RecentQuerySource } from "./sql/recent-query.ts";
import type { FullSchema } from "@query-doctor/core";

async function runInCI(
targetPostgresUrl: Connectable,
Expand Down Expand Up @@ -47,6 +48,17 @@ async function runInCI(
log.warn(`API connection broken during CI run: ${err}`, "main");
});

// `Runner.build` triggers `remote.syncFrom`, which emits `schemaSynced` with
// the schema dumped from the source DB. CI doesn't wire up `hookUpApiReporter`
// (that's the persistent-server path), so capture the schema here and push it
// explicitly. We await the push before `disposeApi` so the short-lived CI
// process doesn't exit before the WS write flushes.
let syncedSchema: FullSchema | undefined;
const onSchemaSynced = (schema: FullSchema) => {
syncedSchema = schema;
};
remote.on("schemaSynced", onSchemaSynced);

try {
const config = repo
? await api.getRepoConfig(repo, branch).catch(
Expand Down Expand Up @@ -81,6 +93,12 @@ async function runInCI(
await runner.close();
}

if (syncedSchema) {
await api.pushSchema(JSON.parse(JSON.stringify(syncedSchema))).catch((err) => {
log.warn(`Failed to push schema: ${err}`, "main");
});
}

const queries = buildQueries(allResults, config);

// POST to Site API first so we get the run ID (for baseline exclusion) and
Expand Down Expand Up @@ -198,6 +216,7 @@ async function runInCI(
}
}
} finally {
remote.off("schemaSynced", onSchemaSynced);
disposeApi();
}
}
Expand Down
Loading