{% endif %}
{# Overall stats summary for MIGRATE/UNDO #}
{% if cmd.command_type in ['MIGRATE','UNDO'] and cmd.per_migration_journal %}
{% set s = namespace(total_stmts=0, total_time=0, min_time=999999, max_time=0) %}
{% for mig_script, mj in cmd.per_migration_journal.items() %}
{% if mj.statements %}
{% set s.total_stmts = s.total_stmts + (mj.statements|length) %}
{% set s.total_time = s.total_time + (mj.total_execution_time or 0) %}
{% if mj.min_statement_time and mj.min_statement_time < s.min_time %}{% set s.min_time = mj.min_statement_time %}{% endif %}
{% if mj.max_statement_time and mj.max_statement_time > s.max_time %}{% set s.max_time = mj.max_statement_time %}{% endif %}
{% endif %}
{% endfor %}
{% if s.total_stmts > 0 %}
Statements
{{ s.total_stmts }}
Total time
{{ s.total_time }} ms
Avg / stmt
{{ (s.total_time / s.total_stmts)|round(2) }} ms
Min / Max
{{ s.min_time }} / {{ s.max_time }} ms
{% endif %}
{% endif %}
{# ========== INFO ========== #}
{% if cmd.command_type == 'INFO' and cmd.migrations %}
{{ icon_table() }} Schema history
{{ cmd.migrations|length }} migrations
{{ icon_search() }}
All {{ cmd.migrations|length }}
{% set ns_inf = namespace(success=0, pending=0, failed=0, ignored=0) %}
{% for m in cmd.migrations %}
{% set st = (m.state|default(m.status|default('')))|upper %}
{% if 'SUCC' in st or 'INSTALL' in st %}{% set ns_inf.success = ns_inf.success + 1 %}
{% elif 'PENDING' in st %}{% set ns_inf.pending = ns_inf.pending + 1 %}
{% elif 'FAIL' in st %}{% set ns_inf.failed = ns_inf.failed + 1 %}
{% elif 'IGNOR' in st %}{% set ns_inf.ignored = ns_inf.ignored + 1 %}
{% endif %}
{% endfor %}
Success {{ ns_inf.success }}
Pending {{ ns_inf.pending }}
Failed {{ ns_inf.failed }}
{% if ns_inf.ignored > 0 %}
Ignored {{ ns_inf.ignored }}
{% endif %}
Version
Description
Type
Status
Installed on
Installed by
Exec
{% for m in cmd.migrations %}
{% set st = (m.state|default(m.status|default('')))|upper %}
{% set status_class = 'neutral' %}{% set status_label = m.state|default(m.status|default('—')) %}{% set status_key = 'other' %}
{% if 'SUCC' in st or 'INSTALL' in st %}{% set status_class = 'ok' %}{% set status_key = 'success' %}
{% elif 'PENDING' in st %}{% set status_class = 'warn' %}{% set status_key = 'pending' %}
{% elif 'FAIL' in st %}{% set status_class = 'fail' %}{% set status_key = 'failed' %}
{% elif 'IGNOR' in st %}{% set status_class = 'neutral' %}{% set status_key = 'ignored' %}
{% endif %}
{{ m.version|default('—') }}
{{ m.description|default(m.script|default('—')) }}{% if m.script and m.description %}
{{ m.script }}
{% endif %}
{% set t = (m.type|default(''))|upper %}{% if 'REPEAT' in t %}Repeatable{% elif 'UNDO' in t %}Undo{% elif t %}Versioned{% else %}—{% endif %}
{% endif %}
{% endif %}
{# ========== MIGRATE / UNDO ========== #}
{% if cmd.command_type in ['MIGRATE','UNDO'] and cmd.per_migration_journal %}
{# Identify failed migration #}
{% set ns_fail = namespace(script=None, stmt=None, idx=0) %}
{% if not cmd.success %}
{% for mig_script, mj in cmd.per_migration_journal.items() %}
{% if mj.statements %}
{% for st in mj.statements %}
{% if not st.success %}
{% if not ns_fail.script %}{% set ns_fail.script = mig_script %}{% set ns_fail.stmt = st %}{% set ns_fail.idx = loop.index %}{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if ns_fail.script %}
{{ icon_alert() }}
Failure root cause
Migration {{ ns_fail.script }} failed at statement #{{ ns_fail.idx }}{% if ns_fail.stmt and ns_fail.stmt.error %} — {{ ns_fail.stmt.error }}{% endif %}. Following migrations were not applied.
{% endif %}
{{ icon_branch() }} Per-migration execution
{% set max_time = namespace(v=1) %}
{% for mig_script, mj in cmd.per_migration_journal.items() %}
{% if mj.statements %}{% for st in mj.statements %}{% if (st.execution_time or 0) > max_time.v %}{% set max_time.v = st.execution_time %}{% endif %}{% endfor %}{% endif %}
{% endfor %}
{% for mig_script, mj in cmd.per_migration_journal.items() %}
{% set ns_mig = namespace(has_fail=false) %}
{% if mj.statements %}{% for st in mj.statements %}{% if not st.success %}{% set ns_mig.has_fail = true %}{% endif %}{% endfor %}{% endif %}
{% set has_fail = ns_mig.has_fail %}
{% if mj.statements %}{{ mj.statements|length }} stmt{% if mj.statements|length != 1 %}s{% endif %}{% endif %}
{{ mj.total_execution_time|default(0) }} ms
{% if has_fail %}Failed{% else %}OK{% endif %}
{% if mj.statements %}
{# Show per-statement SQL here only when the dedicated SQL panel will not render it.
The SQL panel (above) requires show_sql=True AND cmd.sql to be populated.
When both conditions hold the SQL is already visible there — no need to duplicate.
When show_sql is False the user has opted out of SQL display entirely. #}
{% set show_sql_here = cmd.result.show_sql and not cmd.sql %}
{% if show_sql_here %}
{% endif %}
#
Operation
Timeline
Time
{% for st in mj.statements %}
{% set risky = is_risky(st.statement) %}
{% set pct = ((st.execution_time or 0) / max_time.v * 100)|round(1) %}
{{ loop.index }}
{{ op_chip(st.statement) }}
{% if not st.success %}Error{% endif %}
{% if risky %}Risky{% endif %}
{% if show_sql_here %}
{{ st.statement|e }}
{% endif %}
{% if not st.success and st.error %}
{{ icon_alert() }}
{{ st.error }}
{% endif %}
{{ st.execution_time|default(0) }} ms
{% endfor %}
{% else %}
No statements recorded.
{% endif %}
{% endfor %}
{% endif %}
{# ========== DIFF ========== #}
{% if cmd.command_type == 'DIFF' %}
{% set diff = cmd.diff_data|default(cmd.diff|default(None)) %}
{% if diff %}
{# Summary banner #}
{% set total_diffs = diff.total_differences|default(0) %}
{% if total_diffs > 0 %}
Missing constraints
{% for c in tbl.missing_constraints %}{{ c.constraint_name|default(c) }}{% endfor %}
{% endif %}
{% if tbl.extra_constraints %}
Extra constraints
{% for c in tbl.extra_constraints %}{{ c.constraint_name|default(c) }}{% endfor %}
{% endif %}
{% if tbl.unified_diff and tbl.unified_diff.lines %}
{{ icon_diff() }}SQL diff
{% for ln in tbl.unified_diff.lines %}
{% if ln.type == 'removed' %}
{{ ln.before_num|default('') }}
{{ ln.content|e }}
{% elif ln.type == 'added' %}
{{ ln.after_num|default('') }}
{{ ln.content|e }}
{% else %}
{{ ln.before_num|default('') }}
{{ ln.after_num|default('') }}
{{ ln.content|e }}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{# Missing / Extra Tables #}
{% if diff.missing_tables or diff.extra_tables %}
Tables
{% if diff.missing_tables %}−{{ diff.missing_tables|length }} missing{% endif %}
{% if diff.extra_tables %}+{{ diff.extra_tables|length }} extra{% endif %}
{% for t in diff.missing_tables %}
TABLEmissing
{{ t.table_name|default(t) }}
{% endfor %}
{% for t in diff.extra_tables %}
TABLEextra
{{ t.table_name|default(t) }}
{% endfor %}
{% endif %}
{# Views #}
{% if diff.missing_views or diff.extra_views or diff.modified_views %}
Views
{% if diff.missing_views %}−{{ diff.missing_views|length }}{% endif %}
{% if diff.extra_views %}+{{ diff.extra_views|length }}{% endif %}
{% if diff.modified_views %}~{{ diff.modified_views|length }}{% endif %}
{% for v in diff.missing_views %}
VIEWmissing
{{ v.view_name|default(v) }}
{% endfor %}
{% for v in diff.extra_views %}
VIEWextra
{{ v.view_name|default(v) }}
{% endfor %}
{% for v in diff.modified_views %}
VIEWmodified
{{ v.view_name|default(v) }}
{% endfor %}
{% endif %}
{# Indexes #}
{% if diff.missing_indexes or diff.extra_indexes or diff.modified_indexes %}
Indexes
{% if diff.missing_indexes %}−{{ diff.missing_indexes|length }}{% endif %}
{% if diff.extra_indexes %}+{{ diff.extra_indexes|length }}{% endif %}
{% for i in diff.missing_indexes %}
INDEXmissing
{{ i.index_name|default(i) }}
{% endfor %}
{% for i in diff.extra_indexes %}
INDEXextra
{{ i.index_name|default(i) }}
{% endfor %}
{% endif %}
{# Sequences #}
{% if diff.missing_sequences or diff.extra_sequences %}
Sequences
{% if diff.missing_sequences %}−{{ diff.missing_sequences|length }}{% endif %}
{% if diff.extra_sequences %}+{{ diff.extra_sequences|length }}{% endif %}
{% for s in diff.missing_sequences %}
SEQUENCEmissing
{{ s.sequence_name|default(s) }}
{% endfor %}
{% for s in diff.extra_sequences %}
SEQUENCEextra
{{ s.sequence_name|default(s) }}
{% endfor %}
{% endif %}
{# Triggers #}
{% if diff.missing_triggers or diff.extra_triggers %}
Triggers
{% if diff.missing_triggers %}−{{ diff.missing_triggers|length }}{% endif %}
{% if diff.extra_triggers %}+{{ diff.extra_triggers|length }}{% endif %}
{% for t in diff.missing_triggers %}
TRIGGERmissing
{{ t.trigger_name|default(t) }}
{% endfor %}
{% for t in diff.extra_triggers %}
TRIGGERextra
{{ t.trigger_name|default(t) }}
{% endfor %}
{% endif %}
{# Functions & Procedures #}
{% if diff.missing_functions or diff.extra_functions or diff.missing_procedures or diff.extra_procedures %}
{% set fn_miss = (diff.missing_functions|default([]))|length + (diff.missing_procedures|default([]))|length %}
{% set fn_extra = (diff.extra_functions|default([]))|length + (diff.extra_procedures|default([]))|length %}
Functions & Procedures
{% if fn_miss > 0 %}−{{ fn_miss }}{% endif %}
{% if fn_extra > 0 %}+{{ fn_extra }}{% endif %}
{% for f in diff.missing_functions %}
FUNCTIONmissing
{{ f.function_name|default(f) }}
{% endfor %}
{% for f in diff.extra_functions %}
FUNCTIONextra
{{ f.function_name|default(f) }}
{% endfor %}
{% for p in diff.missing_procedures %}
PROCEDUREmissing
{{ p.procedure_name|default(p) }}
{% endfor %}
{% for p in diff.extra_procedures %}
PROCEDUREextra
{{ p.procedure_name|default(p) }}
{% endfor %}
{% endif %}
{# All clean #}
{% if not diff.modified_tables and not diff.missing_tables and not diff.extra_tables and not diff.missing_views and not diff.extra_views and not diff.modified_views and not diff.missing_indexes and not diff.extra_indexes and not diff.missing_sequences and not diff.extra_sequences and not diff.missing_triggers and not diff.extra_triggers and not diff.missing_functions and not diff.extra_functions and not diff.missing_procedures and not diff.extra_procedures %}
{{ icon_check() }}
No differences detected
Schemas are identical.
{% endif %}
{% else %}
{{ icon_diff() }}
No diff data
This DIFF command did not produce structured diff output.
{% endif %}
{% endif %}
{# ========== CLEAN ========== #}
{% if cmd.command_type == 'CLEAN' %}
{% if cmd.result and cmd.result.get_objects_by_type %}
{% set objects_map = cmd.result.get_objects_by_type() %}
{% set ns_clean = namespace(total=0) %}
{% for obj_type, names in objects_map.items() %}{% set ns_clean.total = ns_clean.total + (names|length) %}{% endfor %}
{% endif %}
{# ========== INTROSPECTION ========== #}
{% if cmd.command_type in ['INTROSPECTION','INTROSPECT'] %}
{% set ins = cmd.introspection|default(cmd) %}
{{ icon_db() }} Database introspection
{% if ins.tables %}
Object
Type
Schema
Rows
Size
{% for tbl in ins.tables %}
{{ tbl.name|default(tbl) }}
{{ tbl.type|default('TABLE') }}
{{ tbl.schema|default('—') }}
{% if tbl.row_count is defined %}{{ tbl.row_count }}{% else %}—{% endif %}
{{ tbl.size|default('—') }}
{% endfor %}
{% else %}
{{ icon_db() }}
Introspection complete
{{ cmd.message|default('See raw output below.') }}