Update migration generator
This commit is contained in:
parent
b0c5be9aac
commit
3f1fc77d85
|
|
@ -1,6 +1,7 @@
|
||||||
defmodule Mix.Tasks.Isn.Gen.Migration do
|
defmodule Mix.Tasks.Isn.Gen.Migration do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
import Mix.Ecto
|
import Mix.Ecto
|
||||||
|
import Mix.EctoSQL
|
||||||
import Mix.Generator
|
import Mix.Generator
|
||||||
|
|
||||||
@migration_name "CreateISNExtension"
|
@migration_name "CreateISNExtension"
|
||||||
|
|
@ -18,22 +19,18 @@ defmodule Mix.Tasks.Isn.Gen.Migration do
|
||||||
@doc false
|
@doc false
|
||||||
def run(args) do
|
def run(args) do
|
||||||
Mix.Task.run("app.start", args)
|
Mix.Task.run("app.start", args)
|
||||||
[repo] = parse_repo(args)
|
now = Calendar.strftime(DateTime.utc_now(), "%Y%m%d%H%M%S")
|
||||||
filename = "#{timestamp()}_create_isn_extension.exs"
|
|
||||||
path = Path.relative_to(migrations_path(repo), Mix.Project.app_path())
|
with [repo] <- parse_repo(args),
|
||||||
file = Path.join(path, filename)
|
filename <- "#{now}_create_isn_extension.exs",
|
||||||
|
path <- Path.join(source_repo_priv(repo), "migrations"),
|
||||||
|
file <- Path.join(path, filename),
|
||||||
|
mod <- Module.concat([repo, Migrations, @migration_name]) do
|
||||||
create_directory(path)
|
create_directory(path)
|
||||||
mod = Module.concat([repo, Migrations, @migration_name])
|
|
||||||
create_file(file, migration_template(mod: mod))
|
create_file(file, migration_template(mod: mod))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp timestamp do
|
|
||||||
{{y, m, d}, {hh, mm, ss}} = :calendar.universal_time()
|
|
||||||
"#{y}#{pad(m)}#{pad(d)}#{pad(hh)}#{pad(mm)}#{pad(ss)}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp pad(s), do: s |> to_string() |> String.pad_leading(2, ?0)
|
|
||||||
|
|
||||||
embed_template(:migration, """
|
embed_template(:migration, """
|
||||||
defmodule <%= inspect @mod %> do
|
defmodule <%= inspect @mod %> do
|
||||||
use Ecto.Migration
|
use Ecto.Migration
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue