Skip to content

Commit 5088a1c

Browse files
committed
feat: add topics repo field
1 parent 55c761d commit 5088a1c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/algora/workspace/schemas/repository.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule Algora.Workspace.Repository do
1515
field :url, :string, null: false
1616
field :description, :string
1717
field :tech_stack, {:array, :string}, null: false, default: []
18+
field :topics, {:array, :string}, null: false, default: []
1819
field :og_image_url, :string, null: false
1920
field :og_image_updated_at, :utc_datetime_usec
2021
field :stargazers_count, :integer, null: false, default: 0
@@ -42,6 +43,7 @@ defmodule Algora.Workspace.Repository do
4243
og_image_updated_at: DateTime.utc_now(),
4344
url: meta["html_url"],
4445
stargazers_count: meta["stargazers_count"],
46+
topics: meta["topics"] || [],
4547
user_id: user.id
4648
}
4749

@@ -54,6 +56,7 @@ defmodule Algora.Workspace.Repository do
5456
:og_image_url,
5557
:og_image_updated_at,
5658
:stargazers_count,
59+
:topics,
5760
:user_id
5861
])
5962
|> generate_id()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
defmodule Algora.Repo.Migrations.AddTopicsToRepositories do
2+
use Ecto.Migration
3+
4+
def up do
5+
alter table(:repositories) do
6+
add :topics, {:array, :citext}, null: false, default: []
7+
end
8+
9+
# Backfill topics from provider_meta
10+
execute """
11+
UPDATE repositories
12+
SET topics = ARRAY(
13+
SELECT jsonb_array_elements_text(
14+
COALESCE(provider_meta->'topics', '[]'::jsonb)
15+
)
16+
)
17+
"""
18+
end
19+
20+
def down do
21+
alter table(:repositories) do
22+
remove :topics
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)