Skip to content

Commit 4ff9806

Browse files
committed
feat: add user heatmap schema and migration
1 parent 9dcb394 commit 4ff9806

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule Algora.Workspace.UserHeatmap do
2+
@moduledoc """
3+
Schema for tracking user heatmaps.
4+
"""
5+
use Algora.Schema
6+
7+
alias Algora.Accounts.User
8+
alias Algora.Workspace.UserHeatmap
9+
10+
typed_schema "user_heatmaps" do
11+
field :data, :map, null: false
12+
13+
belongs_to :user, User, null: false
14+
15+
timestamps()
16+
end
17+
18+
@doc """
19+
Changeset for creating or updating a user heatmap.
20+
"""
21+
def changeset(%UserHeatmap{} = heatmap, attrs) do
22+
heatmap
23+
|> cast(attrs, [:user_id, :data])
24+
|> validate_required([:user_id, :data])
25+
|> generate_id()
26+
|> foreign_key_constraint(:user_id)
27+
|> unique_constraint(:user_id)
28+
end
29+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Algora.Repo.Migrations.CreateUserHeatmaps do
2+
use Ecto.Migration
3+
4+
def change do
5+
create table(:user_heatmaps) do
6+
add :data, :map, null: false
7+
8+
add :user_id, references(:users, on_delete: :delete_all), null: false
9+
10+
timestamps()
11+
end
12+
13+
create unique_index(:user_heatmaps, [:user_id])
14+
end
15+
end

0 commit comments

Comments
 (0)