ammocpr/priv/repo/migrations/20260312144740_add_new_retailers.exs
Graham McIntire 9eb85faebd
Add 4 new retailer scrapers for broader price coverage
Add True Shot Ammo (Shopify JSON), Palmetto State Armory (Magento HTML),
Bulk Ammo (Magento HTML), and Natchez Shooters Supply (GraphQL API).

Extends scraper infrastructure with HttpClient.post_json/3 and an
optional fetch/2 callback on the Scraper behaviour for scrapers that
need custom HTTP flows (e.g. GraphQL POST requests).
2026-03-12 10:00:59 -05:00

36 lines
1.1 KiB
Elixir

defmodule Ammoprices.Repo.Migrations.AddNewRetailers do
use Ecto.Migration
def up do
now = DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_naive()
retailers = [
%{name: "True Shot Ammo", slug: "true-shot-ammo", base_url: "https://trueshotammo.com"},
%{
name: "Palmetto State Armory",
slug: "palmetto-state-armory",
base_url: "https://palmettostatearmory.com"
},
%{name: "Bulk Ammo", slug: "bulk-ammo", base_url: "https://www.bulkammo.com"},
%{
name: "Natchez Shooters Supply",
slug: "natchez",
base_url: "https://www.natchezss.com"
}
]
for r <- retailers do
execute("""
INSERT INTO retailers (id, name, slug, base_url, inserted_at, updated_at)
VALUES (gen_random_uuid(), '#{r.name}', '#{r.slug}', '#{r.base_url}', '#{now}', '#{now}')
ON CONFLICT (slug) DO NOTHING
""")
end
end
def down do
execute(
"DELETE FROM retailers WHERE slug IN ('true-shot-ammo', 'palmetto-state-armory', 'bulk-ammo', 'natchez')"
)
end
end