Packages
ecto_tablestore
0.4.0
0.15.1
0.15.0
0.14.0
0.13.3
0.13.2
0.13.1
0.13.0
0.12.2
0.12.1
0.12.0
0.11.2
0.11.1
0.11.0
0.10.1
0.10.0
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.0
0.6.1
0.6.0
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.2
0.4.1
0.4.0
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
Alibaba Tablestore adapter for Ecto
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/ecto.ots.migrate.ex
defmodule Mix.Tasks.Ecto.Ots.Migrate do
use Mix.Task
import Mix.Ecto
import Mix.EctoTablestore
@shortdoc "Run the table creations"
@aliases [
n: :step,
r: :repo
]
@switches [
all: :boolean,
step: :integer,
to: :integer,
prefix: :string,
repo: [:keep, :string]
]
@moduledoc """
Runs the all migration for the given repository.
Migrations are expected at "priv/tablestore/YOUR_REPO/migrations" directory
of the current application, where "YOUR_REPO" is the last segment in your
repository name. For example, the repository `MyApp.Repo` will use
"priv/tablestore/repo/migrations", the repository `Whatever.MyRepo` will
use "priv/tablestore/my_repo/migrations".
Alibaba Tablestore is a cloud service product, there will not do any local storage,
meanwhile it is a NoSQL data storage, the migrations mainly responsible for the
creation of the table primary key(s).
Currently, run migrations will execute the all defined tasks, once Tablestore's
primary key(s) are created, the primary keys(s) cannot be modified, failed to create
an existing table, we can ignore it.
## Example
mix ecto.ots.migrate
mix ecto.ots.migrate -r EctoTablestore.TestRepo
## Command line options
* `-r`, `--repo` - the repo to migrate
"""
@impl true
def run(args) do
repos = parse_repo(args)
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
opts =
if opts[:to] || opts[:step] || opts[:all], do: opts, else: Keyword.put(opts, :all, true)
{:ok, _} = Application.ensure_all_started(:ecto_tablestore)
for repo <- repos do
ensure_repo(repo, args)
path = ensure_migrations_path(repo, opts)
migrator = &EctoTablestore.Migrator.run/3
fun = &migrator.(&1, path, opts)
case EctoTablestore.Migrator.with_repo(repo, fun, [mode: :temporary] ++ opts) do
{:ok, _migrated, _apps} ->
:ok
{:error, error} ->
Mix.raise("Could not start repo #{inspect(repo)}, error: #{inspect(error)}")
end
end
end
end