{% import "macros.html" as ui %} {# DATABASES' pages, one view each (`tab`, its address in pages.DATABASE_URLS); Navigate and Diagrams show their two views as tabs. Connections: what the project declares (blocked until allowed) and what the user enters; every form posts to /databases/, the same store the MCP tools use, and the page comes back redrawn; the notes' buttons and modal are reused. Universe: the databases the server read, drawn by static/graph.js (drawUniverse) in the diagrams' frame (Navigate › By Graph). Navigate › By Level: every object read, filtered, one page at a time; a name opens its page in the consultation modal. #} {# A connection's card: its name and state, kind and server; a click on it opens the rest in the consultation modal. Its colour, on the pill and the side, tells the state: green allowed, red blocked; sent again out of band after a change made in its details. #} {% macro card(c, test, oob=False) -%}

{{ ui.icon("database") }}{{ c.name }} {% if c.allowed %}allowed{% else %}blocked{% endif %}

Kind
{{ c.kind_name }}
{% if c.kind == "sqlite" %}File{% else %}Server{% endif %}
{{ c.host or "—" }}{% if c.port %}:{{ c.port }}{% endif %}
{%- endmacro %} {# A cell of the lint's list (the Lint tab and an object's page), or a value of a column's filter (`row` none). #} {% macro lint_cell(row, key, value=none, actions=true) -%} {%- if row is none -%} {%- if key == "level" %}{{ value }}{% else %}{{ value }}{% endif -%} {%- else -%} {%- set value = row[key] -%} {%- if key == "level" %}{{ value }} {%- elif key == "rule" %}{{ ui.help_hover(row.rule, row.help) }}{{ row.rule }} {%- elif key == "object" %}{% if row.origin %}{{ value }} {%- else %}{{ value }}{% endif %} {%- elif key == "found_in" %}{% for place in value %}{{ place }}{% if not loop.last %}
{% endif %}{% endfor %} {%- elif key == "state" %}{% if value == "accepted" %}accepted: {{ row.reason }} {%- if actions %}
{% endif %} {%- else %}open{% if actions %} {% endif %}{% endif %} {%- elif key == "page" %} {%- elif value is none or value == "" or value == [] -%}- {%- else %}{{ value }}{% endif -%} {%- endif -%} {%- endmacro %} {# A cell of a list of links between the code and the databases: an object's Use in the code, a code entity's Database use. #} {% macro code_cell(row, key) -%} {%- set value = row[key] -%} {%- if key == "code" %}{% if row.page %}{{ value }}{% else %}{{ value }}{% endif %} {%- elif key == "objects" %} {%- elif key == "evidence" and value %}{{ value }} {%- elif key == "where" and value %}{{ value }} {%- elif key == "page" %}{% if row.page %}{% else %}-{% endif %} {%- elif value is none or value == "" or value == [] -%}- {%- else %}{{ value }}{% endif -%} {%- endmacro %} {% macro post(action, confirm="", title="") -%} hx-post="/databases/{{ action }}" hx-target="#content"{% if confirm %} hx-confirm="{{ confirm }}"{% endif %}{% if title %} data-confirm-title="{{ title }}"{% endif %} {%- endmacro %}
{# The page of DATABASES this view belongs to (pages.SECTIONS); Navigate and Diagrams hold two views each, as tabs. #} {% set shown = namespace(page=none) %}{% for p in sections.databases.pages if tab in p.tabs %}{% set shown.page = p %}{% endfor %} {{ ui.view_header("database", "DATABASES :: " ~ shown.page.title, shown.page.text) }} {% if shown.page.name == "navigate" %} {{ ui.tabs((("objects", "By Level", db_urls.objects), ("universe", "By Graph", db_urls.universe)), tab) }} {% elif shown.page.name == "diagrams" %} {{ ui.tabs((("diagram", "ER Diagrams", db_urls.diagram), ("slices", "Sub-Diagrams", db_urls.slices)), tab) }} {% endif %} {% if tab == "universe" %}

The databases doctracker read from the allowed connections, as SQL organises them: servers, databases, schemas, tables and views, columns. Click a node to go into it; choose in the legend which relations to see.

{{ ui.universe_canvas(params.open or "", "/graph/universe" if has_collections else "", "" if has_collections else "No database read yet: allow a connection in Connections.") }} {% elif tab == "diagram" %}

The entity-relationship diagram of the databases read and of what the project's files declare, in the levels of the tree: each table and view with its columns, the foreign keys from a column to the column it refers to, with how many rows each end may have. Click a level to open it, its title to close it; choose in the legend which relations to see, and on the bar the notation.

{% set bar_filters %}
{% call ui.form_field("Project", "Only what one project of the repository holds: its connections' databases and its files.", wide=False) %} {% endcall %} {{ ui.pick_field("Focus", "focus", "er-targets", er_targets, value=params.focus or "", placeholder="A database, schema, file or table…", help="A table or view: only it and the tables a few relations away (Depth). A database, schema or file: only what it holds. Type its name or path.") }} {% call ui.form_field("Slice", "A slice of the schema (see Slices): only its tables, where they were placed, without the levels; the tables related to them drawn faded. Ctrl + click adds a table to it or takes one away; Save keeps the tables and where they stand.", wide=False) %} {% endcall %} {% call ui.form_field("Depth", "How many relations away from a focused table: 1 shows only the tables it links to directly.", wide=False) %} {% endcall %}
{% call ui.form_field("Columns", "Which columns the boxes show, by kind: a column shows when it is of any kind chosen (a key column is also indexed, say). Others: the columns of no kind above. Kept for this browser.", choice=True) %} {% for kind, label in (("pk", "Primary key"), ("fk", "Foreign key"), ("unique", "Unique"), ("index", "Indexed"), ("generated", "Generated"), ("other", "Others")) %}{% endfor %}{% endcall %}
{% endset %} {% set er_actions %} {% endset %} {% call ui.view_canvas("er", er_url, params.focus or "", layouts=true, filters=bar_filters, filters_open=true, details=true, notation=true, actions=er_actions, empty="" if er_url else "No database read and no schema file yet: allow a connection in Connections.") %} project connection / file database / schema table view unconnected 3 ▸closed (click to open) {{ ui.relation_kinds(("foreign-key", "implied", "view-reads", "partition-of", "inherits", "foreign-table", "contained-in"), off=("contained-in",)) }} || one · o| zero or one · o< zero or many {% endcall %} {% elif tab == "slices" %}

Slices of the schema: a few tables kept together, cut from the whole — a part of the system with a name and a text saying what it is for, its boxes placed in the Diagram as you left them. Each slice is a file in doc/slices/, versioned with the project; its tables are found where they were taken from, or by their name elsewhere. The agents read them too.

{% if not slices %}

No slice yet: make one with “New slice”, or choose tables in the Diagram (Ctrl + click) and Save as slice.

{% endif %}
{% for s in slices %}

{{ ui.icon("database") }}{{ s.name }} {% set missing = s.tables | rejectattr("found") | list | length %}{% if missing %}{{ missing }} not found{% endif %}

a slice of {{ s.databases | map("replace", "db:", "") | map("replace", "origin:", "") | join(", ") or "nothing read" }}: {{ s.tables | selectattr("found") | list | length }} of {{ s.total }} tables

{% if s.text %}

{{ s.text }}

{% endif %}
{% endfor %}
{% elif tab == "evolution" %}

How the project's schema evolved, from its migrations and its commits: one lane per origin (SQL files, migration sets, ORM models, dumps), each migration step at the commit that brought it, each commit that changed the origin's files; a filled dot is a migration step, a hollow one a commit, a red ring a step changed after it was created. Click a moment to see what it did; Diff compares the schema at two moments.

{% macro moment_options(chosen) -%} {% for lane in evolution.lanes %} {% for m in evolution.moments if m.origin == lane.origin %}{% endfor %} {% endfor %} {%- endmacro %} {% set bar_filters %}
{% call ui.form_field("Origins", "The lanes shown: tick the origins to see (migration sets, schema files, ORM models, dumps), then Apply. None ticked: every lane.", choice=True) %}
{% if params.origin %}{{ params.origin }}{% else %}All origins{% endif %} ▾
{{ evolution.lanes | length }} origins
    {% for lane in evolution.lanes %}
  • {% endfor %}
{% endcall %}
{% endset %} {% set diff_row %}
{% call ui.form_field("A", "The first moment: the schema as it was then (a migration step: the steps up to it applied; a commit: the origin's files as they were). Also chosen by clicking a moment in the drawing while this row is open: the first click is A, the second B.") %} {% endcall %} {% call ui.form_field("B", "The second moment, compared with A: what B has that A had not is added, what it lost removed.") %} {% endcall %} {% call ui.form_field("Show", "Side by side: both schemas, table by table and column by column, what differs marked. Only the differences: what was added, removed or changed.", choice=True) %} {% for value, label in (("only", "Only the differences"), ("side", "Side by side")) %}{% endfor %}{% endcall %}
{% endset %} {% call ui.view_canvas("evolution", "/graph/evolution" if evolution.moments else "", "", filters=bar_filters, details=true, diff=diff_row, empty="" if evolution.moments else "No migrations nor schema files in the project yet.") %} migration step commit step changed after it was created not committed follows (branches and merges) {% endcall %}
{% if params.a and params.b %}

Loading…

{% endif %}
{% elif tab == "diff" %}

Two places compared, each chosen down its trail: a file of the project (its SQL, migrations, ORM models or dump, as it ends once every step is applied) or a database read, a whole one, a schema, or one table or view. Choosing a file fills B with the database it created (by the migration tool's history table, or the configuration naming it); B can be changed to any other place, a staging database say. Two schemas or two tables of different names are compared with each other. Computed when the page opens: nothing is kept.

{% set HOW = {"history": ("by its history", "The database's own history table of this tool records these steps as applied."), "declared": ("by its configuration", "The origin's configuration, or a connection declared in its folder, names this database."), "related": ("through its migrations", "The ORM's migrations created this database: its models describe the same one.")} %} {# One side of the comparison, a form of its own: the kind of place (buttons), then one autocomplete field per level (Focus's: type a part of the name or path, ↑ ↓ and Enter, or a click), each listing what the field before it holds. A choice redraws the page; the fields under a changed one empty (web.diff_context). #} {% macro diff_side(side, label) -%} {% set boxes = diff_trails[side] %}
Trail {{ label }}
{% if side == "b" %}{% endif %}
{% set kinds = [] %}{% for key, name in diff_groups %}{% set _ = kinds.append({"path": key, "name": name, "role": "kind-" ~ key}) %}{% endfor %} {{ ui.pick_field("Kind of " ~ label, "g" ~ side, "diff-kind-" ~ side, kinds, value=diff_group[side], placeholder="Kind…", required=true, icon=true, clearable=false) }}› {% for box in boxes %} {% if not loop.first %}›{% endif %} {{ ui.pick_field(box.title, side ~ loop.index0, "diff-" ~ side ~ "-" ~ loop.index0, box.options, value=box.picked, placeholder=box.placeholder, required=loop.first, all=not loop.first) }} {% endfor %}
{% if side == "b" %} {% if diff_a and diff_b == diff_start.b and diff_start.how %}

Created by {{ "/".join(diff_a.removeprefix("origin:").partition("::")[0].split("/")[-2:]) }}, {% for how in diff_start.how %}{{ HOW[how][0] }}{% endfor %} {% if diff_start.history %}{% set h = diff_start.history %} · {{ h.applied }} of {{ h.steps }} steps applied (version {{ h.version }}) {%- if h.pending %} · pending: {% for step in h.pending %}{{ step }}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %} {%- if h.changed %} · changed since applied: {% for step in h.changed %}{{ step }}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %} {%- if h.failed %} · failed: {{ h.failed | join(", ") }}{% endif %}{% endif %}

{% endif %} {% endif %}
{%- endmacro %}
{{ ui.tabs((("trails", "Trails", "/databases/diff?view=trails"), ("profiles", "Saved profiles", "/databases/diff?view=profiles")), diff_view) }}
{% if diff_view == "profiles" %} {% if not diff_profiles %}

No profile yet: compare two places in Trails, then Save profile.

{% endif %}
{% for s in diff_profiles %}

{{ ui.icon("diff") }}{{ s.name }}

{{ s.names.a }} × {{ s.names.b }}{% if s.ignore %} · ignoring {{ s.ignore | join(", ") }}{% endif %}

{% if s.description %}

{{ s.description }}

{% endif %}
{% endfor %}
{% else %} {% if diff_a and diff_b %}
{% if diff_profile %}Profile {{ diff_profile.name }}{% if diff_ignore %} · ignoring {{ diff_ignore | join(", ") }}{% endif %} {% else %}This comparison is not saved. {% endif %}
{% endif %}
{{ diff_side("a", "A") }}{{ diff_side("b", "B") }}
{% endif %}
{% if diff_view == "trails" %} {% if not diff_a %}

Choose A: a file of the project or a database.

{% elif not diff_b %}

Nothing says which database {{ diff_a.removeprefix("origin:") }} created: choose B.

{% elif diff.error %}

{{ diff.error }}

{% else %} {% set base = "/databases/diff?view=trails&a=" ~ (diff_a | urlencode) ~ "&b=" ~ (diff_b | urlencode) ~ "&show=" %}
{% set shown = diff.tabs[diff_show] %} {% for t in shown.tables %}

{% if t.a or t.b %}{{ t.key }}{% else %}{{ t.key }}{% endif %} {{ t.kind }}{% if t.whole %} · only in {{ diff_names.a if diff_show == "only_a" else diff_names.b }}{% endif %} {% if t.commits %}{{ ui.icon("database") }}Evolution{% endif %}

{{ ui.diff_lines(t.lines, diff_names.a, diff_names.b) }} {% if t.commits %}

Commits: {% for c in t.commits %}{{ c.short }}{% endfor %}

{% endif %}
{% else %}

Nothing here: {% if diff_show == "only_a" %}{{ diff_names.b }} holds everything {{ diff_names.a }} holds{% elif diff_show == "only_b" %}{{ diff_names.a }} holds everything {{ diff_names.b }} holds{% else %}what both hold is the same{% endif %}.

{% endfor %}
{% endif %} {% endif %} {% elif tab == "lint" %}

What in the databases' schema and in the project's migrations deserves a look: tables without a primary key, foreign keys without an index, relations only by name, destructive migration steps, and more — each rule's ? says why it matters and how to fix it. The databases read and the project's files are linted alike; the same finding in several of them is one row, Found in telling where. A finding you accept, with its reason, stays listed as accepted (the State filter shows it), kept in doc/lint/accepted.json with the project.

{# The counters of the open findings, by level and by rule: a click lists only those. #}
{% for level, count in lint_levels %}{{ "{:,}".format(count) }} {{ level }}{% if count != 1 %}s{% endif %}{% endfor %} {% if lint_accepted %}{{ lint_accepted }} accepted{% endif %} {% for r in lint_rules %}{{ ui.help_hover(r.title, r.help) }}{{ r.title }} {{ "{:,}".format(r.count) }}{% endfor %}
{% set label %}{{ "{:,}".format(listing.total) }} finding{% if listing.total != 1 %}s{% endif %}{% endset %} {% call(row, key, value) ui.list_table("lint", "#lint-filter", listing, label, db_urls.lint) %}{{ lint_cell(row, key, value) }}{% endcall %} {% elif tab == "objects" %}

Every object doctracker read from the allowed connections. Browse goes down the SQL tree one level at a time (servers, databases, schemas, tables and views, columns): a name goes into it, the path above goes back. Search lists every object at once. A column's title sorts by it, its filter icon filters it; the page icon opens the object's page.

{# The mode, and what goes with every request of the list: the level (Browse) or the filters above (Search), the order chosen (sort, dir). #}
{% for name, label, tip in (("browse", "Browse", "One level of the SQL tree at a time: servers, databases, schemas, tables and views, columns"), ("search", "Search", "Every object read at once, filtered by database, schema, kind and name")) %} {% endfor %}
{% if mode == "browse" %} {# The path: each level a box listing every option it has under what is ticked above it, with what each holds, to tick one or more and Apply (as the columns' filters); the list shows the level under the last part ticked. ← takes away the deepest ticks. #} {% else %} {% if chosen.within and not chosen.database %}{% endif %} {% call ui.form_field("Database", "The database to list: its schemas and everything in them. All: every database read.", wide=False) %} {% endcall %} {% call ui.form_field("Schema", "The schema to list, within the database chosen. All: every schema.", wide=False) %} {% endcall %} {% call ui.form_field("Kind", "Only objects of this kind: tables, views, columns, functions, triggers, sequences, types... All: every kind.", wide=False) %} {% endcall %} {% call ui.form_field("Name", "Only objects whose name holds this text, in any case.", extra="objects-name") %} {% endcall %} {% endif %}
{% if not has_collections %}

No database read yet: allow a connection in Connections.

{% else %} {% set label %}{{ listing.total }} {% if mode == "browse" %}{{ level if listing.total != 1 else level[:-1] }}{% else %}object{% if listing.total != 1 %}s{% endif %}{% endif %}{% endset %} {% call(row, key, value) ui.list_table("objects", "#objects-filter", listing, label, db_urls.objects) %} {%- if row is none -%} {%- if key == "size" %}{{ value | int | size }}{% elif key == "read" %}{{ value | local_time(seconds=True) }}{% elif key == "marks" %}{{ db_marks.get(value, value) }}{% else %}{{ value }}{% endif -%} {%- else -%} {%- set value = row[key] -%} {%- if key == "name" -%} {%- if row.down %}{{ row.name }} {%- else %}{{ row.name }}{% endif -%} {%- elif key == "page" -%} {%- elif value is none or value == "" or value == [] -%}- {%- elif key == "marks" -%}{% for mark in value %}{{ db_marks[mark] }}{% endfor %} {%- elif key == "size" -%}{{ value | size }} {%- elif key == "read" -%}{{ value | local_time(seconds=True) }} {%- elif key in ("type", "default") -%}{{ value }} {%- elif key == "where" -%}{{ value }} {%- elif value is number -%}{{ "{:,}".format(value) }} {%- else -%}{{ value }}{%- endif -%} {%- endif -%} {% endcall %} {% endif %} {% else %}

The databases your project declares, and those you enter. Declared ones stay blocked until you allow them; doctracker only ever reads: the session is read only where the database allows it, every transaction is rolled back, and any statement that is not a read is aborted before it is sent.

{% if error %}

{{ error }}

{% endif %} {% if locked %} {# No vault on this system: the saved passwords open with a master password, typed once per start. #}
This system has no vault for the key of the saved passwords. Type the master password{% if not has_secrets %} you want to use{% endif %}:
{% endif %}
{% if not connections %}

Nothing found in the project's files. Enter a connection with “New connection”.

{% endif %}
{% for c in connections %}{{ card(c, tests.get(c.id)) }}{% endfor %}
{% if open_connection %}{# reached from the tree: the connection's details open at once #} {% endif %} {% endif %}