Hakushi.Kits.Schema (Hakushi v0.4.0)

Copy Markdown View Source

The kit of a database schema: tables, with columns that have a name, a type and a key (primary or foreign), and foreign keys drawn from a column to a column of the same type.

A table is a node of type "schema-table" whose data is:

%{
  "name" => "orders",
  "columns" => [
    %{"id" => "c1", "name" => "id", "type" => "uuid", "key" => "pk"},
    %{"id" => "c2", "name" => "customer_id", "type" => "uuid", "key" => "fk"},
    %{"id" => "c3", "name" => "placed_at", "type" => "timestamp", "key" => nil}
  ]
}

Each column has a handle on each side, of the column's type: an edge joins two columns of one type, and takes the sides nearest each other. A column's handles are its "id" (its name, for a column without one), so a foreign key stays when people rename the column. People rename the table and its columns in place, pick a column's type, set its key, and add and remove columns.

In Markdown, a schema is a Mermaid entity relationship diagram: each table with its columns (uuid id PK), and a foreign key as a relationship from its table to the table it refers to, named after its column. from_markdown/1 reads it back, and reads ER diagrams people write: a relationship becomes an edge from the column it names (else the table's first column) to the other table's primary key.

Summary

Functions

The column types people pick from.

Functions

column_types()

@spec column_types() :: [String.t()]

The column types people pick from.