Skip to main content

max / makenotwork

3.2 KB · 83 lines History Blame Raw
1 //! The forum content itself: which threads exist, who posts in them, and what
2 //! they say. Each category's table is a sibling const, so the loop that writes
3 //! it stays readable next to the other three.
4
5 mod discussion;
6 mod general;
7 mod mixing;
8 mod sound_design;
9
10 use super::rows::{seed_post, seed_thread};
11 use super::users::SeedUser;
12 use sqlx::PgPool;
13 use uuid::Uuid;
14
15 /// 35 threads in Music/General, enough for 2 pages.
16 pub(super) async fn seed_music_general(pool: &PgPool, category_id: Uuid, users: &[SeedUser]) {
17 let threads = general::THREADS;
18
19 // Pinned welcome thread
20 let welcome_id = seed_thread(pool, category_id, users[0].id, threads[0].0, true, false).await;
21 seed_post(pool, welcome_id, users[0].id, threads[0].1).await;
22 for (i, reply) in threads[0].2.iter().enumerate() {
23 seed_post(pool, welcome_id, users[(i + 2) % users.len()].id, reply).await;
24 }
25
26 // Remaining threads, one with lots of replies for post pagination
27 for (idx, (title, body, replies)) in threads.iter().enumerate().skip(1) {
28 let author = &users[(idx + 1) % users.len()];
29 let thread_id = seed_thread(pool, category_id, author.id, title, false, false).await;
30 seed_post(pool, thread_id, author.id, body).await;
31
32 for (i, reply) in replies.iter().enumerate() {
33 let replier = &users[(idx + i + 3) % users.len()];
34 seed_post(pool, thread_id, replier.id, reply).await;
35 }
36
37 // Thread #1 (DAW thread): add 55 extra posts to test post pagination (50/page)
38 if idx == 1 {
39 seed_long_discussion(pool, thread_id, users).await;
40 }
41 }
42 }
43
44 /// 15 threads in Mixing & Mastering.
45 pub(super) async fn seed_music_mixing(pool: &PgPool, category_id: Uuid, users: &[SeedUser]) {
46 let threads = mixing::THREADS;
47
48 for (idx, (title, body, replies)) in threads.iter().enumerate() {
49 let author = &users[(idx + 2) % users.len()];
50 let thread_id = seed_thread(pool, category_id, author.id, title, false, false).await;
51 seed_post(pool, thread_id, author.id, body).await;
52 for (i, reply) in replies.iter().enumerate() {
53 let replier = &users[(idx + i + 4) % users.len()];
54 seed_post(pool, thread_id, replier.id, reply).await;
55 }
56 }
57 }
58
59 /// 15 threads in Sound Design.
60 pub(super) async fn seed_music_sound_design(pool: &PgPool, category_id: Uuid, users: &[SeedUser]) {
61 let threads = sound_design::THREADS;
62
63 for (idx, (title, body, replies)) in threads.iter().enumerate() {
64 let author = &users[(idx + 5) % users.len()];
65 let thread_id = seed_thread(pool, category_id, author.id, title, false, false).await;
66 seed_post(pool, thread_id, author.id, body).await;
67 for (i, reply) in replies.iter().enumerate() {
68 let replier = &users[(idx + i + 6) % users.len()];
69 seed_post(pool, thread_id, replier.id, reply).await;
70 }
71 }
72 }
73
74 /// Add 55 extra posts to a thread to test post pagination (50 posts/page).
75 pub(super) async fn seed_long_discussion(pool: &PgPool, thread_id: Uuid, users: &[SeedUser]) {
76 let posts = discussion::POSTS;
77
78 for (i, body) in posts.iter().enumerate() {
79 let author = &users[(i + 4) % users.len()];
80 seed_post(pool, thread_id, author.id, body).await;
81 }
82 }
83