/dynamo_migration

🍻 Simple version management tool for migration file.For DynamoDB

Primary LanguageElixirApache License 2.0Apache-2.0

hex.pm version CI GitHub code size in bytes

DynamoMigration

Simple version management tool for migration file of DynamoDB.

Installation

The package can be installed by adding :dynamo_migration to your list of dependencies in mix.exs along with your preferred JSON codec, HTTP client and ExAwsDynamo.

def deps do
  [
    {:dynamo_migration, "~> 0.1.0"},
    {:ex_aws_dynamo, "~> 4.0"},
    {:jason, "~> 1.0"},
    {:hackney, "~> 1.9"}
  ]
end

ExAws uses Jason as its default JSON codec - if you intend to use a different codec, see ex_aws for more information about setting a custom :json_codec.

See also ExAwsDynamo.

Usage

1. dynamo.setup

First of all, you need to create a migration table for version management. Type this in your console.

$ mix dynamo.setup

2. dynamo.gen.migration

Then create a file for management and add your changes.

$ mix dynamo.gen.migration create_tests_table --table tests -e
option alias type effect
--table -t string table name for management ★ Required.
--env_prefix -e boolean Mix.env () is added to the prefix of the table name.
# priv/dynamo/migrations/20220130083004_create_tests_table.exs
defmodule Dynamo.Migrations.CreateTestsTable do
  @table_name "#{Mix.env()}.test"
  def table_name, do: @table_name
  def change do
    # Rewrite any changes.
    # Examples.
    ExAws.Dynamo.create_table(
      "Tests",
      [id: :hash],
      %{id: :number},
      1,Create migrations tabl
      1,
      :provisioned
    )
    |> ExAws.request!()
  end
end

3. dynamo.migrate

You can run the migration file. And it's managed by a version table so it won't be duplicated. It is also useful as an operation history for DynamoDB.

# Executes `priv/dynamo/migrations/*` if there had not migrated.
$ mix dynamo.migrate

4. dynamo.reset

In a test environment, you would like to reset migration every time I run it. You can use mix dynamo.reset.

option alias type effect
--prefix -p string Executes only for table changes that include the specified prefix.
--env_prefix -e boolean Execute only for tables to which Mix.env () is applied as prefix.
It is recommended to use the -e option of gen.migration together.

Bugs and Feature requests

Feel free to open an issues or a PR to contribute to the project.