<commit_before><?php

use Rogue\Models\Post;
use Rogue\Models\Action;
use Rogue\Models\Signup;
use Rogue\Models\Campaign;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Create 10 campaigns with signups & posts.
        factory(Campaign::class, 10)->create()->each(function (Campaign $campaign) {
            // Create 10-20 signups with one accepted post & some pending posts.
            factory(Signup::class, rand(10, 20))->create(['campaign_id' => $campaign->id])
                ->each(function (Signup $signup) {
                    $signup->posts()->save(factory(Post::class, 'accepted')->create([
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));

                    $signup->posts()->saveMany(factory(Post::class, rand(2, 4))->create([
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));
                });

            // Create 5-10 signups with only accepted posts, from lil' angels!
            factory(Signup::class, rand(10, 20))->create(['campaign_id' => $campaign->id])
                ->each(function (Signup $signup) {
                    $signup->posts()->save(factory(Post::class, 'accepted')->create([
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));
                });

            // Create 5-10 signups with rejected posts, from troublemakers!
            factory(Signup::class, rand(10, 20))->create(['campaign_id' => $campaign->id])
                ->each(function (Signup $signup) {
                    $signup->posts()->save(factory(Post::class, 'rejected')->create([
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));
                });

            // Create 100 signups with no posts yet.
            factory(Signup::class, 100)->create(['campaign_id' => $campaign->id]);
        });

        // And two campaigns with no activity yet.
        factory(Campaign::class, 2)->create();

        // Create four actions.
        factory(Action::class, 4)->create();
    }
}<commit_msg>Fix issue where we'd create a new action per seeded post.<commit_after><?php

use Rogue\Models\Post;
use Rogue\Models\Action;
use Rogue\Models\Signup;
use Rogue\Models\Campaign;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Create 10 campaigns with signups & posts.
        factory(Campaign::class, 10)->create()->each(function (Campaign $campaign) {
            // Add a "default" action so this functions as expected in the "dev" environment.
            $action = factory(Action::class)->create(['campaign_id' => $campaign->id, 'name' => 'default']);

            // Create 10-20 signups with one accepted post & some pending posts.
            factory(Signup::class, rand(10, 20))->create(['campaign_id' => $campaign->id])
                ->each(function (Signup $signup) use ($action) {
                    $signup->posts()->save(factory(Post::class, 'accepted')->create([
                        'action_id' => $action->id,
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));

                    $signup->posts()->saveMany(factory(Post::class, rand(2, 4))->create([
                        'action_id' => $action->id,
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));
                });

            // Create 5-10 signups with only accepted posts, from lil' angels!
            factory(Signup::class, rand(10, 20))->create(['campaign_id' => $campaign->id])
                ->each(function (Signup $signup) use ($action) {
                    $signup->posts()->save(factory(Post::class, 'accepted')->create([
                        'action_id' => $action->id,
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));
                });

            // Create 5-10 signups with rejected posts, from troublemakers!
            factory(Signup::class, rand(10, 20))->create(['campaign_id' => $campaign->id])
                ->each(function (Signup $signup) use ($action) {
                    $signup->posts()->save(factory(Post::class, 'rejected')->create([
                        'action_id' => $action->id,
                        'signup_id' => $signup->id,
                        'campaign_id' => $signup->campaign_id,
                        'northstar_id' => $signup->northstar_id,
                    ]));
                });

            // Create 100 signups with no posts yet.
            factory(Signup::class, 100)->create(['campaign_id' => $campaign->id]);
        });

        // And two campaigns with no activity yet.
        factory(Campaign::class, 2)->create();
    }
}
{'fraction_non_alphanumeric': 0.151473136915078, 'fraction_numerical': 0.012305025996533795, 'mean_word_length': 1.6804458894565721, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 124, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '225895', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1534, 'n_words': 317}