- Migration renames table, column, all indexes, and FK constraints - Contact schema now references "contacts" table - TerrainProfile foreign key renamed from qso_id to contact_id - All code and tests updated to use contact_id
28 lines
662 B
Elixir
28 lines
662 B
Elixir
defmodule Microwaveprop.Terrain do
|
|
@moduledoc false
|
|
|
|
import Ecto.Query
|
|
|
|
alias Microwaveprop.Repo
|
|
alias Microwaveprop.Terrain.TerrainProfile
|
|
|
|
def upsert_terrain_profile(attrs) do
|
|
%TerrainProfile{}
|
|
|> TerrainProfile.changeset(attrs)
|
|
|> Repo.insert(
|
|
on_conflict: {:replace_all_except, [:id, :contact_id, :inserted_at]},
|
|
conflict_target: [:contact_id],
|
|
returning: true
|
|
)
|
|
end
|
|
|
|
def get_terrain_profile(contact_id) do
|
|
Repo.get_by(TerrainProfile, contact_id: contact_id)
|
|
end
|
|
|
|
def has_terrain_profile?(contact_id) do
|
|
TerrainProfile
|
|
|> where([t], t.contact_id == ^contact_id)
|
|
|> Repo.exists?()
|
|
end
|
|
end
|