ArangoXEcto.Migration (ArangoX Ecto v0.7.0) View Source
Defines Ecto Migrations for ArangoDB
NOTE: ArangoXEcto dynamically creates collections for you and this method is discouraged unless you need to define indexes.
Migrations must use this module, otherwise migrations will not work. To do this, replace
use Ecto.Migration
with use ArangoXEcto.Migration
.
Since ArangoDB is schemaless, no fields need to be provided, only the collection name. First create
a collection struct using the collection/2
function. Then pass the collection struct to the
create/1
function. To create indexes it is a similar process using the index/3
function.
Collections must be created BEFORE indexes.
To drop the collection on a migration down, do the same as creation except use the drop/1
function
instead of the create/1
function. Indexes are automatically removed when the collection is removed
and cannot be deleted using the drop/1
function.
Example
defmodule MyProject.Repo.Migrations.CreateUsers do
use ArangoXEcto.Migration
def up do
create(collection(:users))
create(index("users", [:email]))
end
def down do
drop(collection(:users))
end
end
Link to this section Summary
Functions
Creates a collection struct
Creates an object
Deletes an object
Creates an edge collection struct
Creates an index struct
Link to this section Types
Specs
Link to this section Functions
Specs
Creates a collection struct
Used to in functions that perform actions on the database.
Accepts a collection type parameter that can either be :document
or :edge
, otherwise it will
raise an error. The default option is :document
.
Examples
iex> collection("users")
%Collection{name: "users", 2)
iex> collection("users", :edge)
%Collection{name: "users", 3)
Specs
create( %ArangoXEcto.Migration.Collection{name: term(), type: term()} | %ArangoXEcto.Migration.Index{ collection_name: term(), deduplication: term(), fields: term(), minLength: term(), sparse: term(), type: term(), unique: term() } ) :: :ok | {:error, binary()}
Creates an object
Will create the passed object, either a collection or an index.
Examples
Create a collection
iex> create(collection("users"))
:ok
Create an index
iex> create(index("users", [:email])
:ok
Specs
Deletes an object
Will delete an object passed, can only be a collection, indexes cannot be deleted here.
Example
iex> drop(collection("users"))
:ok
Specs
edge(String.t()) :: ArangoXEcto.Migration.Collection.t()
Creates an edge collection struct
Same as passing :edge
as the second parameter to collection/2
.
Specs
index(String.t(), [String.t()], [index_option()]) :: ArangoXEcto.Migration.Index.t()
Creates an index struct
Default index type is a hash. To change this pass the :type
option in options.
Options
Options only apply to the creation of indexes and has no effect when using the drop/1
function.
:type
- The type of index to create- Accepts:
:fulltext
,:geo
,:hash
,:persistent
,:skiplist
or:ttl
- Accepts:
:unique
- If the index should be unique, defaults to false (hash, persistent & skiplist only):sparse
- If index should be spares, defaults to false (hash, persistent & skiplist only):deduplication
- If duplication of array values should be turned off, defaults to true (hash & skiplist only):minLength
- Minimum character length of words to index (fulltext only):geoJson
- If a geo-spatial index on a location is constructed and geoJson is true, then the order within the array is longitude followed by latitude (geo only):expireAfter
- Time in seconds after a document's creation it should count asexpired
(ttl only)
Examples
Create index on email field
iex> index("users", [:email])
%Index{collection_name: "users", fields: [:email]}
Create dual index on email and ph_number fields
iex> index("users", [:email, :ph_number])
%Index{collection_name: "users", fields: [:email, :ph_number]}
Create unique email index
iex> index("users", [:email], unique: true)
%Index{collection_name: "users", fields: [:email], [unique: true]}