{% import "macros.html" as ui %} {% from "database.html" import code_cell, lint_cell %} {# The page of a database object (`item`, from CatalogStore.object): a server, database, schema, table, view, column, function, trigger..., read from a live database or declared by a file (origin:...): the same page, from the same store, the header telling which (read from the live database / declared in file:line). Folding sections from the general to the specific, those that apply to its kind; what is not known of it, or what later steps of DATABASES fill, says "Data unavailable". Empty cells of a table show "-". Names link to their own pages (in the consultation modal too, as the code's pages do). The Universe opens in the page itself, in its own section, on this object; in the modal, its footer has Close, Universe and Open the page, the only one that leaves for another screen. #} {% set kind = item.kind %} {% set source = "file" if item.declared else "database" %}{# who says what the page shows #} {% set data = item.data %} {% set tabular = kind in ("table", "view", "materialized view", "foreign table") %} {% macro link(path, name) -%}{{ name }}{%- endmacro %} {% macro unavailable(reason) -%}
Data unavailable: {{ reason }}
{%- endmacro %} {% macro marks(found) -%} {% for mark in (found.marks or []) %}{% if mark != "null" %}{{ db_marks[mark] }}{% endif %}{% endfor %} {%- if found.nullable is defined and not found.nullable %}not null{% endif %} {%- endmacro %} {# Sample the table again now (a live one's): the page follows by itself once it is read. #} {% macro sample_again(table) -%} {% if item.read %}{% endif %} {%- endmacro %} {% macro sampled(found) -%}{{ "{:,}".format(found.rows) }} rows taken at random{% if found.read %} · {{ found.read | local_time(seconds=True) }}{% endif %}{%- endmacro %} {% set drawn = kind in ("server", "database", "schema", "table", "view", "materialized view", "foreign table", "column") %} {% set table_list = "/databases/navigate/level?mode=browse&at=" ~ (item.path | urlencode) %}{% for path, name in item.crumbs %}{{ name }}›{% endfor %}
See in {{ universe_button }}{% if item.kind in ("database", "schema", "table", "view", "materialized view", "foreign table") %}{{ ui.icon("database") }}Diagram{% endif %}{% if item.path.startswith("db:") and (kind in ("server", "database", "schema") or tabular) %}{{ ui.icon("database") }}Navigate{% endif %}
{% endif %}{{ data.comment }}
{% else %}The {{ source }} holds no comment on it.
{% endif %} {% endcall %} {% if drawn %} {# The Universe opened on it, drawn only once its section opens (Universe in the header or the footer). #} {% call ui.section("class", "Universe", name="universe", divider=true, open=false) %} {# Drawn from the live databases, or from what this object's file declares. #} {% endcall %} {% endif %} {% if kind in ("server", "database", "schema") %} {# What it holds, by kind, each a link. #} {% for group_kind, children in item.children | groupby("kind") %} {% call ui.section("attributes", group_kind ~ "s", count=children | length, name="holds-" ~ group_kind, divider=true) %}| Name | Type | Default | Marks | Comment |
|---|---|---|---|---|
{{ link(column.path, column.name) }} | {% if column.data.type %}{{ column.data.type }}{% else %}-{% endif %} |
{% if column.data.default %}{{ column.data.default }}{% elif column.data.computed %}{{ column.data.computed }} computed{% else %}-{% endif %} |
{% set column_marks = marks(column.data) | trim %}{{ column_marks if column_marks else "-" }} | {{ column.data.comment or "-" }} |
No columns read.
{% endif %} {% endcall %} {% if kind != "view" and kind != "materialized view" %} {% call ui.section("attributes", "Keys and constraints", name="keys", divider=true) %}{{ data.primary_key.columns | join(", ") }}{% if data.primary_key.name %} {{ data.primary_key.name }}{% endif %}{% else %}none{% endif %}{{ key.columns | join(", ") }} → {{ link(key.target, db_place(key.target)) }} ({{ key.target_columns | join(", ") }})
{% for option, value in key.options.items() %} {{ option | replace("on", "ON ") | upper }} {{ value }}{% endfor %}{% if key.name %} {{ key.name }}{% endif %}{{ unique.columns | join(", ") }}{% if unique.name %} {{ unique.name }}{% endif %}{{ check.check }}{% if check.name %} {{ check.name }}{% endif %}{{ index.name }} on {{ (index.columns + index.expressions) | join(", ") }}{% if index.unique %} unique{% endif %}No indexes.
{% endif %} {% endcall %} {% endif %} {% endif %} {% if kind == "column" %} {% call ui.section("attributes", "Type and constraints", name="type", divider=true) %}{{ data.type }}{{ data.default }}{{ data.computed }}{{ value | join(", ") }}{% else %}{{ value }}{% endif %}No relations read.
{% endfor %} {% endcall %} {% endif %} {% if tabular %} {% set triggers = item.children | selectattr("kind", "equalto", "trigger") | list %} {% call ui.section("function", "Behaviour", count=triggers | length, name="behaviour", divider=true) %} {% if triggers %}{{ trigger.data.definition }}{% endif %}No triggers.
{% endif %} {{ unavailable("rules, row security policies and grants are not read yet.") }} {% endcall %} {% call ui.section("attributes", "Physical structure", name="physical", divider=true) %}{{ data.partition_bound }}{% endif %}{{ data.partitioning }}{{ part.name }} {{ part.bound or "" }}{{ d.origin }}
{{ d.kind }} · created {{ d.object.created.file.rsplit("/", 1)[-1] }}:{{ d.object.created.line }}{% if d.object.changed != d.object.created %} · last changed {{ d.object.changed.file.rsplit("/", 1)[-1] }}:{{ d.object.changed.line }}{% endif %}As the files say.
{% endif %}No origin linked to this database declares it.
{% endfor %} {% endcall %} {% endif %} {% if item.found_in is defined %} {# Its mirror, on what a file declares: where it is in the live databases its file describes, and where they differ. #} {% call ui.section("source", "Found in", count=item.found_in | length, name="found-in", divider=true) %} {% for d in item.found_in %}{{ db_place(d.path) }}
linked by {{ d.how | join(", ") }}As the database has it.
{% endif %}No database its file describes holds it.
{% endfor %} {% endcall %} {% endif %} {% if tabular or kind in ("function", "procedure", "aggregate", "trigger") %} {% call ui.section("source", "Definition", name="definition", divider=true) %} {% if data.definition %}{{ data.definition }}
{% elif item.declared %}{{ unavailable("the file gives no definition of it but its statements, in its file's Source.") }}
{% else %}{{ unavailable("the database gives no definition of it; the files declaring it are in Declared by.") }}{% endif %}
{% endcall %}
{% endif %}
{% if tabular %}
{# Its sample, one line per column: the column, and beside it the values taken at random (each once,
a sensitive column's masked: each letter and digit as *). #}
{% set sample = item.sample %}
{% call ui.section("attributes", "Sample", count=(sample.columns or []) | length, name="sample", divider=true) %}
{% if sample.unavailable %}{{ unavailable(sample.unavailable) }}
{% else %}
{{ sampled(sample) }}; each column's values shown once, at most 20, sensitive ones masked.
{% if sample.rows %}| Column | Sample |
|---|---|
{{ link(item.path ~ "." ~ name, name) }}{% if found.sensitive %} sensitive{% endif %} |
{% for value in found["values"] %}{{ value }}{% else %}-{% endfor %} |
The table holds no rows.
{% endif %} {% endif %} {{ sample_again(item.path) }} {% endcall %} {% endif %} {% if kind == "column" %} {# What its sampled values show: the profile, a sensitive column's values masked. #} {% set found = item.profile %} {% call ui.section("attributes", "Data", name="data", divider=true) %} {% if found.unavailable %}{{ unavailable(found.unavailable) }} {% else %}{{ found.min }}{% else %}-{% endif %}{{ found.max }}{% else %}-{% endif %}{{ value }} {{ count }}×{% if not loop.last %}, {% endif %}{% else %}-{% endfor %}{{ value }}{% if not loop.last %} {% endif %}{% else %}-{% endfor %}No code of the project is found using it.
{% endif %} {% endcall %} {% if tabular %}{% call ui.section("warns", "Lint", count=item.lint | length, name="lint", divider=true) %} {% if item.lint %}{% call(row, key, value) ui.list_table("lint-object", "", item.lint_listing, "", interactive=False) %}{{ lint_cell(row, key, value, actions=false) }}{% endcall %}{{ ui.icon("database") }}Lint lists every finding, to accept one saying why.
{% else %}The lint finds nothing in it.
{% endif %} {% endcall %}{% endif %} {% call ui.section("warns", "History", name="history", divider=true) %}{{ unavailable("the history from migrations and commits comes in a later step.") }}{% endcall %} {% endif %}