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