From 5a732f9846be5654b8a186dc624e95f91fb2cf43 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Wed, 7 Apr 2021 08:57:28 -0700 Subject: [PATCH] Fully remove Seeders and Facrtories (will re-add to deal with case change) --- database/factories/FoodFactory.php | 95 ---------- database/factories/GoalFactory.php | 30 ---- .../factories/IngredientAmountFactory.php | 72 -------- database/factories/JournalEntryFactory.php | 35 ---- database/factories/RecipeFactory.php | 54 ------ database/factories/RecipeSeparatorFactory.php | 26 --- database/factories/RecipeStepFactory.php | 25 --- database/factories/TagFactory.php | 25 --- database/factories/UserFactory.php | 29 ---- database/seeders/DatabaseSeeder.php | 19 -- database/seeders/FoodSeeder.php | 162 ------------------ database/seeders/JournalEntrySeeder.php | 128 -------------- database/seeders/RecipeSeeder.php | 159 ----------------- database/seeders/UserSeeder.php | 24 --- 14 files changed, 883 deletions(-) delete mode 100644 database/factories/FoodFactory.php delete mode 100644 database/factories/GoalFactory.php delete mode 100644 database/factories/IngredientAmountFactory.php delete mode 100644 database/factories/JournalEntryFactory.php delete mode 100644 database/factories/RecipeFactory.php delete mode 100644 database/factories/RecipeSeparatorFactory.php delete mode 100644 database/factories/RecipeStepFactory.php delete mode 100644 database/factories/TagFactory.php delete mode 100644 database/factories/UserFactory.php delete mode 100644 database/seeders/DatabaseSeeder.php delete mode 100644 database/seeders/FoodSeeder.php delete mode 100644 database/seeders/JournalEntrySeeder.php delete mode 100644 database/seeders/RecipeSeeder.php delete mode 100644 database/seeders/UserSeeder.php diff --git a/database/factories/FoodFactory.php b/database/factories/FoodFactory.php deleted file mode 100644 index 0c14307..0000000 --- a/database/factories/FoodFactory.php +++ /dev/null @@ -1,95 +0,0 @@ - Words::randomWords(Arr::random(['n', 'an'])), - 'detail' => $this->faker->optional()->sentence(2), - 'brand' => $this->faker->optional()->word, - 'source' => $this->faker->optional()->url, - 'notes' => $this->faker->optional(0.25)->paragraph, - 'serving_size' => $this->faker->randomFloat(2, 1/2, 5), - 'serving_unit' => $this->faker->randomElement(['tsp', 'tbsp', 'cup']), - 'serving_weight' => $this->faker->numberBetween(5, 500), - 'serving_unit_name' => $this->faker->optional(0.25)->word, - 'calories' => $this->faker->randomFloat(2, 0, 100), - 'fat' => $this->faker->randomFloat(2, 0, 10), - 'cholesterol' => $this->faker->randomFloat(2, 0, 100), - 'sodium' => $this->faker->randomFloat(2, 0, 500), - 'carbohydrates' => $this->faker->randomFloat(2, 0, 20), - 'protein' => $this->faker->randomFloat(2, 0, 20), - 'tags' => $this->faker->words, - ]; - } - - /** - * Define a "tsp" serving unit. - */ - public function tspServingUnit() - { - return $this->state(function (array $attributes) { - return [ - 'serving_unit' => 'tsp', - 'serving_size' => 1, - ]; - }); - } - - /** - * Define a "tbsp" serving unit. - */ - public function tbspServingUnit() - { - return $this->state(function (array $attributes) { - return [ - 'serving_unit' => 'tbsp', - 'serving_size' => 1, - ]; - }); - } - - /** - * Define a "cup" serving unit. - */ - public function cupServingUnit() - { - return $this->state(function (array $attributes) { - return [ - 'serving_unit' => 'cup', - 'serving_size' => 1, - ]; - }); - } - - /** - * Define no serving unit. - */ - public function noServingUnit() - { - return $this->state(function (array $attributes) { - return [ - 'serving_unit' => null, - 'serving_unit_name' => 'head' - ]; - }); - } -} diff --git a/database/factories/GoalFactory.php b/database/factories/GoalFactory.php deleted file mode 100644 index 2878c7b..0000000 --- a/database/factories/GoalFactory.php +++ /dev/null @@ -1,30 +0,0 @@ -faker->dateTimeThisMonth; - $to = $this->faker->dateTimeBetween($from, '+1 year'); - return [ - 'from' => $this->faker->randomElement([$from, null]), - 'to' => $this->faker->randomElement([$to, null]), - 'frequency' => $this->faker->randomElement(Goal::$frequencyOptions)['value'], - 'name' => $this->faker->randomElement(Goal::getNameOptions())['value'], - 'goal' => $this->faker->numberBetween(0, 2000), - ]; - } -} diff --git a/database/factories/IngredientAmountFactory.php b/database/factories/IngredientAmountFactory.php deleted file mode 100644 index 2e97342..0000000 --- a/database/factories/IngredientAmountFactory.php +++ /dev/null @@ -1,72 +0,0 @@ -faker->boolean(90)) { - $ingredient_factory = Food::factory(); - $ingredient_type = Food::class; - $ingredient_unit = Nutrients::units()->pluck('value')->random(1)->first(); - } - else { - $ingredient_factory = Recipe::factory(); - $ingredient_type = Recipe::class; - $ingredient_unit = 'serving'; - } - - return [ - 'ingredient_id' => $ingredient_factory, - 'ingredient_type' => $ingredient_type, - 'amount' => $this->faker->randomFloat(1, 1/3, 5), - 'unit' => $ingredient_unit, - 'detail' => $this->faker->optional(0.8)->realText(), - 'weight' => $this->faker->numberBetween(0, 50), - 'parent_id' => Recipe::factory(), - 'parent_type' => Recipe::class, - ]; - } - - /** - * Define a specific parent. - */ - public function parent(Model $parent): static - { - return $this->state(function (array $attributes) use ($parent) { - return [ - 'parent_id' => $parent->id, - 'parent_type' => $parent::class, - ]; - }); - } - - /** - * Define a specific ingredient. - */ - public function ingredient(Model $ingredient): static - { - return $this->state(function (array $attributes) use ($ingredient) { - return [ - 'ingredient_id' => $ingredient->id, - 'ingredient_type' => $ingredient::class, - ]; - }); - } -} diff --git a/database/factories/JournalEntryFactory.php b/database/factories/JournalEntryFactory.php deleted file mode 100644 index 3f4e188..0000000 --- a/database/factories/JournalEntryFactory.php +++ /dev/null @@ -1,35 +0,0 @@ - User::factory(), - 'date' => $this->faker->dateTimeThisMonth, - 'summary' => $this->faker->realText(50), - 'calories' => $this->faker->randomFloat(2, 0, 500), - 'fat' => $this->faker->randomFloat(2, 0, 50), - 'cholesterol' => $this->faker->randomFloat(2, 0, 2000), - 'sodium' => $this->faker->randomFloat(2, 0, 2000), - 'carbohydrates' => $this->faker->randomFloat(2, 0, 100), - 'protein' => $this->faker->randomFloat(2, 0, 100), - 'meal' => $this->faker->randomElement(['breakfast', 'lunch', 'dinner', 'snacks']), - ]; - } - -} diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php deleted file mode 100644 index ad2b21c..0000000 --- a/database/factories/RecipeFactory.php +++ /dev/null @@ -1,54 +0,0 @@ -faker->realText(500)); - return [ - 'name' => Words::randomWords(Arr::random(['npan', 'npn', 'anpn'])), - 'description' => "

{$description}

", - 'description_delta' => '{"ops":[{"insert":"' . $description . '\n"}]}"', - 'time_prep' => $this->faker->numberBetween(0, 20), - 'time_cook' => $this->faker->numberBetween(0, 90), - 'source' => $this->faker->optional()->url, - 'servings' => $this->faker->numberBetween(1, 10), - 'weight' => $this->faker->randomFloat(1, 60, 2000), - 'tags' => $this->faker->words, - ]; - } - - /** - * Create a recipe and add fake media to it. - */ - public function createOneWithMedia(array $attributes = []): Recipe { - Storage::fake('tests'); - /** @var \App\Models\Recipe $recipe */ - $recipe = $this->createOne($attributes); - $file = UploadedFile::fake()->image('recipe.jpg', 1600, 900); - $path = $file->store('tests'); - $recipe->addMediaFromDisk($path) - ->usingName($recipe->name) - ->usingFileName("{$recipe->slug}.jpg") - ->toMediaCollection(); - return $recipe; - } -} diff --git a/database/factories/RecipeSeparatorFactory.php b/database/factories/RecipeSeparatorFactory.php deleted file mode 100644 index db1ec52..0000000 --- a/database/factories/RecipeSeparatorFactory.php +++ /dev/null @@ -1,26 +0,0 @@ - 'ingredients', - 'weight' => $this->faker->numberBetween(0, 100), - 'text' => $this->faker->optional()->realText(20), - ]; - } -} diff --git a/database/factories/RecipeStepFactory.php b/database/factories/RecipeStepFactory.php deleted file mode 100644 index 1b45723..0000000 --- a/database/factories/RecipeStepFactory.php +++ /dev/null @@ -1,25 +0,0 @@ - $this->faker->numberBetween(1, 50), - 'step' => $this->faker->realText(500), - ]; - } -} diff --git a/database/factories/TagFactory.php b/database/factories/TagFactory.php deleted file mode 100644 index 40712ef..0000000 --- a/database/factories/TagFactory.php +++ /dev/null @@ -1,25 +0,0 @@ - Words::randomWords('a'), - ]; - } -} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php deleted file mode 100644 index f2d1bb8..0000000 --- a/database/factories/UserFactory.php +++ /dev/null @@ -1,29 +0,0 @@ - $this->faker->unique()->userName, - 'password' => Hash::make('password'), - 'name' => $this->faker->name, - 'remember_token' => Str::random(10), - ]; - } -} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php deleted file mode 100644 index 8c378cc..0000000 --- a/database/seeders/DatabaseSeeder.php +++ /dev/null @@ -1,19 +0,0 @@ -call(UserSeeder::class); - $this->call(FoodSeeder::class); - $this->call(RecipeSeeder::class); - $this->call(JournalEntrySeeder::class); - } -} diff --git a/database/seeders/FoodSeeder.php b/database/seeders/FoodSeeder.php deleted file mode 100644 index 36ac983..0000000 --- a/database/seeders/FoodSeeder.php +++ /dev/null @@ -1,162 +0,0 @@ - 'baking powder', - 'serving_size' => 1, - 'serving_unit' => 'tsp', - 'serving_weight' => 4.6, - 'calories' => 2.44, - 'fat' => 0, - 'cholesterol' => 0, - 'sodium' => 0.488, - 'carbohydrates' => 1.27, - 'protein' => 0, - ], - [ - 'name' => 'egg', - 'detail' => 'large', - 'serving_size' => 1, - 'serving_weight' => 50.3, - 'calories' => 71.9, - 'fat' => 5.01, - 'cholesterol' => 0.207, - 'sodium' => 0.0649, - 'carbohydrates' => 0.483, - 'protein' => 6.24, - ], - [ - 'name' => 'flour', - 'detail' => 'all-purpose', - 'serving_size' => 1, - 'serving_unit' => 'cup', - 'serving_weight' => 125, - 'calories' => 455, - 'fat' => 1.22, - 'cholesterol' => 0, - 'sodium' => 0.0025, - 'carbohydrates' => 95.4, - 'protein' => 12.9, - ], - [ - 'name' => 'milk', - 'detail' => 'whole', - 'serving_size' => 1, - 'serving_unit' => 'cup', - 'serving_weight' => 244, - 'calories' => 146, - 'fat' => 7.81, - 'cholesterol' => 0.0293, - 'sodium' => 0.0927, - 'carbohydrates' => 11.4, - 'protein' => 8, - ], - [ - 'name' => 'salt', - 'detail' => 'table', - 'serving_size' => 1, - 'serving_unit' => 'tsp', - 'serving_weight' => 6, - 'calories' => 0, - 'fat' => 0, - 'cholesterol' => 0, - 'sodium' => 2.33, - 'carbohydrates' => 0, - 'protein' => 0, - - ], - [ - 'name' => 'sugar', - 'detail' => 'white', - 'serving_size' => 1, - 'serving_unit' => 'cup', - 'serving_weight' => 200, - 'calories' => 770, - 'fat' => 0.64, - 'cholesterol' => 0, - 'sodium' => 0.002, - 'carbohydrates' => 199, - 'protein' => 0, - ], - [ - 'name' => 'vegetable oil', - 'serving_size' => 1, - 'serving_unit' => 'tbsp', - 'serving_weight' => 14, - 'calories' => 124, - 'fat' => 14, - 'cholesterol' => 0, - 'sodium' => 0, - 'carbohydrates' => 0, - 'protein' => 0, - ], - [ - 'name' => 'peanut butter', - 'detail' => 'organic creamy', - 'brand' => 'Kirkland', - 'serving_size' => 2, - 'serving_unit' => 'tbsp', - 'serving_weight' => 32, - 'calories' => 180, - 'fat' => 15, - 'cholesterol' => 0, - 'sodium' => 0.065, - 'carbohydrates' => 7, - 'protein' => 8, - ], - [ - 'name' => 'raisins', - 'brand' => 'Kroger', - 'serving_size' => 0.25, - 'serving_unit' => 'cup', - 'serving_weight' => 40, - 'calories' => 140, - 'fat' => 0, - 'cholesterol' => 0, - 'sodium' => 0.010, - 'carbohydrates' => 33, - 'protein' => 1, - ], - [ - 'name' => 'peanuts', - 'detail' => 'dry roasted, unsalted', - 'brand' => 'Kroger', - 'serving_size' => 0.25, - 'serving_unit' => 'cup', - 'serving_weight' => 28, - 'calories' => 160, - 'fat' => 14, - 'cholesterol' => 0, - 'sodium' => 0, - 'carbohydrates' => 6, - 'protein' => 7, - ], - [ - 'name' => 'canned corn', - 'detail' => 'golden sweet', - 'brand' => 'WinCo', - 'serving_size' => 0.5, - 'serving_unit' => 'cup', - 'serving_weight' => 125, - 'calories' => 60, - 'fat' => 0.5, - 'sodium' => 0.2, - 'carbohydrates' => 9, - 'protein' => 1, - ], - ]; - Food::factory()->createMany($default_foods); - } -} diff --git a/database/seeders/JournalEntrySeeder.php b/database/seeders/JournalEntrySeeder.php deleted file mode 100644 index 4cf0b85..0000000 --- a/database/seeders/JournalEntrySeeder.php +++ /dev/null @@ -1,128 +0,0 @@ -first(); - } - - /** @var \App\Models\Recipe $recipe */ - $recipe = Recipe::all()->first(); - - /** @var \App\Models\User $user */ - $user = User::all()->first; - - $default_entries = [ - [ - 'user_id' => $user->id, - 'date' => Carbon::now()->toDateString(), - 'summary' => '2 egg, 1 serving milk', - 'calories' => $foods['egg']->calories * 2 + $foods['milk']->calories, - 'fat' => $foods['egg']->fat * 2 + $foods['milk']->fat, - 'cholesterol' => $foods['egg']->cholesterol * 2 + $foods['milk']->cholesterol, - 'sodium' => $foods['egg']->sodium * 2 + $foods['milk']->sodium, - 'carbohydrates' => $foods['egg']->carbohydrates * 2 + $foods['milk']->carbohydrates, - 'protein' => $foods['egg']->protein * 2 + $foods['milk']->protein, - 'meal' => 'breakfast', - ], - [ - 'user_id' => $user->id, - 'date' => Carbon::now()->toDateString(), - 'summary' => '1 serving pancakes', - 'calories' => $recipe->caloriesPerServing(), - 'fat' => $recipe->fatPerServing(), - 'cholesterol' => $recipe->cholesterolPerServing(), - 'sodium' => $recipe->sodiumPerServing(), - 'carbohydrates' => $recipe->carbohydratesPerServing(), - 'protein' => $recipe->proteinPerServing(), - 'meal' => 'lunch', - ], - [ - 'user_id' => $user->id, - 'date' => Carbon::now()->toDateString(), - 'summary' => '1 serving pancakes', - 'calories' => $recipe->caloriesPerServing(), - 'fat' => $recipe->fatPerServing(), - 'cholesterol' => $recipe->cholesterolPerServing(), - 'sodium' => $recipe->sodiumPerServing(), - 'carbohydrates' => $recipe->carbohydratesPerServing(), - 'protein' => $recipe->proteinPerServing(), - 'meal' => 'dinner', - ], - [ - 'user_id' => $user->id, - 'date' => Carbon::now()->toDateString(), - 'summary' => '1 serving peanut butter', - 'calories' => $foods['peanut butter']->calories, - 'fat' => $foods['peanut butter']->fat, - 'cholesterol' => $foods['peanut butter']->cholesterol, - 'sodium' => $foods['peanut butter']->sodium, - 'carbohydrates' => $foods['peanut butter']->carbohydrates, - 'protein' => $foods['peanut butter']->protein, - 'meal' => 'snacks', - ], - [ - 'user_id' => $user->id, - 'date' => Carbon::now()->toDateString(), - 'summary' => '2 servings raisins', - 'calories' => $foods['raisins']->calories * 2, - 'fat' => $foods['raisins']->fat * 2, - 'cholesterol' => $foods['raisins']->cholesterol * 2, - 'sodium' => $foods['raisins']->sodium * 2, - 'carbohydrates' => $foods['raisins']->carbohydrates * 2, - 'protein' => $foods['raisins']->protein * 2, - 'meal' => 'snacks', - ], - ]; - JournalEntry::factory()->createMany($default_entries); - - DB::table('journalables')->insert([ - 'journal_entry_id' => 1, - 'journalable_id' => $foods['egg']->id, - 'journalable_type' => Food::class, - ]); - DB::table('journalables')->insert([ - 'journal_entry_id' => 1, - 'journalable_id' => $foods['milk']->id, - 'journalable_type' => Food::class, - ]); - DB::table('journalables')->insert([ - 'journal_entry_id' => 2, - 'journalable_id' => $recipe->id, - 'journalable_type' => Recipe::class, - ]); - DB::table('journalables')->insert([ - 'journal_entry_id' => 3, - 'journalable_id' => $recipe->id, - 'journalable_type' => Recipe::class, - ]); - DB::table('journalables')->insert([ - 'journal_entry_id' => 4, - 'journalable_id' => $foods['peanut butter']->id, - 'journalable_type' => Food::class, - ]); - DB::table('journalables')->insert([ - 'journal_entry_id' => 5, - 'journalable_id' => $foods['raisins']->id, - 'journalable_type' => Food::class, - ]); - } -} diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php deleted file mode 100644 index aa296c3..0000000 --- a/database/seeders/RecipeSeeder.php +++ /dev/null @@ -1,159 +0,0 @@ -create([ - 'name' => 'pancakes', - 'description' => 'Basic pancakes in two steps.', - 'servings' => 4, - ]); - - $weight = 0; - $amounts = [ - [ - 'ingredient_id' => Food::where('name', 'flour') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 4.25, - 'unit' => 'oz', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight++, - ], - [ - 'ingredient_id' => Food::where('name', 'sugar') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 2, - 'unit' => 'tbsp', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight++, - ], - [ - 'ingredient_id' => Food::where('name', 'baking powder') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 2, - 'unit' => 'tsp', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight++, - ], - [ - 'ingredient_id' => Food::where('name', 'salt') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 1, - 'unit' => 'tsp', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight++, - ], - [ - 'ingredient_id' => Food::where('name', 'egg') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 1, - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight++, - ], - [ - 'ingredient_id' => Food::where('name', 'milk') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 1, - 'unit' => 'cup', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight++, - ], - [ - 'ingredient_id' => Food::where('name', 'vegetable oil') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 2, - 'unit' => 'tbsp', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight, - ], - ]; - IngredientAmount::factory()->createMany($amounts); - - $steps = [ - [ - 'recipe_id' => $recipe->id, - 'number' => 1, - 'step' => 'In a large bowl, mix flour, sugar, baking powder and salt. Make a well in the center, and pour in milk, egg and oil. Mix until smooth.', - ], - [ - 'recipe_id' => $recipe->id, - 'number' => 2, - 'step' => 'Heat a lightly oiled griddle or frying pan over medium high heat. Pour or scoop the batter onto the griddle, using approximately 1/4 cup for each pancake. Brown on both sides and serve hot.', - ] - ]; - RecipeStep::factory()->createMany($steps); - - /** @var \App\Models\Recipe $recipe */ - $recipe = Recipe::factory()->create([ - 'name' => 'peanut butter corn', - 'description' => 'Peanut butter and corn -- YUM', - 'servings' => 4, - ]); - - $weight = 0; - $amounts = [ - [ - 'ingredient_id' => Food::where('name', 'peanut butter') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 2, - 'unit' => 'cup', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight++, - ], - [ - 'ingredient_id' => Food::where('name', 'canned corn') - ->first()->id, - 'ingredient_type' => Food::class, - 'amount' => 15.25, - 'unit' => 'oz', - 'parent_id' => $recipe->id, - 'parent_type' => Recipe::class, - 'weight' => $weight, - ], - ]; - IngredientAmount::factory()->createMany($amounts); - - $steps = [ - [ - 'recipe_id' => $recipe->id, - 'number' => 1, - 'step' => 'Mix it together.', - ], - [ - 'recipe_id' => $recipe->id, - 'number' => 2, - 'step' => 'Eat it.', - ] - ]; - RecipeStep::factory()->createMany($steps); - } -} diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php deleted file mode 100644 index 7f209ea..0000000 --- a/database/seeders/UserSeeder.php +++ /dev/null @@ -1,24 +0,0 @@ -create([ - 'username' => 'admin', - 'password' => Hash::make('admin'), - 'name' => 'Admin', - 'remember_token' => Str::random(10), - ]); - } -}