Skip to content

Commit

Permalink
Add feed status, dataplicity_id to feeds (#547)
Browse files Browse the repository at this point in the history
* Allow detection and candidate update actions to accept more attributes

* Add online aggregate and dataplicity_id column to feeds

* Update accepts for feed create and update
  • Loading branch information
skanderm committed Jul 27, 2024
1 parent 307831d commit 65a53a9
Show file tree
Hide file tree
Showing 7 changed files with 754 additions and 5 deletions.
25 changes: 20 additions & 5 deletions server/lib/orcasite/radio/feed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Orcasite.Radio.Feed do
index [:node_name]
index [:visible]
index [:slug]
index [:dataplicity_id]
end

migration_defaults id: "fragment(\"uuid_generate_v7()\")"
Expand All @@ -36,6 +37,7 @@ defmodule Orcasite.Radio.Feed do
attribute :bucket, :string, public?: true
attribute :bucket_region, :string, public?: true
attribute :cloudfront_url, :string, public?: true
attribute :dataplicity_id, :string, public?: true

create_timestamp :inserted_at
update_timestamp :updated_at
Expand Down Expand Up @@ -65,10 +67,21 @@ defmodule Orcasite.Radio.Feed do
public?: true
end

aggregates do
exists :online, :feed_segments do
public? true
filter expr(inserted_at > ago(30, :second))
end
end


relationships do
has_many :feed_streams, Orcasite.Radio.FeedStream do
public? true
end
has_many :feed_segments, Orcasite.Radio.FeedSegment do
public? true
end
end

policies do
Expand All @@ -86,12 +99,12 @@ defmodule Orcasite.Radio.Feed do

read :read do
primary? true
prepare build(load: [:lat_lng, :lat_lng_string])
prepare build(load: [:lat_lng, :lat_lng_string, :online])
end

read :index do
filter expr(visible)
prepare build(load: [:lat_lng, :lat_lng_string])
prepare build(load: [:lat_lng, :lat_lng_string, :online])
end

read :get_by_slug do
Expand All @@ -114,7 +127,8 @@ defmodule Orcasite.Radio.Feed do
:visible,
:bucket,
:bucket_region,
:cloudfront_url
:cloudfront_url,
:dataplicity_id
]

argument :lat_lng_string, :string do
Expand All @@ -137,7 +151,8 @@ defmodule Orcasite.Radio.Feed do
:visible,
:bucket,
:bucket_region,
:cloudfront_url
:cloudfront_url,
:dataplicity_id
]

argument :lat_lng_string, :string do
Expand All @@ -149,7 +164,7 @@ defmodule Orcasite.Radio.Feed do
end

admin do
table_columns [:id, :name, :slug, :node_name, :location_point, :visible]
table_columns [:id, :name, :slug, :node_name, :location_point, :visible, :online]

format_fields location_point: {Jason, :encode!, []}, lat_lng: {Jason, :encode!, []}

Expand Down
1 change: 1 addition & 0 deletions server/lib/orcasite/radio/feed_segment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Orcasite.Radio.FeedSegment do
index [:feed_id]
index [:feed_stream_id]
index [:bucket]
index [:inserted_at]
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Orcasite.Repo.Migrations.AddInsertedAtIndexToFeedSegments do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
create index(:feed_segments, [:inserted_at])
end

def down do
drop_if_exists index(:feed_segments, [:inserted_at])
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Orcasite.Repo.Migrations.AddDataplicityIdToFeeds do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
alter table(:feeds) do
add :dataplicity_id, :text
end

create index(:feeds, [:dataplicity_id])
end

def down do
drop_if_exists index(:feeds, [:dataplicity_id])

alter table(:feeds) do
remove :dataplicity_id
end
end
end
Loading

0 comments on commit 65a53a9

Please sign in to comment.