View Source ActiveMemory.Adapters.Mnesia.Migration (ActiveMemory v0.8.2)
Migrations will get run on app startup and are designed to modify :mnesia's schema.
table-copies
Table Copies
In the options of an ActiveMemory.Table, the copy type and nodes which should have them can be specified.
ram-copies
Ram copies
Tables that only reside in ram on the nodes specified. The default is node()
Example table using default setting:
defmodule Test.Support.Dogs.Dog do
use ActiveMemory.Table,
options: [compressed: true, read_concurrency: true]
.
# module code
.
endThe default will be [node()] and this table will reside on the node() ram.
Example table spcifing nodes and ram copies:
defmodule Test.Support.Dogs.Dog do
use ActiveMemory.Table,
options: [compressed: true, read_concurrency: true, ram_copes: [node() | Node.list()]
.
# module code
.
endAll the active nodes in Node.list() and node() will have ram copes of the table.
disc-copies
Disc copies
Disc copy tables reside both in ram and disc on the nodes specified. In order to persist to disc the schema must be setup on at lest one running node. The default is [] (no nodes). Example table spcifing nodes and disc copies:
defmodule Test.Support.Dogs.Dog do
use ActiveMemory.Table,
options: [compressed: true, read_concurrency: true, disc_copes: [node()]
.
# module code
.
endThe table will have a ram copy and disc copy on node()
disc-only-copies
Disc only copies
Disc oly tables reside only on disc on the nodes specified. In order to persist to disc the schema must be setup on at lest one running node. The default is [] (no nodes). Example table spcifing nodes and disc copies:
defmodule Test.Support.Dogs.Dog do
use ActiveMemory.Table,
options: [compressed: true, read_concurrency: true, disc_only_copes: [node()]
.
# module code
.
endThe table will only have a disc copy on node()
table-read-and-write-access
Table Read and Write Access
Mnesia tables can be set to read_only or read_write. The default is read_write.
Read only tables updates cannot be performed.
if you need to change the access use the following syntax: [access_mode: :read_only]
table-types
Table Types
Tables can be either a :set, :ordered_set, or a :bag. The default is :set
if you need to change the type use the following syntax: [type: :bag]
indexes
Indexes
If Indexes are desired specify an atom attribute list for which Mnesia is to build and maintain an extra index table.
The qlc query compiler may be able to optimize queries if there are indexes available.
To specify Indexes use the following syntax: [index: [:age, :hair_color, :cylon?]]
table-load-order
Table Load Order
The load order priority is by default 0 (zero) but can be set to any integer. The tables with the highest load order priority are loaded first at startup.
If you need to change the load order use the following syntax: [load_order: 2]
majority
Majority
If true, any (non-dirty) update to the table is aborted, unless a majority of the table replicas are available for the commit. When used on a fragmented table, all fragments are given the same the same majority setting.
If you need to modify the majority use the following syntax: [majority: true]
Link to this section Summary
Functions
Bring an existing Mnesia table's schema in line with its ActiveMemory.Table
options.
Link to this section Functions
@spec migrate_table_options(atom()) :: :ok
Bring an existing Mnesia table's schema in line with its ActiveMemory.Table
options.
Called from ActiveMemory.Adapters.Mnesia.create_table/1 when the table already
exists — the {:ok, :recovered} path — so a table that outlived this node's process
picks up option changes made in the code since it was created. It reconciles, in
order: the replica nodes for each copy type, access_mode, index, load_order
and majority.
Returns :ok. A change Mnesia refuses at runtime — a replica on a node that is
not reachable, a copy type change it will not perform — is logged as a warning and
skipped, so the store still starts and the table keeps its current setting for
that option. The one exception is a copy configuration that is wrong in the code
itself (the same node under two copy types), which raises ArgumentError: it
would fail identically on every boot, so it is a bug to fix rather than a
condition to ride out.