feat: consolidate database management work
Add catalog-owned logical relationships and runtime snapshots, extend the database-management UI and validation coverage, and document the updated operational workflow. Keep active sensitive-generation status in a tooltip and indicator, and update the layout E2E to follow the history action in its new database-scoped location.
This commit is contained in:
@@ -7,16 +7,23 @@ MAX_EXAMPLES_IN_PROMPT = 5
|
||||
|
||||
|
||||
def table_foreign_keys(
|
||||
physical: PhysicalSchema, annotations: Annotations, table: str
|
||||
physical: PhysicalSchema,
|
||||
annotations: Annotations,
|
||||
table: str,
|
||||
effective_relationships: dict[str, list[ForeignKey]] | None = None,
|
||||
) -> list[ForeignKey]:
|
||||
"""FK fisiche + FK logiche dalle annotations (dedup su columns/ref)."""
|
||||
if effective_relationships is not None:
|
||||
return list(effective_relationships.get(table, []))
|
||||
fks = list(physical.tables[table].foreign_keys)
|
||||
ann = annotations.tables.get(table)
|
||||
if ann:
|
||||
seen = {(tuple(f.columns), f.ref_table, tuple(f.ref_columns)) for f in fks}
|
||||
for fk in ann.foreign_keys:
|
||||
if (tuple(fk.columns), fk.ref_table, tuple(fk.ref_columns)) not in seen:
|
||||
key = (tuple(fk.columns), fk.ref_table, tuple(fk.ref_columns))
|
||||
if key not in seen:
|
||||
fks.append(fk)
|
||||
seen.add(key)
|
||||
return fks
|
||||
|
||||
|
||||
@@ -47,6 +54,8 @@ def to_mschema_text(
|
||||
physical: PhysicalSchema,
|
||||
annotations: Annotations | None = None,
|
||||
tables: list[str] | None = None,
|
||||
*,
|
||||
effective_relationships: dict[str, list[ForeignKey]] | None = None,
|
||||
) -> str:
|
||||
"""Serializzazione testuale in stile ThothAI (【Schema】/【Foreign keys】)."""
|
||||
annotations = annotations or Annotations()
|
||||
@@ -73,7 +82,9 @@ def to_mschema_text(
|
||||
shown = ", ".join(column.examples[:MAX_EXAMPLES_IN_PROMPT])
|
||||
lines.append(f" -- Examples: {shown}")
|
||||
lines.append(");")
|
||||
for fk in table_foreign_keys(physical, annotations, table_name):
|
||||
for fk in table_foreign_keys(
|
||||
physical, annotations, table_name, effective_relationships
|
||||
):
|
||||
for src, dst in zip(fk.columns, fk.ref_columns):
|
||||
fk_lines.append(f"{table_name}.{src}={fk.ref_table}.{dst}")
|
||||
lines.extend(["", "【Foreign keys】", *fk_lines])
|
||||
@@ -81,7 +92,10 @@ def to_mschema_text(
|
||||
|
||||
|
||||
def to_schema_dict(
|
||||
physical: PhysicalSchema, annotations: Annotations | None = None
|
||||
physical: PhysicalSchema,
|
||||
annotations: Annotations | None = None,
|
||||
*,
|
||||
effective_relationships: dict[str, list[ForeignKey]] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Vista compatibile con le logiche AV-SQL (schema_dict)."""
|
||||
annotations = annotations or Annotations()
|
||||
@@ -103,13 +117,20 @@ def to_schema_dict(
|
||||
"primary_keys": [c for c in cols if table.columns[c].pk],
|
||||
"foreign_keys": [
|
||||
{"columns": fk.columns, "ref_table": fk.ref_table, "ref_columns": fk.ref_columns}
|
||||
for fk in table_foreign_keys(physical, annotations, table_name)
|
||||
for fk in table_foreign_keys(
|
||||
physical, annotations, table_name, effective_relationships
|
||||
)
|
||||
],
|
||||
}
|
||||
return out
|
||||
|
||||
|
||||
def to_markdown(physical: PhysicalSchema, annotations: Annotations | None = None) -> str:
|
||||
def to_markdown(
|
||||
physical: PhysicalSchema,
|
||||
annotations: Annotations | None = None,
|
||||
*,
|
||||
effective_relationships: dict[str, list[ForeignKey]] | None = None,
|
||||
) -> str:
|
||||
"""Report leggibile per il reviewer."""
|
||||
annotations = annotations or Annotations()
|
||||
lines = [
|
||||
@@ -146,7 +167,9 @@ def to_markdown(physical: PhysicalSchema, annotations: Annotations | None = None
|
||||
f"| {column_name} | {column.type} | {'sì' if column.nullable else 'no'} "
|
||||
f"| {'sì' if column.pk else ''} | {cdesc} | {examples} |"
|
||||
)
|
||||
fks = table_foreign_keys(physical, annotations, table_name)
|
||||
fks = table_foreign_keys(
|
||||
physical, annotations, table_name, effective_relationships
|
||||
)
|
||||
if fks:
|
||||
lines += ["", "Foreign keys:"]
|
||||
for fk in fks:
|
||||
|
||||
Reference in New Issue
Block a user