Packages
shopifex
2.1.5
2.4.0
2.3.0
2.2.2
2.2.1
2.2.0
2.1.20
2.1.19
2.1.18
2.1.17
2.1.16
2.1.15
2.1.14
2.1.13
2.1.12
2.1.11
2.1.10
2.1.9
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
1.1.1
1.1.0
1.0.1
1.0.0
0.6.2
0.6.1
0.6.0
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.1
0.4.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Phoenix boilerplate for Shopify Embedded App SDK
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/gen.migration.ex
defmodule Mix.Tasks.Shopifex.Gen.Migration do
@shortdoc "Generates Shopifex migration file"
@moduledoc """
Generates migration file.
mix shopifex.gen.migrations -r MyApp.Repo
mix shopifex.gen.migrations -r MyApp.Repo --namespace shopify_app
This generator will add the shopifex migration file in `priv/repo/migrations`.
The repository must be set under `:ecto_repos` in the current app
configuration or given via the `-r` option.
By default, the migration will be generated to the
"priv/YOUR_REPO/migrations" directory of the current application but it
can be configured to be any subdirectory of `priv` by specifying the
`:priv` key under the repository configuration.
## Arguments
* `-r`, `--repo` - the repo module
* `--binary-id` - use binary id for primary keys
* `--namespace` - namespace to prepend table, schema and controller module name
"""
use Mix.Task
alias Mix.{Ecto, Shopifex, Shopifex.Migration}
@switches [binary_id: :boolean, namespace: :string]
@default_opts [binary_id: false, namespace: "shopify"]
@mix_task "shopifex.gen.migrations"
@impl true
def run(args) do
Shopifex.no_umbrella!(@mix_task)
args
|> Shopifex.parse_options(@switches, @default_opts)
|> parse()
|> create_migration_files(args)
end
defp parse({config, _parsed, _invalid}), do: config
defp create_migration_files(config, args) do
args
|> Ecto.parse_repo()
|> Enum.map(&ensure_repo(&1, args))
|> Enum.map(&Map.put(config, :repo, &1))
|> Enum.each(&create_migration_files/1)
end
defp create_migration_files(%{repo: repo, namespace: namespace} = config) do
name = "Create#{Macro.camelize(namespace)}Tables"
content = Migration.gen(name, namespace, config)
Migration.create_migration_file(repo, name, content)
end
defp ensure_repo(repo, args) do
Ecto.ensure_repo(repo, args ++ ~w(--no-deps-check))
end
end