Added new uploaded_at column to media items

This commit is contained in:
Kieran Eglin 2024-03-10 16:21:49 -07:00
parent 67d7f397d1
commit cc5b759531
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 28 additions and 1 deletions

View file

@ -1,3 +1,4 @@
import Ecto.Query, warn: false
alias Pinchflat.Repo alias Pinchflat.Repo
alias Pinchflat.Tasks.Task alias Pinchflat.Tasks.Task
@ -35,6 +36,10 @@ defmodule IexHelpers do
"https://www.youtube.com/watch?v=bR52O78ZIUw" "https://www.youtube.com/watch?v=bR52O78ZIUw"
end end
def last_media_item do
Repo.one(from m in MediaItem, limit: 1)
end
def details(type) do def details(type) do
source = source =
case type do case type do

View file

@ -20,6 +20,7 @@ defmodule Pinchflat.Media.MediaItem do
:livestream, :livestream,
:source_id, :source_id,
:short_form_content, :short_form_content,
:uploaded_at,
# these fields are captured only on download # these fields are captured only on download
:media_downloaded_at, :media_downloaded_at,
:media_filepath, :media_filepath,
@ -28,7 +29,16 @@ defmodule Pinchflat.Media.MediaItem do
:thumbnail_filepath, :thumbnail_filepath,
:metadata_filepath :metadata_filepath
] ]
@required_fields ~w(title original_url livestream media_id source_id short_form_content)a # Pretty much all the fields captured at index are required.
@required_fields ~w(
title
original_url
livestream
media_id
source_id
uploaded_at
short_form_content
)a
schema "media_items" do schema "media_items" do
field :title, :string field :title, :string
@ -38,6 +48,7 @@ defmodule Pinchflat.Media.MediaItem do
field :livestream, :boolean, default: false field :livestream, :boolean, default: false
field :short_form_content, :boolean, default: false field :short_form_content, :boolean, default: false
field :media_downloaded_at, :utc_datetime field :media_downloaded_at, :utc_datetime
field :uploaded_at, :utc_datetime
field :media_filepath, :string field :media_filepath, :string
field :media_size_bytes, :integer field :media_size_bytes, :integer

View file

@ -0,0 +1,11 @@
defmodule Pinchflat.Repo.Migrations.AddUploadedAtToMediaItems do
use Ecto.Migration
def change do
alter table(:media_items) do
# Setting default to unix epoch so I can enforce not null BUT also easily
# identify records that were created before this column was added
add :uploaded_at, :utc_datetime, default: "1970-01-01T00:00:00", null: false
end
end
end