Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create detour notification table #2798

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/notifications/db/detour.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Notifications.Db.Detour do
@moduledoc """
Ecto Model for Detour Notifications struct and Database table
"""

use Skate.Schema
import Ecto.Changeset

@derive {Jason.Encoder,
only: [
:__struct__,
:status
]}

typed_schema "detour_notifications" do
belongs_to :detour, Skate.Detours.Db.Detour
has_one :notification, Notifications.Db.Notification

field :status, Ecto.Enum, values: [:activated]
end

def changeset(
%__MODULE__{} = struct,
attrs \\ %{}
) do
struct
|> cast(attrs, [
:detour,
:status
])
|> validate_required([
:detour,
:status
])
end
end
1 change: 1 addition & 0 deletions lib/notifications/db/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Notifications.Db.Notification do

belongs_to(:block_waiver, DbBlockWaiver)
belongs_to(:bridge_movement, DbBridgeMovement)
belongs_to(:detour, Notifications.Db.Detour)
end

def block_waiver_changeset(notification, attrs \\ %{}) do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Skate.Repo.Migrations.CreateDetourNotificationsTable do
use Ecto.Migration

def change do
create table(:detour_notifications) do
add :detour_id, references(:detours, on_delete: :nothing)
add :status, :string
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Skate.Repo.Migrations.CreateDetourNotificationsIndex do
use Ecto.Migration

@disable_ddl_transaction true
@disable_migration_lock true

def change do
create index(:detour_notifications, [:detour_id], concurrently: true)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Skate.Repo.Migrations.CreateDetourNotificationsReference do
use Ecto.Migration

def change do
alter table(:notifications) do
add(:detour_id, references(:detour_notifications))
end
end
end
Loading