Meet SourceLevel, an All-in-one Data & Analytics for Engineering Teams

SourceLevel provides metrics and insights by collecting data from many sources such as GitHub and GitLab. Our product brings visibility over every corner of the delivery pipeline in a Data & Analytics Solution for Engineering Teams.

Get started for free
Go to line 1
defmodule Hexpm.ReleaseTasks do
Go to line 2
  alias Hexpm.ReleaseTasks.{CheckNames, Stats}
Go to line 3
  require Logger
Go to line 5
  @repo_apps [
Go to line 8
    :postgrex,
Go to line 9
    :ecto_sql
Go to line 12
  @repos Application.get_env(:hexpm, :ecto_repos, [])
Go to line 14
  def script(args) do
Go to line 15
    {:ok, _} = Application.ensure_all_started(:logger)
Go to line 16
    Logger.info("[task] running script")
Go to line 17
    start_app()
Go to line 19
    run_script(args)
Go to line 21
    Logger.info("[task] finished script")
Go to line 25
  def check_names() do
Go to line 26
    {:ok, _} = Application.ensure_all_started(:logger)
Go to line 27
    Logger.info("[job] running check_names")
Go to line 28
    start_app()
Go to line 30
    CheckNames.run()
Go to line 32
    Logger.info("[job] finished check_names")
Go to line 36
  def migrate(args \\ []) do
Go to line 37
    {:ok, _} = Application.ensure_all_started(:logger)
Go to line 38
    Logger.info("[task] running migrate")
Go to line 39
    start_repo()
Go to line 41
    run_migrations(args)
Go to line 43
    Logger.info("[task] finished migrate")
Go to line 47
  def rollback(args \\ []) do
Go to line 48
    {:ok, _} = Application.ensure_all_started(:logger)
Go to line 49
    Logger.info("[task] running rollback")
Go to line 50
    start_repo()
Go to line 52
    run_rollback(args)
Go to line 54
    Logger.info("[task] finished rollback")
Go to line 58
  def seed(args \\ []) do
Go to line 59
    {:ok, _} = Application.ensure_all_started(:logger)
Go to line 60
    Logger.info("[task] running seed")
Go to line 61
    start_repo()
Go to line 63
    run_migrations(args)
Go to line 64
    run_seeds()
Go to line 66
    Logger.info("[task] finished seed")
Go to line 70
  def stats() do
Go to line 71
    {:ok, _} = Application.ensure_all_started(:logger)
Go to line 72
    Logger.info("[job] running stats")
Go to line 73
    start_app()
Go to line 75
    Stats.run()
Go to line 77
    Logger.info("[job] finished stats")
Go to line 81
  defp start_app() do
Go to line 82
    IO.puts("Starting app...")
Go to line 83
    Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
Go to line 84
    Application.put_env(:hexpm, :topologies, [], persistent: true)
Go to line 85
    {:ok, _} = Application.ensure_all_started(:hexpm)
Go to line 88
  defp start_repo() do
Go to line 89
    IO.puts("Starting dependencies...")
Go to line 91
    Enum.each(@repo_apps, fn app ->
Go to line 92
      {:ok, _} = Application.ensure_all_started(app)
Go to line 95
    IO.puts("Starting repos...")
Go to line 96
    :ok = Application.load(:hexpm)
Go to line 98
    Enum.each(@repos, fn repo ->
Go to line 99
      {:ok, _} = repo.start_link(pool_size: 2)
Go to line 103
  defp stop() do
Go to line 104
    IO.puts("Stopping...")
Go to line 105
    :init.stop()
Go to line 108
  defp run_migrations(args) do
Go to line 109
    Enum.each(@repos, fn repo ->
Go to line 110
      app = Keyword.get(repo.config(), :otp_app)
Go to line 111
      IO.puts("Running migrations for #{app}")
Go to line 113
      case args do
Go to line 114
        ["--step", n] -> migrate(repo, :up, step: String.to_integer(n))
Go to line 115
        ["-n", n] -> migrate(repo, :up, step: String.to_integer(n))
Go to line 116
        ["--to", to] -> migrate(repo, :up, to: to)
Go to line 117
        ["--all"] -> migrate(repo, :up, all: true)
Go to line 118
        [] -> migrate(repo, :up, all: true)
Go to line 123
  defp run_rollback(args) do
Go to line 124
    Enum.each(@repos, fn repo ->
Go to line 125
      app = Keyword.get(repo.config(), :otp_app)
Go to line 126
      IO.puts("Running rollback for #{app}")
Go to line 128
      case args do
Go to line 129
        ["--step", n] -> migrate(repo, :down, step: String.to_integer(n))
Go to line 130
        ["-n", n] -> migrate(repo, :down, step: String.to_integer(n))
Go to line 131
        ["--to", to] -> migrate(repo, :down, to: to)
Go to line 132
        ["--all"] -> migrate(repo, :down, all: true)
Go to line 133
        [] -> migrate(repo, :down, step: 1)
Go to line 138
  defp migrate(repo, direction, opts) do
Go to line 139
    migrations_path = priv_path_for(repo, "migrations")
Go to line 140
    Ecto.Migrator.run(repo, migrations_path, direction, opts)
Go to line 143
  defp run_seeds() do
Go to line 144
    Enum.each(@repos, &run_seeds_for/1)
Go to line 147
  defp run_seeds_for(repo) do
Go to line 148
    # Run the seed script if it exists
Go to line 149
    seed_script = priv_path_for(repo, "seeds.exs")
Go to line 151
    if File.exists?(seed_script) do
Go to line 152
      IO.puts("Running seed script...")
Go to line 153
      Code.eval_file(seed_script)
Go to line 157
  defp priv_path_for(repo, filename) do
Go to line 158
    app = Keyword.get(repo.config(), :otp_app)
Go to line 159
    priv_dir = Application.app_dir(app, "priv")
Go to line 161
    Path.join([priv_dir, "repo", filename])
Go to line 164
  # TODO: Move all scripts to release tasks
Go to line 165
  defp run_script(args) do
Go to line 166
    [script | args] = args
Go to line 168
    priv_dir = Application.app_dir(:hexpm, "priv")
Go to line 169
    script_dir = Path.join(priv_dir, "scripts")
Go to line 170
    original_argv = System.argv()
Go to line 172
    Logger.info("[script] running #{script} #{inspect(args)}")
Go to line 175
      System.argv(args)
Go to line 176
      Code.eval_file(script, script_dir)
Go to line 178
      System.argv(original_argv)
Go to line 181
    Logger.info("[script] finished #{script} #{inspect(args)}")