libredb / libredb/libredb-studio

Schema Diff compares against a cached schema, so a diff after a DDL change reports no differences

Open
#884 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
726
Forks
119
Avg merge
7h 41m
Merged PRs (30d)
284

Description

## What

Schema Diff's "Current Schema" option reads a schema passed in as a prop rather than reading the database. A diff taken right after a DDL change reports no differences.

## Where

src/components/SchemaDiff.tsx:35-39

```tsx
schema: readonly DetailedObject[];
...
export function SchemaDiff({ schema, connection }: SchemaDiffProps) {
```

Lines 81 and 83 resolve "current" to that prop:

```ts
const sourceSchema = sourceId === "current" ? schema : snapshots.find((s) => s.id === sourceId)?.schema || [];
const targetSchema = targetId === "current" ? schema : snapshots.find((s) => s.id === targetId)?.schema || [];
```

Nothing re-reads the database for "current". The snapshot button at line 56 deep-copies the same prop, so a snapshot taken from a stale prop is stale too.

Note the contrast: `fetchRemoteSchema` at line 102 does go to the server for a remote connection. Only the local "current" side is served from memory.

## Observed

Take a snapshot, run a DDL change, open Schema Diff and compare the snapshot against Current Schema. It reports "No differences found". Reloading the page and repeating the comparison shows the difference.

## Why this matters

Schema Diff exists to answer "what changed", and the one case where the answer matters most, a change made moments ago, is the case it gets wrong. It also generates migration SQL from that comparison, so a migration generated right after a DDL change can be empty or wrong.

## Suggested direction

Refresh the schema before computing a diff that involves "current", or invalidate whatever cache feeds the prop when a DDL statement runs. A visible "last read at" stamp beside the Current Schema option would also make a stale read obvious rather than silent.

Contributor guide

Open the contributing guide

Research direction

Start in src/components/SchemaDiff.tsx, especially the schema prop, snapshot handling around line 56, and current-schema resolution at lines 81-83. Compare this path with fetchRemoteSchema at line 102 and trace how the local schema prop changes after DDL execution. Done means a diff involving Current Schema reflects a recent database change and generated migration SQL is not empty or incorrect.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
databases, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.