{# The modals of DATABASES: a lint finding, a slice, what a use of the code reaches, and those of Connections. `details`: everything about one connection (the card shows only its kind and server), in the consultation modal; with `editing`, its settings become the form's fields. Its actions sit in the modal's footer (sent out of band, as an entity's page does); they answer in the modal, the card following; Delete asks first, over the modal, then the page comes back and the modal closes. Without `details`: a new connection, in the notes' modal, posted to /databases/save. The details also show what was last read from the connection's database: the server reads it by itself while the connection is allowed; Refresh, in the footer, reads it again now. Every field is the wiki's form field (macros.form_field): ? with its explanation, outlined, * if required. #} {% import "macros.html" as ui %} {% from "database.html" import card %} {% set HELP = { "Name": "The name this connection is shown by, in DATABASES and to the agents. Only for you to recognise it; it changes nothing in the connection.", "Kind": "The kind of database. It decides the driver doctracker uses (pg8000, PyMySQL, python-tds, Python's sqlite3, oracledb) and how the session is made read only.", "Host": "The database server's name or address (for SQLite, the file's path, from the project's root). When the connection goes through SSH, it is the server as the SSH server sees it, e.g. a name inside its network. Any value may be ${VARIABLE} or ${VARIABLE:-default}, read from the environment and the project's .env files when connecting.", "Port": "The database server's port. Empty: the kind's usual one (PostgreSQL 5432, MySQL 3306, SQL Server 1433, Oracle 1521). May be ${VARIABLE}.", "Server": "Address and port of the database server. Any value may be ${VARIABLE} or ${VARIABLE:-default}, read from the environment and the project's .env files when connecting.", "File": "The SQLite file, from the project's root. It is opened read only.", "Database": "Name of the database on the server. Empty: every database the user can see on the server is read (each one doctracker can connect to).", "User": "The user doctracker connects as. A read-only user is best; whatever the user may do, doctracker only reads. May be ${VARIABLE}.", "Password": "The user's password. Typed here, it is saved encrypted in doc/connections/ (out of git), the key kept in your system's vault; or write ${VARIABLE} to take it from an environment variable. Never shown afterwards: once saved, empty keeps it. Not asked with AWS RDS IAM, whose token takes its place.", "SSH host": "An SSH server to go through: doctracker logs in to it and reaches the database from there. Empty: no tunnel, straight to the database.", "SSH port": "The SSH server's port. Empty: 22.", "SSH user": "The user on the SSH server. Empty: taken from ~/.ssh/config when that is ticked.", "Key file": "The private key to log in to the SSH server, e.g. ~/.ssh/id_ed25519 (a path from the project's root, or absolute). Empty: the password below, or your SSH agent's keys.", "SSH password": "The SSH user's password, or, when there is a key file, the key's passphrase. Saved encrypted like the database password, or ${VARIABLE}. Empty keeps the one saved.", "Jump host": "An SSH server reached first, to get to the SSH server above (a bastion): user@host:port. Empty: none.", "~/.ssh/config": "Ticked: whatever is not typed here (host name, port, user, key, jump host) comes from your ~/.ssh/config, by the SSH host's name.", "Sign-in": "How doctracker signs in: with the password, or with an AWS RDS IAM token made for this server and user (it needs doctracker's extra: pip install doctracker[aws]).", "AWS region": "Only for AWS RDS IAM: the region of the database, e.g. us-east-1. Empty: the one AWS's own settings give.", "SSH": "An SSH server the connection goes through: doctracker logs in to it, with a key or a password, and reaches the database from there. A jump host is reached first. With ~/.ssh/config, what is not typed comes from your SSH settings.", "URL in": "The environment variable holding the whole connection URL, read when connecting.", "From": "Where the connection is declared (file and line), or that it was entered here.", "Database read": "What doctracker read from the database's catalog, read only: every schema of the connection's database, with its tables, views, columns, keys, indexes, functions, triggers, comments and statistics, and the relations between them. Read by itself while the connection is allowed (when allowed, when doctracker starts, and every minute); Refresh reads it again now. Only this last reading is kept. What could not be read (permissions, statistics never gathered) is listed, never guessed. With no database named, every database on the server is read; with one named, the others on the same server are only listed.", "Last test": "The last test, read only: connect, read the server's version, try a write that must be aborted before it reaches the database; with when it ran and how long it took.", } %} {# A name in the details (not a form), with the ? explaining it. #} {% macro label(name) -%}
{{ ui.help_hover(name, HELP[name]) }}{{ name }}
{%- endmacro %} {# The fields of a connection, the same in the New form and when changing one (`c`); a new one also has its name and kind. #} {% macro connection_fields(c) -%} {% set sqlite = c and c.kind == "sqlite" %} {% if not c %} {% call ui.form_field("Name", HELP["Name"], required=True) %}{% endcall %} {% call ui.form_field("Kind", HELP["Kind"], required=True) %}{% endcall %} {% endif %}
{% call ui.form_field("File" if sqlite else "Host", HELP["File" if sqlite else "Host"], required=True) %}{% endcall %} {% if not sqlite %}{% call ui.form_field("Port", HELP["Port"]) %}{% endcall %}{% endif %}
{% if not sqlite %} {% call ui.form_field("Database", HELP["Database"]) %}{% endcall %} {% call ui.form_field("User", HELP["User"], required=True) %}{% endcall %} {% call ui.form_field("Password", HELP["Password"], required=True, extra="password-only") %}{% endcall %}
SSH tunneloptional{% if c and c.ssh_host %} · {{ c.ssh_user ~ "@" if c.ssh_user }}{{ c.ssh_host }}{% endif %}
{% call ui.form_field("SSH host", HELP["SSH host"]) %}{% endcall %} {% call ui.form_field("SSH port", HELP["SSH port"]) %}{% endcall %}
{% call ui.form_field("SSH user", HELP["SSH user"]) %}{% endcall %} {% call ui.form_field("Key file", HELP["Key file"]) %}{% endcall %} {% call ui.form_field("SSH password", HELP["SSH password"]) %}{% endcall %} {% call ui.form_field("Jump host", HELP["Jump host"]) %}{% endcall %} {% call ui.form_field("~/.ssh/config", HELP["~/.ssh/config"]) %} complete what is not typed from ~/.ssh/config{% endcall %}
{% call ui.form_field("Sign-in", HELP["Sign-in"], choice=True) %}{% for key, title in sign_ins.items() %}{% endfor %}{% endcall %} {% call ui.form_field("AWS region", HELP["AWS region"], extra="aws-only") %}{% endcall %}
{% endif %} {%- endmacro %} {% if lint_mode %} {# A finding of the lint accepted: what it is, and why it is accepted (required); in the notes' modal, posted to /databases/lint-accept. #}

Accept finding

{% if finding %}
{% if error %}

{{ error }}

{% endif %}

{{ finding.level }} {{ finding.title }}: {{ finding.object }} — {{ finding.detail }}

Found in {% for place in finding.found_in %}{{ place | replace("db:", "") | replace("origin:", "") }}{% if not loop.last %}, {% endif %}{% endfor %}

{% call ui.form_field("Reason", "Why this finding is accepted as it is (e.g. a log table that needs no primary key, a rename already deployed with its code). It is kept with the finding in doc/lint/accepted.json, versioned with the project, and the agents read it: say it so whoever comes later understands.", required=True) %} {% endcall %}
{% else %}

This finding is no longer found: the lint was read again.

{% endif %} {% elif reaches_mode %} {# What one use of a code entity reaches (its Database use's Reaches), in the consultation modal: the use itself, then the places holding the table or column, the live databases apart from the files. #} {% if link %}
Where
{{ link.where }}
Confidence
{{ link.confidence }}
How
{{ link.how }}
Evidence
{{ link.evidence }}
{% for group, title in (("live", "In the live databases"), ("files", "Declared in the project's files")) %} {% call ui.section("source", title, count=places[group] | length, name="reaches-" ~ group, divider=true) %} {% if places[group] %} {% for p in places[group] %}{% endfor %}
{{ "Database" if group == "live" else "File" }}Object
{{ p.where }}{{ p.object }}
{% else %}

None.

{% endif %} {% endcall %} {% endfor %} {% else %}

This use is no longer found: the code was read again.

{% endif %} {% elif diff_profile_mode %} {# A comparison of DATABASES › Diff kept as a profile, in doc/diff/: its name, what it is for and what it leaves out; A and B are the comparison shown in Trails. A saved one is changed in place (`previous`). #} {% set p = profile %} {% set chosen_ignore = form.ignore if form.ignore is defined else (p.ignore if p else []) %} {% if details %} {# Its details, in the consultation modal: everything it keeps and what its comparison finds now. #} {% if p.description %}
{{ p.description | markdown | safe }}
{% endif %}
A
{{ p.a }}
B
{{ p.b }}
Ignores
{% for key in p.ignore %}{{ ignorable[key] }}{% if not loop.last %}, {% endif %}{% else %}-{% endfor %}
{% if counts.error %}
Comparison
{{ counts.error }}
{% else %}
Only in A
{{ counts.only_a }}
Only in B
{{ counts.only_b }}
Differences
{{ counts.different }}
{% endif %}
Created
{{ p.created | local_time }}
Changed
{{ p.changed | local_time }}
{% else %} {% macro profile_fields() -%} {% if error %}

{{ error }}

{% endif %}

Compares {{ a.removeprefix("db:").removeprefix("origin:") }} with {{ b.removeprefix("db:").removeprefix("origin:") }}.

{% call ui.form_field("Name", "The profile's name, as Saved profiles and the agents show it. Its file in doc/diff/ is named after it.", required=True) %}{% endcall %} {% call ui.form_field("Description", "What the comparison is for: production against staging before a deploy, the migrations against the database they created... The agents read it.") %}{% endcall %} {% call ui.form_field("Ignore", "What the comparison leaves out: the checks, the comments or the indexes, when one side does not keep them the way the other does.", choice=True, named=True) %} {% for key, label in ignorable.items() %}{% endfor %}{% endcall %} {%- endmacro %} {% if p %} {# A saved one, edited in the consultation modal, as a slice is: Cancel goes back to its details. #}
{{ profile_fields() }}
{% else %}

Save as a profile

{{ profile_fields() }}
{% endif %} {% endif %} {% elif slice_mode %} {# A slice of the schema: its details in the consultation modal (its text, its tables as found now, Open in Diagram, Edit, Delete), or its form — name, text, the tables ticked in the box of ticks (searched), and a table with its neighbours to start from — in the same modal; a new slice's form in the notes' modal. #} {% set SLICE_HELP = { "Name": "The slice's name, as the Slices tab, the Diagram and the agents show it. Its file in doc/slices/ is named after it.", "Text": "What the slice is for, in Markdown: the part of the system its tables make, how they are used, what to know about them. The agents read it with the tables.", "Tables": "The tables and views the slice holds, from any database read or any of the project's files (type to search, tick, then Apply). In the Diagram, Ctrl + click adds or takes away a table too.", "Start from": "A table, and the tables its keys and views reach a few steps away (Steps): Add ticks them all in Tables, beside what is ticked already.", } %} {% set s = slice %} {% set chosen_paths = chosen | map(attribute="path") | list %} {% macro slice_fields() -%} {% if error %}

{{ error }}

{% endif %} {% if s %}{% endif %} {% call ui.form_field("Name", SLICE_HELP["Name"], required=True) %}{% endcall %} {% call ui.form_field("Text", SLICE_HELP["Text"]) %}{% endcall %} {% call ui.form_field("Tables", SLICE_HELP["Tables"], required=True, choice=True) %}
{{ chosen_paths | length }} table{{ "s" if chosen_paths | length != 1 }} ticked ▾
{{ choices | length }} tables and views
{% endcall %} {% for t in choices %} {% call ui.form_field("Start from", SLICE_HELP["Start from"]) %} {% endcall %} {%- endmacro %}
{% if s and not editing %} {% if s.text %}
{{ s.text | markdown }}
{% endif %} {% for t in s.tables %}{% endfor %}
TableWhereFound
{% if t.found %}{{ t.key }}{% else %}{{ t.key }}{% endif %} {% if t.found %}{{ t.found.split("::")[0] if "::" in t.found else "/".join(t.found.split("/")[:2]) }}{% else %}-{% endif %} {% if t.found_by == "path" %}where it was taken from{% elif t.found_by == "name" %}by its name (taken from {{ t.path }}){% else %}not found{% endif %}
{% elif s %}
{{ slice_fields() }}
{% else %}

New slice

{% for t in chosen if t.x is defined %}{% endfor %} {{ slice_fields() }}
{% endif %}
{% elif details %} {% set c = details %} {% if error %}

{{ error }}

{% endif %} {% if editing %}
{{ connection_fields(c) }}
{% else %}
{{ label("Kind") }}
{{ c.kind_name }}
{% if c.kind == "sqlite" %} {{ label("File") }}
{{ c.host }}
{% else %} {{ label("Server") }}
{{ c.host or "—" }}{% if c.port %}:{{ c.port }}{% endif %}
{{ label("Database") }}
{% if c.database %}{{ c.database }}{% else %}—{% endif %}
{{ label("User") }}
{% if c.user %}{{ c.user }}{% else %}—{% endif %}
{{ label("Password") }}
{{ c.password or "none" }}
{{ label("SSH") }}
{% if c.ssh_host %}{% if c.ssh_user %}{{ c.ssh_user }}@{% endif %}{{ c.ssh_host }}:{{ c.ssh_port or 22 }}{% if c.ssh_jump %} via {{ c.ssh_jump }}{% endif %}{% if c.ssh_key %} · key {{ c.ssh_key }}{% endif %}{% if c.ssh_password %} · {{ c.ssh_password }}{% endif %}{% if c.ssh_config %} · ~/.ssh/config{% endif %} {% else %}none: straight to the server{% endif %}
{{ label("Sign-in") }}
{{ sign_ins.get(c.sign_in or "password") }}{% if c.sign_in_option %} · {{ c.sign_in_option }}{% endif %}
{% endif %} {% if c.url_variable %}{{ label("URL in") }}
${{ "{" }}{{ c.url_variable }}{{ "}" }}
{% endif %} {{ label("From") }}
{% if c.source == "entered" %}entered here{% else %}{{ c.source }} · {{ c.origin }}{% if c.edited %} · changed here{% endif %}{% endif %}
{{ label("Last test") }}
{% if not test %}{% if c.allowed %}not tested yet{% else %}blocked: allow it to test it{% endif %} {% elif test.ok %}Read only: connected{% if test.version %} to {{ test.version }}{% endif %}; the write tried was aborted{% if test.read_only_session %}; the session is read only{% endif %}{% if test.can_write %}; this user may write, doctracker still only reads{% endif %}. · {{ test.tested_at | local_time(seconds=True) }} ({{ test.seconds }} s) {% else %}Failed: {{ test.error }} · {{ test.tested_at | local_time(seconds=True) }} ({{ test.seconds }} s){% endif %}
{% set k = collection %} {{ label("Database read") }}
{% if not k %}{% if c.allowed %}being read: it shows here in a moment{% else %}blocked: allow it to read it{% endif %} {% else %} {% if k.failure %}Reading it again failed: {{ k.failure.error }} · {{ k.failure.started | local_time(seconds=True) }}{% if k.started %}
Shown: the reading before.{% endif %}{% endif %} {% if k.started %} {% if k.database %}{{ k.database }}{% else %}every database{% endif %} on {{ k.server }} · {{ k.started | local_time(seconds=True) }} ({{ k.seconds }} s) {% endif %} {% endif %}
{% endif %} {% if oob %}{{ card(c, test, oob=True) }}{% endif %} {% else %}

New connection

{{ connection_fields(None) }}
{% endif %}