From 465c466a93d95aef4c021bf681118824f79e018d Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Fri, 19 Feb 2021 09:14:26 -0800 Subject: [PATCH] Remove development migrations --- .../2020_12_21_214128_create_foods_table.php | 1 + ...12_21_215527_create_food_amounts_table.php | 39 -------- ...24712_make_recipe_description_optional.php | 32 ------- ...1_01_18_083429_convert_names_lowercase.php | 27 ------ ...8_084734_add_food_amount_detail_column.php | 32 ------- ..._01_18_090224_add_recipe_source_column.php | 32 ------- ...ert_food_amounts_to_ingredient_amounts.php | 62 ------------- ...7_054520_add_source_and_notes_to_foods.php | 33 ------- ...3_add_serving_unit_name_field_to_foods.php | 32 ------- ...6_convert_cholesterol_and_sodium_to_mg.php | 34 ------- ...11_192732_add_weight_column_to_recipes.php | 32 ------- ...1_02_19_055501_drop_food_amounts_table.php | 27 ------ ...1_02_19_080648_add_cascade_constraints.php | 88 ------------------- 13 files changed, 1 insertion(+), 470 deletions(-) delete mode 100644 database/migrations/2020_12_21_215527_create_food_amounts_table.php delete mode 100644 database/migrations/2021_01_15_124712_make_recipe_description_optional.php delete mode 100644 database/migrations/2021_01_18_083429_convert_names_lowercase.php delete mode 100644 database/migrations/2021_01_18_084734_add_food_amount_detail_column.php delete mode 100644 database/migrations/2021_01_18_090224_add_recipe_source_column.php delete mode 100644 database/migrations/2021_01_22_224514_convert_food_amounts_to_ingredient_amounts.php delete mode 100644 database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php delete mode 100644 database/migrations/2021_02_03_205453_add_serving_unit_name_field_to_foods.php delete mode 100644 database/migrations/2021_02_10_134156_convert_cholesterol_and_sodium_to_mg.php delete mode 100644 database/migrations/2021_02_11_192732_add_weight_column_to_recipes.php delete mode 100644 database/migrations/2021_02_19_055501_drop_food_amounts_table.php delete mode 100644 database/migrations/2021_02_19_080648_add_cascade_constraints.php diff --git a/database/migrations/2020_12_21_214128_create_foods_table.php b/database/migrations/2020_12_21_214128_create_foods_table.php index 9c8cb75..ee17ae1 100644 --- a/database/migrations/2020_12_21_214128_create_foods_table.php +++ b/database/migrations/2020_12_21_214128_create_foods_table.php @@ -21,6 +21,7 @@ class CreateFoodsTable extends Migration $table->string('notes')->nullable(); $table->unsignedFloat('serving_size'); $table->enum('serving_unit', ['tsp', 'tbsp', 'cup', 'oz'])->nullable(); + $table->string('serving_unit_name')->nullable(); $table->unsignedFloat('serving_weight'); $table->unsignedFloat('calories')->default(0); $table->unsignedFloat('fat')->default(0); diff --git a/database/migrations/2020_12_21_215527_create_food_amounts_table.php b/database/migrations/2020_12_21_215527_create_food_amounts_table.php deleted file mode 100644 index 7321bf3..0000000 --- a/database/migrations/2020_12_21_215527_create_food_amounts_table.php +++ /dev/null @@ -1,39 +0,0 @@ -id(); - $table->foreignIdFor(Food::class)->index(); - $table->unsignedFloat('amount'); - $table->enum('unit', ['tsp', 'tbsp', 'cup', 'oz'])->nullable(); - $table->string('detail')->nullable(); - $table->foreignIdFor(Recipe::class)->index(); - $table->unsignedInteger('weight'); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('food_amounts'); - } -} diff --git a/database/migrations/2021_01_15_124712_make_recipe_description_optional.php b/database/migrations/2021_01_15_124712_make_recipe_description_optional.php deleted file mode 100644 index 28344f4..0000000 --- a/database/migrations/2021_01_15_124712_make_recipe_description_optional.php +++ /dev/null @@ -1,32 +0,0 @@ -string('description')->nullable()->change(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('recipes', function (Blueprint $table) { - $table->string('description')->change(); - }); - } -} diff --git a/database/migrations/2021_01_18_083429_convert_names_lowercase.php b/database/migrations/2021_01_18_083429_convert_names_lowercase.php deleted file mode 100644 index 300a35b..0000000 --- a/database/migrations/2021_01_18_083429_convert_names_lowercase.php +++ /dev/null @@ -1,27 +0,0 @@ -name = Str::lower($recipe->name); - $recipe->save(); - } - foreach (Food::all() as $recipe) { - $recipe->name = Str::lower($recipe->name); - $recipe->save(); - } - } - -} diff --git a/database/migrations/2021_01_18_084734_add_food_amount_detail_column.php b/database/migrations/2021_01_18_084734_add_food_amount_detail_column.php deleted file mode 100644 index 5aabd4c..0000000 --- a/database/migrations/2021_01_18_084734_add_food_amount_detail_column.php +++ /dev/null @@ -1,32 +0,0 @@ -string('detail')->nullable()->after('unit'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('food_amounts', function (Blueprint $table) { - $table->dropColumn('detail'); - }); - } -} diff --git a/database/migrations/2021_01_18_090224_add_recipe_source_column.php b/database/migrations/2021_01_18_090224_add_recipe_source_column.php deleted file mode 100644 index 89743a2..0000000 --- a/database/migrations/2021_01_18_090224_add_recipe_source_column.php +++ /dev/null @@ -1,32 +0,0 @@ -string('source')->nullable()->after('description'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('recipes', function (Blueprint $table) { - $table->dropColumn('source'); - }); - } -} diff --git a/database/migrations/2021_01_22_224514_convert_food_amounts_to_ingredient_amounts.php b/database/migrations/2021_01_22_224514_convert_food_amounts_to_ingredient_amounts.php deleted file mode 100644 index b5ff2fb..0000000 --- a/database/migrations/2021_01_22_224514_convert_food_amounts_to_ingredient_amounts.php +++ /dev/null @@ -1,62 +0,0 @@ -truncate(); - $query = "INSERT INTO ingredient_amounts (ingredient_id, ingredient_type, amount, unit, detail, weight, parent_id, parent_type, created_at, updated_at) VALUES "; - $foodAmounts = DB::select(DB::raw("SELECT * FROM food_amounts;")); - foreach ($foodAmounts as $foodAmount) { - $query .= sprintf("(%d, '%s', %s, %s, %s, %s, %d, '%s', '%s', '%s'),", ...[ - $foodAmount->food_id, - 'App\Models\Food', - $foodAmount->amount, - $foodAmount->unit ? "'{$foodAmount->unit}'" : 'null', - $foodAmount->detail ? "'" . addslashes($foodAmount->detail) . "'" : 'null', - $foodAmount->weight, - $foodAmount->recipe_id, - 'App\Models\Recipe', - $foodAmount->created_at, - $foodAmount->updated_at, - ]); - } - $query = substr($query, 0, -1) . ';'; - DB::unprepared($query); - DB::table('food_amounts')->truncate(); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - DB::table('food_amounts')->truncate(); - $query = "INSERT INTO food_amounts (food_id, amount, unit, recipe_id, weight, created_at, updated_at, detail) VALUES "; - $ingredientAmounts = DB::select(DB::raw("SELECT * FROM ingredient_amounts WHERE ingredient_type = 'App\Models\Food';")); - foreach ($ingredientAmounts as $ingredientAmount) { - $query .= sprintf("(%d, %s, %s, %d, %s, '%s', '%s', %s),", ...[ - $ingredientAmount->ingredient_id, - $ingredientAmount->amount, - $ingredientAmount->unit ? "'{$ingredientAmount->unit}'" : 'null', - $ingredientAmount->parent_id, - $ingredientAmount->weight, - $ingredientAmount->created_at, - $ingredientAmount->updated_at, - $ingredientAmount->detail ? "'" . addslashes($ingredientAmount->detail) . "'" : 'null', - ]); - } - $query = substr($query, 0, -1) . ';'; - DB::unprepared($query); - DB::table('ingredient_amounts')->truncate(); - } -} diff --git a/database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php b/database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php deleted file mode 100644 index 131a28f..0000000 --- a/database/migrations/2021_01_27_054520_add_source_and_notes_to_foods.php +++ /dev/null @@ -1,33 +0,0 @@ -string('source')->nullable()->after('brand'); - $table->string('notes')->nullable()->after('brand'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('foods', function (Blueprint $table) { - $table->dropColumn(['source', 'notes']); - }); - } -} diff --git a/database/migrations/2021_02_03_205453_add_serving_unit_name_field_to_foods.php b/database/migrations/2021_02_03_205453_add_serving_unit_name_field_to_foods.php deleted file mode 100644 index dfe2f80..0000000 --- a/database/migrations/2021_02_03_205453_add_serving_unit_name_field_to_foods.php +++ /dev/null @@ -1,32 +0,0 @@ -string('serving_unit_name')->nullable()->after('serving_unit'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('foods', function (Blueprint $table) { - $table->dropColumn(['serving_unit_name']); - }); - } -} diff --git a/database/migrations/2021_02_10_134156_convert_cholesterol_and_sodium_to_mg.php b/database/migrations/2021_02_10_134156_convert_cholesterol_and_sodium_to_mg.php deleted file mode 100644 index 6d4fcfe..0000000 --- a/database/migrations/2021_02_10_134156_convert_cholesterol_and_sodium_to_mg.php +++ /dev/null @@ -1,34 +0,0 @@ -unsignedFloat('weight')->nullable()->after('servings'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('recipes', function (Blueprint $table) { - $table->dropColumn('weight'); - }); - } -} diff --git a/database/migrations/2021_02_19_055501_drop_food_amounts_table.php b/database/migrations/2021_02_19_055501_drop_food_amounts_table.php deleted file mode 100644 index e3c2679..0000000 --- a/database/migrations/2021_02_19_055501_drop_food_amounts_table.php +++ /dev/null @@ -1,27 +0,0 @@ -id(); - $table->foreignIdFor(Recipe::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete(); - $table->unsignedInteger('number'); - $table->longText('step'); - $table->timestamps(); - }); - DB::insert("INSERT INTO `recipe_steps` SELECT * FROM `recipe_steps_old`;"); - Schema::dropIfExists('recipe_steps_old'); - Schema::table('recipe_steps', function (Blueprint $table) { - $table->index('recipe_id'); - $table->index('number'); - }); - - // Journal entries. - Schema::rename('journal_entries', 'journal_entries_old'); - Schema::create('journal_entries', function (Blueprint $table) { - $table->id(); - $table->foreignIdFor(User::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete(); - $table->date('date')->useCurrent(); - $table->string('summary'); - $table->unsignedFloat('calories')->default(0); - $table->unsignedFloat('fat')->default(0); - $table->unsignedFloat('cholesterol')->default(0); - $table->unsignedFloat('sodium')->default(0); - $table->unsignedFloat('carbohydrates')->default(0); - $table->unsignedFloat('protein')->default(0); - $table->enum('meal', ['breakfast', 'lunch', 'dinner', 'snacks']); - $table->timestamps(); - }); - DB::insert("INSERT INTO `journal_entries` SELECT * FROM `journal_entries_old`;"); - Schema::dropIfExists('journal_entries_old'); - Schema::table('journal_entries', function (Blueprint $table) { - $table->index('user_id'); - $table->index('date'); - }); - - // Journalables. - Schema::rename('journalables', 'journalables_old'); - Schema::create('journalables', function (Blueprint $table) { - $table->foreignIdFor(JournalEntry::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete(); - $table->unsignedInteger('journalable_id'); - $table->string('journalable_type'); - }); - DB::delete("DELETE FROM `journalables_old` WHERE `journal_entry_id` NOT IN (SELECT `id` FROM `journal_entries`);"); - DB::insert("INSERT INTO `journalables` SELECT * FROM `journalables_old`;"); - Schema::dropIfExists('journalables_old'); - Schema::table('journalables', function (Blueprint $table) { - $table->index('journal_entry_id'); - }); - - // Ingredient amounts (index only). - Schema::table('ingredient_amounts', function (Blueprint $table) { - $table->index('parent_id'); - }); - - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - // - } -}