Skip to content

Commit ab8b865

Browse files
committed
feat: add candidate notes schema and migration
1 parent 4ff9806 commit ab8b865

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
defmodule Algora.Workspace.CandidateNote do
2+
@moduledoc """
3+
Schema for storing candidate notes/highlights.
4+
"""
5+
use Algora.Schema
6+
7+
alias Algora.Accounts.User
8+
alias Algora.Jobs.JobPosting
9+
alias Algora.Workspace.CandidateNote
10+
11+
typed_schema "candidate_notes" do
12+
field :notes, {:array, :string}, null: false
13+
14+
belongs_to :user, User, null: false
15+
belongs_to :job, JobPosting
16+
17+
timestamps()
18+
end
19+
20+
@doc """
21+
Changeset for creating or updating candidate notes.
22+
"""
23+
def changeset(%CandidateNote{} = note, attrs) do
24+
note
25+
|> cast(attrs, [:user_id, :job_id, :notes])
26+
|> validate_required([:user_id, :notes])
27+
|> generate_id()
28+
|> foreign_key_constraint(:user_id)
29+
|> foreign_key_constraint(:job_id)
30+
|> unique_constraint([:user_id, :job_id])
31+
end
32+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Algora.Repo.Migrations.CreateCandidateNotes do
2+
use Ecto.Migration
3+
4+
def change do
5+
create table(:candidate_notes) do
6+
add :notes, {:array, :string}, null: false
7+
add :user_id, references(:users, on_delete: :delete_all), null: false
8+
add :job_id, references(:job_postings, on_delete: :delete_all)
9+
10+
timestamps()
11+
end
12+
13+
create unique_index(:candidate_notes, [:user_id, :job_id])
14+
create index(:candidate_notes, [:user_id])
15+
create index(:candidate_notes, [:job_id])
16+
end
17+
end

0 commit comments

Comments
 (0)