Skip to content

Implementations Of The Deployment Database Introspection Logic#65

Merged
abdotop merged 2 commits intomasterfrom
64-implementations-of-the-deployment-database-introspection-logic
Oct 7, 2025
Merged

Implementations Of The Deployment Database Introspection Logic#65
abdotop merged 2 commits intomasterfrom
64-implementations-of-the-deployment-database-introspection-logic

Conversation

@abdotop
Copy link
Member

@abdotop abdotop commented Oct 1, 2025

feat(schema): add endpoint to fetch cached database schema and implement schema refresh loop

@abdotop abdotop requested review from Copilot and kigiri October 1, 2025 08:19
@abdotop abdotop self-assigned this Oct 1, 2025
@abdotop abdotop added the tournament Pull requests that are related to the Tournament team label Oct 1, 2025
@abdotop abdotop linked an issue Oct 1, 2025 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds database schema introspection functionality to the deployment system. It implements automatic detection of database dialects, schema retrieval, and a periodic refresh mechanism to keep schema information current.

Key changes:

  • Adds comprehensive SQL dialect detection and schema introspection for multiple database types (PostgreSQL, MySQL, SQLite, SQL Server, Oracle, DuckDB)
  • Implements a periodic background schema refresh loop that updates cached database schemas
  • Provides a new API endpoint to fetch cached database schema information for deployments

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
api/sql.ts Core implementation of database dialect detection, schema introspection queries, and refresh logic
api/server.ts Integration of schema refresh loop startup in the main server initialization
api/schema.ts Database schema model definition and collection setup for caching schema data
api/routes.ts New API endpoint to retrieve cached database schema for a deployment
Comments suppressed due to low confidence (1)

api/sql.ts:1

  • The Oracle query has incorrect SQL syntax. The assignment table_schema = owner AS table_schema is invalid. It should be owner AS table_schema.
import { DatabaseSchemasCollection, DeploymentsCollection } from './schema.ts'

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +150 to +153
export function startSchemaRefreshLoop() {
if (intervalHandle) return
// initial kick (non-blocking)
refreshAllSchemas()
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial schema refresh call is not awaited, which means the interval starts immediately without waiting for the first refresh to complete. This could lead to overlapping refresh operations if the refresh takes longer than the interval. Consider awaiting this call or adding concurrency protection.

Suggested change
export function startSchemaRefreshLoop() {
if (intervalHandle) return
// initial kick (non-blocking)
refreshAllSchemas()
export async function startSchemaRefreshLoop() {
if (intervalHandle) return
// initial kick (awaited)
await refreshAllSchemas()

Copilot uses AI. Check for mistakes.
Comment on lines +144 to +146
for (const dep of DeploymentsCollection.values()) {
await refreshOneSchema(dep)
}
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sequential processing of deployments could be slow with many deployments. Consider using Promise.allSettled() to refresh schemas concurrently while preventing one failure from blocking others.

Suggested change
for (const dep of DeploymentsCollection.values()) {
await refreshOneSchema(dep)
}
await Promise.allSettled(
Array.from(DeploymentsCollection.values()).map(dep => refreshOneSchema(dep))
);

Copilot uses AI. Check for mistakes.
Comment on lines +352 to +365
output: OBJ({
deploymentUrl: STR('Deployment url (matches deployment.url)'),
dialect: STR('Detected SQL dialect'),
refreshedAt: STR('ISO datetime of last refresh'),
tables: ARR(OBJ({
columns: ARR(OBJ({
name: STR('Column name'),
type: STR('Column data type'),
ordinal: NUM('Column ordinal position'),
})),
schema: optional(STR('Schema name')),
table: STR('Table name'),
})),
}, 'Database schema cache for a deployment'),
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output schema definition duplicates the DatabaseSchemaDef from schema.ts. Consider importing and reusing DatabaseSchemaDef to maintain consistency and reduce duplication.

Copilot uses AI. Check for mistakes.
@abdotop abdotop force-pushed the 64-implementations-of-the-deployment-database-introspection-logic branch from 8d19bd3 to a28d776 Compare October 1, 2025 08:26
@abdotop abdotop marked this pull request as ready for review October 7, 2025 08:59
@abdotop abdotop merged commit ca1dfe5 into master Oct 7, 2025
2 checks passed
@abdotop abdotop deleted the 64-implementations-of-the-deployment-database-introspection-logic branch October 7, 2025 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tournament Pull requests that are related to the Tournament team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementations Of The Deployment Database Introspection Logic

2 participants