fix forums not being seeded

This commit is contained in:
Luna D 2021-10-11 23:32:49 +02:00
parent 2ad2a4347f
commit 08b4889b31
No known key found for this signature in database
GPG key ID: 81AF416F2CC36FC8
2 changed files with 49 additions and 47 deletions

View file

@ -100,11 +100,10 @@ for comment_body <- resources["comments"] do
end end
IO.puts "---- Generating forum posts" IO.puts "---- Generating forum posts"
for resource <- resources["forum_posts"] do for %{"forum" => forum_name, "topics" => topics} <- resources["forum_posts"] do
for {forum_name, topics} <- resource do
forum = Repo.get_by!(Forum, short_name: forum_name) forum = Repo.get_by!(Forum, short_name: forum_name)
for {topic_name, [first_post | posts]} <- topics do for %{"title" => topic_name, "posts" => [first_post | posts]} <- topics do
Topics.create_topic( Topics.create_topic(
forum, forum,
request_attributes, request_attributes,
@ -138,7 +137,6 @@ for resource <- resources["forum_posts"] do
IO.inspect changeset.errors IO.inspect changeset.errors
end end
end end
end
end end
IO.puts "---- Done." IO.puts "---- Done."

View file

@ -57,23 +57,27 @@
"spoilers inside of a table\n\nHello | World\n--- | ---:\n`||cool beans!||` | ||cool beans!||" "spoilers inside of a table\n\nHello | World\n--- | ---:\n`||cool beans!||` | ||cool beans!||"
], ],
"forum_posts": [{ "forum_posts": [{
"dis": [{ "forum": "dis",
"Example topic": [ "topics": [{
"title": "Example Topic",
"posts": [
"example post", "example post",
"yet another example post" "yet another example post"
] ]
}, },
{ {
"Second example topic": [ "title": "Second Example Topic",
"posts": [
"post", "post",
"post 2" "post 2"
] ]
} }
] ]},
},
{ {
"art": [{ "forum": "art",
"Embedded images": [ "topics": [{
"title": "Embedded Images",
"posts": [
">>1t >>1s >>1p", ">>1t >>1s >>1p",
">>1", ">>1",
"non-existent: >>1000t >>1000s >>1000p >>1000" "non-existent: >>1000t >>1000s >>1000p >>1000"