add upsert support for geoip imports to prevent duplicates
This commit is contained in:
parent
b341f89332
commit
234ff7cbd2
3 changed files with 22 additions and 20 deletions
|
|
@ -113,7 +113,13 @@ defmodule ToweropsWeb.Api.V1.GeoipController do
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{inserted, _} = Repo.insert_all(Location, entries)
|
# Use upsert to avoid duplicates - replace existing records with same geoname_id
|
||||||
|
{inserted, _} =
|
||||||
|
Repo.insert_all(Location, entries,
|
||||||
|
on_conflict: {:replace_all_except, [:inserted_at]},
|
||||||
|
conflict_target: :geoname_id
|
||||||
|
)
|
||||||
|
|
||||||
{:ok, inserted}
|
{:ok, inserted}
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
|
|
@ -144,7 +150,13 @@ defmodule ToweropsWeb.Api.V1.GeoipController do
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{inserted, _} = Repo.insert_all(Block, entries)
|
# Use upsert to avoid duplicates - replace existing records with same network
|
||||||
|
{inserted, _} =
|
||||||
|
Repo.insert_all(Block, entries,
|
||||||
|
on_conflict: {:replace_all_except, [:id, :inserted_at]},
|
||||||
|
conflict_target: :network
|
||||||
|
)
|
||||||
|
|
||||||
{:ok, inserted}
|
{:ok, inserted}
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule Towerops.Repo.Migrations.AddUniqueConstraintToGeoipBlocks do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
# Add unique index on network field to prevent duplicate CIDR blocks
|
||||||
|
create unique_index(:geoip_blocks, [:network])
|
||||||
|
end
|
||||||
|
end
|
||||||
18
vendor/oban_web/lib/oban/web/components/icons.ex
vendored
18
vendor/oban_web/lib/oban/web/components/icons.ex
vendored
|
|
@ -3,24 +3,6 @@ defmodule Oban.Web.Components.Icons do
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
|
|
||||||
attr :rest, :global,
|
|
||||||
default: %{
|
|
||||||
"aria-hidden": "true",
|
|
||||||
class: "w-4 h-4",
|
|
||||||
fill: "currentColor",
|
|
||||||
viewBox: "0 0 16 16"
|
|
||||||
}
|
|
||||||
|
|
||||||
slot :inner_block, required: true
|
|
||||||
|
|
||||||
defp svg_mini(assigns) do
|
|
||||||
~H"""
|
|
||||||
<svg {@rest}>
|
|
||||||
{render_slot(@inner_block)}
|
|
||||||
</svg>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
attr :rest, :global,
|
attr :rest, :global,
|
||||||
default: %{
|
default: %{
|
||||||
"stroke-width": "1.5",
|
"stroke-width": "1.5",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue