mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-21 00:02:30 +00:00
fix(db-manager): draw a schema the database actually has
`selected.schemaKey` follows the tree and is only replaced once it is empty, so it can still name a schema of the database browsed before this one. The diagram's first draw took it on trust, found no tables under it and stood down for good, leaving that database on a blank canvas. It is now taken only when this database has that schema, and otherwise falls back to the same default the tree starts from. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MXECAKye6KgN13wznsuRzP
This commit is contained in:
co-authored by
Claude Opus 5
parent
f11b468aed
commit
899c808efd
@@ -729,18 +729,28 @@
|
||||
: []
|
||||
)
|
||||
|
||||
/** The schema a database's diagram opens on. `selected.schemaKey` follows the
|
||||
* tree and is only replaced once it is empty, so after a switch between
|
||||
* databases it can still name a schema of the previous one; it is taken only
|
||||
* when this database actually has it. */
|
||||
function schemaToDraw(schema: DBSchema['schema']): string | undefined {
|
||||
const browsed = selected.schemaKey
|
||||
if (browsed && browsed in schema) return browsed
|
||||
return ['public', 'dbo', 'main'].find((s) => s in schema) ?? Object.keys(schema)[0]
|
||||
}
|
||||
|
||||
// Opening the diagram on an empty canvas would make it look broken, so a
|
||||
// database's first draw is its current schema — unless that is big enough that
|
||||
// drawing all of it is a choice the user should make. The schema and the
|
||||
// selected schema key are read reactively: after a switch they arrive late, and
|
||||
// counting the draw done without them is how a database ends up on a blank
|
||||
// canvas for good.
|
||||
// database's first draw is that schema — unless it is big enough that drawing
|
||||
// all of it is a choice the user should make. Everything it needs is read
|
||||
// reactively: after a switch the schema arrives late, and counting the draw
|
||||
// done without it is how a database ends up on a blank canvas for good.
|
||||
const DIAGRAM_AUTOSELECT_LIMIT = 40
|
||||
$effect(() => {
|
||||
const key = databaseKey
|
||||
const schemaKey = selected.schemaKey
|
||||
const schema = dbSchema.schema
|
||||
if (viewMode !== 'diagram' || diagram.drawn || !schemaKey) return
|
||||
if (viewMode !== 'diagram' || diagram.drawn) return
|
||||
const schemaKey = schemaToDraw(schema)
|
||||
if (!schemaKey) return
|
||||
const tables = Object.keys(schema[schemaKey] ?? {})
|
||||
if (!tables.length) return
|
||||
untrack(() => {
|
||||
|
||||
Reference in New Issue
Block a user