DrinkMeAlice.Ash.Schema (drink_me_alice v0.1.0)

Copy Markdown

SurrealQL DDL for resources using DrinkMeAlice.Ash.DataLayer, shaped as DrinkMeAlice.Migrations migrations.

migrations = [
  DrinkMeAlice.Ash.Schema.migration(1, "crew", [MyApp.Crew.Seat, MyApp.Crew.Mission])
]
:ok = DrinkMeAlice.Admin.migrate(root_config, migrations)

Per resource: DEFINE TABLE <t> SCHEMAFULL, one DEFINE FIELD per non-primary-key attribute (option<T> when allow_nil?), and a UNIQUE index per identity. The primary key is the record id, not a field. Migrations are append-only: once a version is applied its statements are checksummed, so a changed resource needs a NEW migration (e.g. DEFINE FIELD … OVERWRITE), never an edited one.

Summary

Functions

DDL for a graph edge table (TYPE RELATION), for use with DrinkMeAlice.Graph. fields is [{name, surreal_type}].

A migration map for resources (raises on an unsupported attribute type).

The DDL statements for one resource.

Like statements/1, raising on error.

Functions

edge_statements(edge, from_table, to_table, fields \\ [])

@spec edge_statements(binary(), binary(), binary(), [{binary(), binary()}]) :: [
  binary()
]

DDL for a graph edge table (TYPE RELATION), for use with DrinkMeAlice.Graph. fields is [{name, surreal_type}].

migration(version, name, resources)

A migration map for resources (raises on an unsupported attribute type).

statements(resource)

@spec statements(module()) :: {:ok, [binary()]} | {:error, term()}

The DDL statements for one resource.

statements!(resource)

Like statements/1, raising on error.