Cardbox's tables, in versions, for the migrations of your app.
$ mix cardbox.gen.migration
writes a migration that pins the latest version:
defmodule MyApp.Repo.Migrations.AddCardbox do
use Ecto.Migration
def up, do: Cardbox.Migrations.up(version: 1)
def down, do: Cardbox.Migrations.down(to: 0)
endA later Cardbox that changes the tables has a new version, and
mix cardbox.gen.migration writes the migration that takes them there,
from the version your migrations already pin:
def up, do: Cardbox.Migrations.up(version: 2)
def down, do: Cardbox.Migrations.down(to: 1)So a migration, once written, does the same thing whichever Cardbox
runs it: your history is the same for a new developer, in CI and in
production. The version a database is at is kept in a table of one row,
cardbox_schema, and up/1 runs only the versions after it, so the
migrations of an app that made the tables another way run once.
The versions run on PostgreSQL and on SQLite.
Versions
- The five tables:
cardbox_collections,cardbox_fields,cardbox_records(the values a JSON map, with a GIN index and a trigram index of the search text on PostgreSQL),cardbox_linksandcardbox_views.
Summary
Functions
:ok when the tables of a repo are at the latest version, else an
error that says which migration to write: for a release check, or a
health check of your app.
Takes the tables back down to :to (0, no tables, unless given). Call
it in a migration.
The latest version of Cardbox's tables.
The version the tables of a repo are at: 0 before Cardbox's migration
has run.
Takes the tables up to :version (the latest unless given: pin it, as
mix cardbox.gen.migration does). Call it in a migration.
Functions
@spec check(Ecto.Repo.t()) :: :ok | {:error, String.t()}
:ok when the tables of a repo are at the latest version, else an
error that says which migration to write: for a release check, or a
health check of your app.
@spec down(keyword()) :: :ok
Takes the tables back down to :to (0, no tables, unless given). Call
it in a migration.
@spec latest_version() :: pos_integer()
The latest version of Cardbox's tables.
@spec migrated_version(Ecto.Repo.t()) :: non_neg_integer()
The version the tables of a repo are at: 0 before Cardbox's migration
has run.
@spec up(keyword()) :: :ok
Takes the tables up to :version (the latest unless given: pin it, as
mix cardbox.gen.migration does). Call it in a migration.