Fix warning

This commit is contained in:
Shadowfacts 2019-11-08 22:33:24 -05:00
parent 0d0c749b68
commit e5ea6b3e1b
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 46 additions and 48 deletions

View File

@ -4,58 +4,56 @@ defmodule Frenzy.Repo.Migrations.FeedsConvertPipelineStagesToPipelines do
import Ecto.Query
def up do
pipeline_entries =
Repo.all(
from(stage in "pipeline_stages",
join: feed in "feeds",
on: stage.feed_id == feed.id,
join: group in "groups",
on: feed.group_id == group.id,
select: %{
index: stage.index,
module_name: stage.module_name,
options: stage.options,
feed_id: feed.id,
feed_title: feed.title,
user_id: group.user_id
}
)
Repo.all(
from(stage in "pipeline_stages",
join: feed in "feeds",
on: stage.feed_id == feed.id,
join: group in "groups",
on: feed.group_id == group.id,
select: %{
index: stage.index,
module_name: stage.module_name,
options: stage.options,
feed_id: feed.id,
feed_title: feed.title,
user_id: group.user_id
}
)
|> Enum.group_by(fn data -> data.feed_id end)
|> Enum.map(fn {feed_id, [first | _] = pipeline_data} ->
feed_title = first.feed_title
user_id = first.user_id
)
|> Enum.group_by(fn data -> data.feed_id end)
|> Enum.map(fn {feed_id, [first | _] = pipeline_data} ->
feed_title = first.feed_title
user_id = first.user_id
stages =
pipeline_data
|> Enum.sort_by(& &1.index)
|> Enum.map(fn data ->
%{
module_name: data.module_name,
options: data.options
}
end)
stages =
pipeline_data
|> Enum.sort_by(& &1.index)
|> Enum.map(fn data ->
%{
module_name: data.module_name,
options: data.options
}
end)
{feed_id,
[
name:
if(feed_title,
do: "#{feed_title} Pipeline",
else: "Unknown Feed Pipeline (feed ID #{feed_id})"
),
stages: stages,
user_id: user_id,
inserted_at: NaiveDateTime.utc_now(),
updated_at: NaiveDateTime.utc_now()
]}
end)
|> Enum.each(fn {feed_id, pipeline_entry} ->
{_, [%{id: pipeline_id}]} =
Repo.insert_all("pipelines", [pipeline_entry], returning: [:id])
{feed_id,
[
name:
if(feed_title,
do: "#{feed_title} Pipeline",
else: "Unknown Feed Pipeline (feed ID #{feed_id})"
),
stages: stages,
user_id: user_id,
inserted_at: NaiveDateTime.utc_now(),
updated_at: NaiveDateTime.utc_now()
]}
end)
|> Enum.each(fn {feed_id, pipeline_entry} ->
{_, [%{id: pipeline_id}]} = Repo.insert_all("pipelines", [pipeline_entry], returning: [:id])
feed_query = from(f in "feeds", where: f.id == ^feed_id)
Repo.update_all(feed_query, set: [pipeline_id: pipeline_id])
end)
feed_query = from(f in "feeds", where: f.id == ^feed_id)
Repo.update_all(feed_query, set: [pipeline_id: pipeline_id])
end)
end
def down do