Skip to content

Commit ee76c99

Browse files
committed
add new fields and indexes
1 parent b5acb33 commit ee76c99

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ defmodule Algora.Accounts.User do
156156
# Poaching targets - stores repos and companies to poach from
157157
field :poaching_targets, :string
158158

159+
# Customer stage tracking
160+
field :stage, Ecto.Enum,
161+
values: [:inbound, :opening, :onboarding, :campaigning, :interviewing, :none],
162+
default: :none
163+
164+
# Import tracking - identifies the source that imported this user
165+
field :import_source, :string
166+
159167
has_many :identities, Identity
160168
has_many :memberships, Member, foreign_key: :user_id
161169
has_many :members, Member, foreign_key: :org_id
@@ -536,7 +544,8 @@ defmodule Algora.Accounts.User do
536544
:dm_thread_url,
537545
:linkedin_url,
538546
:employment_info,
539-
:internal_email
547+
:internal_email,
548+
:stage
540549
])
541550
end
542551

lib/algora/matches/schemas/job_match.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ defmodule Algora.Matches.JobMatch do
55
import Ecto.Changeset
66

77
typed_schema "job_matches" do
8-
field :status, Ecto.Enum, values: [:pending, :discarded, :automatched, :approved, :highlighted], default: :pending
8+
field :status, Ecto.Enum,
9+
values: [:pending, :discarded, :automatched, :dripped, :approved, :highlighted],
10+
default: :pending
11+
912
field :score, :decimal
1013
field :notes, :string
1114
field :company_approved_at, :utc_datetime_usec
@@ -41,7 +44,7 @@ defmodule Algora.Matches.JobMatch do
4144
:anonymize
4245
])
4346
|> validate_required([:user_id, :job_posting_id])
44-
|> validate_inclusion(:status, [:pending, :discarded, :automatched, :approved, :highlighted])
47+
|> validate_inclusion(:status, [:pending, :discarded, :automatched, :dripped, :approved, :highlighted])
4548
|> foreign_key_constraint(:user_id)
4649
|> foreign_key_constraint(:job_posting_id)
4750
|> unique_constraint([:user_id, :job_posting_id])
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Algora.Repo.Migrations.AddStageToUsers do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add :stage, :string, null: true
7+
end
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Algora.Repo.Migrations.AddImportSourceToUsers do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add :import_source, :string, null: true
7+
end
8+
end
9+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Algora.Repo.Migrations.AddIndexToUsersStage do
2+
use Ecto.Migration
3+
4+
def change do
5+
create index(:users, [:stage])
6+
end
7+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule Algora.Repo.Migrations.AddPipelineIndexes do
2+
use Ecto.Migration
3+
4+
def change do
5+
# Critical indexes for pipeline performance
6+
create index(:users, [:last_job_match_email_at], where: "last_job_match_email_at IS NOT NULL")
7+
create index(:users, [:last_dm_date], where: "last_dm_date IS NOT NULL")
8+
create index(:users, [:country], where: "country IS NOT NULL")
9+
create index(:users, [:open_to_new_role], where: "open_to_new_role = true")
10+
create index(:users, [:type], where: "type = 'individual'")
11+
12+
# Composite index for the main query ordering
13+
create index(:users, [
14+
"GREATEST(last_job_match_email_at, last_dm_date)",
15+
:id
16+
], where: "last_job_match_email_at IS NOT NULL AND open_to_new_role = true AND type = 'individual'")
17+
18+
# Job matches indexes for EXISTS queries
19+
create index(:job_matches, [:user_id, :candidate_discarded_at, :candidate_approved_at])
20+
create index(:job_matches, [:user_id, :candidate_discarded_at, :candidate_bookmarked_at])
21+
end
22+
end

0 commit comments

Comments
 (0)