From 17b3d83961335515be26262839a22b658b6de10b Mon Sep 17 00:00:00 2001 From: NRayya <82588017+NRayya@users.noreply.github.com> Date: Wed, 23 Nov 2022 17:09:37 +0100 Subject: [PATCH] feat: create project seeder #631 --- database/seeders/ProjectSeeder.php | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 database/seeders/ProjectSeeder.php diff --git a/database/seeders/ProjectSeeder.php b/database/seeders/ProjectSeeder.php new file mode 100644 index 00000000..21337372 --- /dev/null +++ b/database/seeders/ProjectSeeder.php @@ -0,0 +1,84 @@ +withPersonalTeam()->create(['password' => bcrypt($password)]); + $team = $user->personalTeam(); + + $project = Project::factory()->create([ + 'team_id' => $team->id, + 'owner_id' => $user->id, + ]); + + $studies = Study::factory(2)->create([ + 'team_id' => $team->id, + 'owner_id' => $user->id, + 'project_id' => $project->id, + 'created_at' => $project->created_at, + 'updated_at' => $project->updated_at->subMinutes(rand(1, 30)), + ]); + + foreach ($studies as $study) { + $sample = Sample::factory()->create([ + 'study_id' => $study->id, + 'project_id' => $project->id, + 'created_at' => $study->created_at->addMinutes(rand(1, 10)), + 'updated_at' => $study->created_at->addMinutes(rand(11, 20)), + ]); + + //todo: add molecules to the sample + + $datasets = Dataset::factory(5)->create([ + 'team_id' => $team->id, + 'owner_id' => $user->id, + 'project_id' => $project->id, + 'study_id' => $study->id, + 'created_at' => $project->created_at, + 'updated_at' => $study->updated_at, + ]); + + $dsTypes = [ + 'proton', + '13c', + 'dept', + 'hmbc', + 'hsqc', ]; + + $index = 0; + foreach ($datasets as $dataset) { + $dataset->type = $dsTypes[$index]; + $dataset->has_nmrium = true; + $dataset->save(); + + $nmrium = NMRium::factory()->create([ + 'nmrium_info' => NMRiumMockData($dataset->type), + 'dataset_id' => $dataset->id, + ]); + $index = $index + 1; + } + } + + $this->command->alert('nmrXiv: Projects table seed successfully'); + $this->command->line('You may log in to admin console using '.$user->email.' and password: '.$password.''); + $this->command->line(''); + } +}