{% import "macros.html" as ui %} {# The page of an origin of the schema (`origin`, from databases.origins): a migration set (Flyway, golang-migrate, dbmate, Alembic, Django, Prisma), an SQL file, or an ORM's models (SQLAlchemy, Django, a Prisma schema). Its source, and the schema it ends with, each object to its page. Which databases it describes and where they differ is DATABASES › Diff. #} {% set KINDS = {"flyway": "Flyway migrations", "golang-migrate": "golang-migrate migrations", "dbmate": "dbmate migrations", "dump": "schema dump", "sql file": "SQL file", "sqlalchemy": "SQLAlchemy models", "alembic": "Alembic migrations", "django models": "Django models", "django migrations": "Django migrations", "prisma schema": "Prisma schema", "prisma migrations": "Prisma migrations"} %} {% set DIALECTS = {"postgres": "PostgreSQL", "mysql": "MySQL / MariaDB", "tsql": "SQL Server (T-SQL)", "sqlite": "SQLite"} %} {% macro place(where) -%}{{ where.file.rsplit("/", 1)[-1] }}:{{ where.line }}{%- endmacro %} {# What it ends with, as the store keeps it (the same objects as a live database's, see databases.origins.as_collection): by kind, each to its page; a table's or view's columns in a table. #} {% set declared = origin.declared %} {% set shown = declared | rejectattr("kind", "in", ("database", "schema", "column")) | list %} {% call ui.section("attributes", "Schema it ends with", count=shown | length, name="objects", divider=true) %} {% for title, kinds in db_groups if shown | selectattr("kind", "in", kinds) | list %}

{{ title }}

{% for obj in shown | selectattr("kind", "in", kinds) | sort(attribute="path") %} {% set where = obj.data.declared or {} %}
{{ db_place(obj.path) }} {% if where.created %}created {{ place(where.created) }}{% if where.changed != where.created %} · last changed {{ place(where.changed) }}{% endif %}{% endif %}{% if obj.data.comment %} · {{ obj.data.comment }}{% endif %} {% set columns = declared | selectattr("parent", "equalto", obj.path) | selectattr("kind", "equalto", "column") | list %} {% if columns %} {% for c in columns %}{% endfor %}
ColumnTypeNullDefaultMarks
{{ c.name }}{% if c.data.type %}{{ c.data.type }}{% else %}-{% endif %} {{ "yes" if c.data.nullable else "no" }} {% if c.data.default %}{{ c.data.default }}{% elif c.data.computed %}{{ c.data.computed }} computed{% else %}-{% endif %} {% for mark in c.data.marks or [] if mark != "null" %}{{ db_marks[mark] }}{% else %}-{% endfor %}
{% endif %}
{% endfor %} {% else %}

It declares no object.

{% endfor %} {% endcall %} {# The code itself, as CODE's Source block: each file of the origin in order (a migration's undo folded under it), fetched when shown, in the origin's dialect; what was not read is told by its line. #} {% call ui.section("source", "Source", count=origin.steps | length if origin.steps | length > 1 else none, name="source", divider=true) %} {# Each file folded at first under its title, opened by it (its code fetched then). #} {% for step in origin.steps %}
{% if step.version %}{{ step.version }} · {% endif %}{{ step.title }} {{ step.file.rsplit("/", 1)[-1] }} {% set unread = step.statements | rejectattr("read") | map(attribute="line") | list %} {% if unread %}

Not read: the statement{% if unread | length > 1 %}s{% endif %} at line {{ unread | join(", ") }}.

{% endif %}

Loading…

{% if step.down %}
Undone by {{ step.down.rsplit("/", 1)[-1] }}

Loading…

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