-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a single audio_image per feed_segment within a given range for…
… a feed
- Loading branch information
Showing
8 changed files
with
458 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Orcasite.Validations.Compare do | ||
use Ash.Resource.Validation | ||
|
||
def validate(changeset, [{op, [arg_key_1, arg_key_2]}], _context) do | ||
arg_1 = changeset |> Ash.Changeset.get_argument(arg_key_1) | ||
arg_2 = changeset |> Ash.Changeset.get_argument(arg_key_2) | ||
|
||
case {compare(arg_1, arg_2), op} do | ||
{:eq, :gte} -> :ok | ||
{:gt, :gte} -> :ok | ||
{:lt, :lte} -> :ok | ||
{:lt, :lt} -> :ok | ||
{:eq, :eq} -> :ok | ||
_ -> {:error, "#{arg_key_1} (#{arg_1}) is not #{op} #{arg_key_2} (#{arg_2})"} | ||
end | ||
end | ||
|
||
def compare(%DateTime{} = datetime_1, %DateTime{} = datetime_2) do | ||
DateTime.compare(datetime_1, datetime_2) | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
server/priv/repo/migrations/20240831190249_add_unique_index_to_audio_image.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Orcasite.Repo.Migrations.AddUniqueIndexToAudioImage 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 unique_index(:audio_images, [:feed_id, :image_type, :start_time, :end_time], | ||
name: "audio_images_unique_audio_image_index" | ||
) | ||
end | ||
|
||
def down do | ||
drop_if_exists unique_index(:audio_images, [:feed_id, :image_type, :start_time, :end_time], | ||
name: "audio_images_unique_audio_image_index" | ||
) | ||
end | ||
end |
Oops, something went wrong.