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).
36 lines
1.1 KiB
Elixir
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
|