ecto_adapters_dynamodb v0.2.3 Ecto.Adapters.DynamoDB.Migration View Source
Implements Ecto migrations for create table
and alter table
.
The functions, add
, remove
and modify
correspond to indexes on the DynamoDB table. Using add
, the second parameter, field type (which corresponds with the DynamoDB attribute) must be specified. Use the third parameter to specify a primary key not already specified. For a HASH-only primary key, use primary_key: true
as the third parameter. For a composite primary key (HASH and RANGE), in addition to the primary_key
specification, set the third parameter on the range key attribute to range_key: true
. There should be only one primary key (hash or composite) specified per table.
To specify index details, such as provisioned throughput, global and local indexes, use the options
keyword in create table
and alter table
, please see the examples below for greater detail.
Please note that change
may not work as expected on rollback. We recommend specifying up
and down
instead.
Example:
#Migration file 1:
def change do
create table(:post,
primary_key: false,
options: [
global_indexes: [
[index_name: "email_content",
keys: [:email, :content],
provisioned_throughput: [100, 100]] # [read_capacity, write_capacity]
],
provisioned_throughput: [20,20]
]) do
add :email, :string, primary_key: true # primary composite key
add :title, :string, range_key: true # primary composite key
add :content, :string
timestamps()
end
end
# Migration file 2:
def up do
alter table(:post,
options: [
global_indexes: [
[index_name: "content",
keys: [:content],
projection: [projection_type: :include, non_key_attributes: [:email]]]
]
]) do
add :content, string
end
end
def down do
alter table(:post) do
remove :content
end
end
# Migration file 3:
def up do
alter table(:post) do
# modify will not be processed in a rollback if 'change' is used
modify :"email_content", :string, provisioned_throughput: [2,2]
remove :content
end
end
def down do
alter table(:post,
options: [
global_indexes: [
[index_name: "content",
keys: [:content],
projection: [projection_type: :include, non_key_attributes: [:email]]]
]
]) do
modify :"email_content", :string, provisioned_throughput: [100,100]
add :content, :string
end
end