Skip to content

Commit

Permalink
sketch out migrators (not tested yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 29, 2024
1 parent 54afae9 commit ad39ab5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
21 changes: 21 additions & 0 deletions lib/banchan/offerings/gallery_image.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Banchan.Offerings.GalleryImage do
@moduledoc """
Schema for gallery images associated with offerings.
DEPRECATED: This is no longer used, but is kept around for data migration
purposes.
"""
use Ecto.Schema

alias Banchan.Offerings.Offering
alias Banchan.Uploads.Upload

schema "offering_gallery_images" do
field :index, :integer

belongs_to :offering, Offering
belongs_to :upload, Upload, on_replace: :nilify, type: :binary_id

timestamps()
end
end
3 changes: 3 additions & 0 deletions lib/banchan/studios/portfolio_image.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
defmodule Banchan.Studios.PortfolioImage do
@moduledoc """
Schema for portfolio images associated with studios.
DEPRECATED: This is no longer used, but is kept around for data migration
purposes.
"""
use Ecto.Schema

Expand Down
4 changes: 0 additions & 4 deletions lib/banchan/studios/studio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ defmodule Banchan.Studios.Studio do
belongs_to :header_img, Upload, type: :binary_id
belongs_to :card_img, Upload, type: :binary_id

has_many :portfolio_imgs, PortfolioImage,
on_replace: :delete_if_exists,
preload_order: [asc: :index]

many_to_many :artists, Banchan.Accounts.User,
join_through: "users_studios",
where: [deactivated_at: nil]
Expand Down
2 changes: 1 addition & 1 deletion lib/banchan/workers/thumbnailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule Banchan.Workers.Thumbnailer do

File.mkdir_p!(Path.dirname(tmp_dest))

Image.thumbnail!(tmp_src, opts["dimensions"] || "512",
Image.thumbnail!(tmp_src, opts["dimensions"] || "256",
resize:
if opts["upscale"] do
:both
Expand Down
53 changes: 53 additions & 0 deletions lib/banchan/works/works.ex
Original file line number Diff line number Diff line change
Expand Up @@ -511,5 +511,58 @@ defmodule Banchan.Works do
ret
end

def import_legacy_portfolio_images(%User{} = actor) do
{:ok, ret} =

Check warning on line 515 in lib/banchan/works/works.ex

View workflow job for this annotation

GitHub Actions / Unit Tests (1.14.5, 25)

variable "ret" is unused (if the variable is not meant to be used, prefix it with an underscore)
Repo.transaction(fn ->
with {:ok, _actor} <- Accounts.check_admin(actor) do
from(pimg in Studios.PortfolioImage,
preload: [:studio, :upload]
)
|> Repo.stream()
|> Enum.each(fn pimg ->
{:ok, _} =
new_work(
actor,
pimg.studio,
%{
"title" => pimg.upload.name || "Legacy Portfolio Image",
"description" =>
"This work was automatically imported from a legacy Studio portfolio image.",
"tags" => ["banchan-legacy-import"]
},
uploads: [pimg.upload]
)
end)
end
end)
end

def import_legacy_offering_gallery_images(%User{} = actor) do
{:ok, ret} =

Check warning on line 541 in lib/banchan/works/works.ex

View workflow job for this annotation

GitHub Actions / Unit Tests (1.14.5, 25)

variable "ret" is unused (if the variable is not meant to be used, prefix it with an underscore)
Repo.transaction(fn ->
with {:ok, _actor} <- Accounts.check_admin(actor) do
from(gimg in Offerings.GalleryImage,

Check warning on line 544 in lib/banchan/works/works.ex

View workflow job for this annotation

GitHub Actions / Unit Tests (1.14.5, 25)

Offerings.GalleryImage.__schema__/1 is undefined (module Offerings.GalleryImage is not available or is yet to be defined)
preload: [:upload, offering: [:studio]]
)
|> Repo.stream()
|> Enum.each(fn gimg ->
{:ok, _} =
new_work(
actor,
gimg.offering.studio,
%{
"title" => gimg.upload.name || "Legacy Offering Gallery Image",
"description" =>
"This work was automatically imported from a legacy Offering gallery image.",
"tags" => ["banchan-legacy-import"]
},
uploads: [gimg.upload],
offering: gimg.offering
)
end)
end
end)
end

## TODO
end

0 comments on commit ad39ab5

Please sign in to comment.