Have Ecto be responsible for creating coach_scraper.export table.

pull/3/head
Joshua Potter 2023-12-04 12:30:38 -07:00
parent 8bf4167e61
commit bb650f6d35
2 changed files with 23 additions and 13 deletions

View File

@ -2,12 +2,13 @@ defmodule BoardWise.Coaches.Coach do
@moduledoc """
Table `coach_scraper.export` containing all scraped coach information.
Notice this table does not exist in the `public` schema.
Though initially created by our Phoenix application, the data found within
this table is managed by an external utility:
[coach-scraper](https://github.com/boardwise-gg/coach-scraper).
This table is managed by an external utility [coach-scraper](https://github.com/boardwise-gg/coach-scraper).
Said utility is responsible for periodically rewriting the entries in the
table with fresh data. For the time-being, avoid using any of the mutative
functions found in the `Coach` context.
The `coach-scraper` app is responsible for periodically rewriting the entries
in the table with fresh data. For the time-being, avoid using any of the
mutative functions found in the `Coach` context.
"""
use Ecto.Schema
@ -17,6 +18,7 @@ defmodule BoardWise.Coaches.Coach do
field :blitz, :integer
field :bullet, :integer
field :rapid, :integer
field :site, :string
field :username, :string
end
@ -25,6 +27,7 @@ defmodule BoardWise.Coaches.Coach do
def changeset(coach, attrs) do
coach
|> cast(attrs, [:rapid, :blitz, :bullet, :site, :username])
|> validate_required([:rapid, :blitz, :bullet, :site, :username])
|> validate_required([:site, :username])
|> unique_constraint(:site_username_unique, name: :site_username_unique)
end
end

View File

@ -1,17 +1,24 @@
defmodule BoardWise.Repo.Migrations.CreateCoaches do
use Ecto.Migration
# We are not responsible for generating this table in production. This
# migration exists for testing purposes
def change do
execute "CREATE SCHEMA IF NOT EXISTS coach_scraper"
@prefix "coach_scraper"
create_if_not_exists table(:export, prefix: "coach_scraper") do
add :site, :string
add :username, :string
def change do
execute "CREATE SCHEMA coach_scraper"
create table(:export, prefix: @prefix) do
add :site, :string, null: false
add :username, :string, null: false
add :rapid, :integer
add :blitz, :integer
add :bullet, :integer
end
create unique_index(
:export,
[:site, :username],
prefix: @prefix,
name: "site_username_unique"
)
end
end