726038f028b29f3b9c04f00c4b08a1588f12873a — Ivan Habunek 1 year, 2 months ago f4ed647
Add --force option to osm import task
1 files changed, 14 insertions(+), 5 deletions(-)

M lib/mix/tasks/triglav/import_osm.ex
M lib/mix/tasks/triglav/import_osm.ex => lib/mix/tasks/triglav/import_osm.ex +14 -5
@@ 3,10 3,17 @@ defmodule Mix.Tasks.Triglav.ImportOsm do

  alias Triglav.Repo

  @shortdoc "Imports OSM data for Croatia from Geofabrik"
  @shortdoc "Imports the latest OSM data for Croatia from Geofabrik"

  @moduledoc """
  Imports the latest OSM data for Croatia from Geofabrik


  @impl Mix.Task
  def run(_args) do
  def run(args) do
    {:ok, _} = Application.ensure_all_started(:triglav)

    web_state = get_web_state()

@@ 15,6 22,8 @@ defmodule Mix.Tasks.Triglav.ImportOsm do
    %{osm_sequence_number: db_seq, osm_timestamp: db_ts} = db_state
    %{osm_sequence_number: web_seq, osm_timestamp: web_ts} = web_state

    {opts, _rest} = OptionParser.parse!(args, strict: [force: :boolean])

    if db_seq do
      IO.puts(" Local data: seq ##{db_seq} from #{db_ts}")

@@ 23,7 32,7 @@ defmodule Mix.Tasks.Triglav.ImportOsm do

    IO.puts("Remote data: seq ##{web_seq} from #{web_ts}\n")

    if is_nil(db_seq) or web_seq > db_seq do
    if is_nil(db_seq) or web_seq > db_seq or opts[:force] do
      url = "https://download.geofabrik.de/europe/croatia-latest.osm.pbf"
      IO.puts("Downloading #{url}")
      download(url, "croatia-latest.osm.pbf")

@@ 45,7 54,7 @@ defmodule Mix.Tasks.Triglav.ImportOsm do
      Repo.query("UPDATE planet_osm_rels SET tags_hstore = tags::hstore")
      Repo.query("UPDATE planet_osm_rels SET type = tags_hstore->'type'")
      Repo.query("UPDATE planet_osm_rels SET ref = tags_hstore->'ref'")
      Repo.query("UPDATE planet_osm_rels SET is_zet = (lower(tags_hstore->'operator') in ('zet', 'zagrebački električni tramvaj')")
      Repo.query("UPDATE planet_osm_rels SET is_zet = lower(tags_hstore->'operator') in ('zet', 'zagrebački električni tramvaj')")

      Repo.query("CREATE INDEX idx_planet_osm_rels_is_zet ON planet_osm_rels(is_zet)")
      Repo.query("CREATE INDEX idx_planet_osm_rels_type ON planet_osm_rels(type)")

@@ 59,7 68,7 @@ defmodule Mix.Tasks.Triglav.ImportOsm do

      IO.puts("You already have the latest OSM data.")
      IO.puts("You already have the latest OSM data. Use --force option to import anyway.")