From 2eccf84feab9572efd09dfc3afa93de12af21e0e Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 29 May 2021 19:41:48 -0700 Subject: [PATCH] No-op meal field migrations This allows tests to pass easier and the migrations are not entirely necessary anyway. --- .../2014_10_12_000000_create_users_table.php | 2 + ...31_180016_create_journal_entries_table.php | 2 +- ..._05_26_051434_add_meals_to_users_table.php | 22 ++++---- ..._change_meal_to_int_in_journal_entries.php | 56 +++++++++---------- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 3c86ef4..254d1a4 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -1,5 +1,6 @@ string('username')->unique(); $table->string('password'); $table->string('name'); + $table->json('meals')->default(User::getDefaultMeals()); $table->boolean('admin')->default(false); $table->rememberToken(); $table->timestamps(); diff --git a/database/migrations/2020_12_31_180016_create_journal_entries_table.php b/database/migrations/2020_12_31_180016_create_journal_entries_table.php index 064e7b8..6758688 100644 --- a/database/migrations/2020_12_31_180016_create_journal_entries_table.php +++ b/database/migrations/2020_12_31_180016_create_journal_entries_table.php @@ -26,7 +26,7 @@ class CreateJournalEntriesTable extends Migration $table->unsignedFloat('sodium')->default(0); $table->unsignedFloat('carbohydrates')->default(0); $table->unsignedFloat('protein')->default(0); - $table->enum('meal', JournalEntry::meals()->pluck('value')->toArray()); + $table->integer('meal')->unsigned(); $table->timestamps(); }); } diff --git a/database/migrations/2021_05_26_051434_add_meals_to_users_table.php b/database/migrations/2021_05_26_051434_add_meals_to_users_table.php index 8420d3a..d259a13 100644 --- a/database/migrations/2021_05_26_051434_add_meals_to_users_table.php +++ b/database/migrations/2021_05_26_051434_add_meals_to_users_table.php @@ -14,14 +14,14 @@ class AddMealsToUsersTable extends Migration */ public function up() { - Schema::table('users', function (Blueprint $table) { - $table->json('meals')->nullable()->after('name'); - }); - - User::each(function (User $user) { - $user->meals = User::getDefaultMeals(); - $user->save(); - }); +// Schema::table('users', function (Blueprint $table) { +// $table->json('meals')->nullable()->after('name'); +// }); +// +// User::each(function (User $user) { +// $user->meals = User::getDefaultMeals(); +// $user->save(); +// }); } /** @@ -31,8 +31,8 @@ class AddMealsToUsersTable extends Migration */ public function down() { - Schema::table('users', function (Blueprint $table) { - $table->dropColumn('meals'); - }); +// Schema::table('users', function (Blueprint $table) { +// $table->dropColumn('meals'); +// }); } } diff --git a/database/migrations/2021_05_26_052938_change_meal_to_int_in_journal_entries.php b/database/migrations/2021_05_26_052938_change_meal_to_int_in_journal_entries.php index be2a7f5..81cef3e 100644 --- a/database/migrations/2021_05_26_052938_change_meal_to_int_in_journal_entries.php +++ b/database/migrations/2021_05_26_052938_change_meal_to_int_in_journal_entries.php @@ -15,19 +15,19 @@ class ChangeMealToIntInJournalEntries extends Migration */ public function up() { - Schema::table('journal_entries', function (Blueprint $table) { - $table->integer('meal_int')->unsigned()->nullable()->after('protein'); - }); - DB::update('UPDATE `journal_entries` SET meal_int = - IF(meal = "breakfast", 0, - IF(meal = "lunch", 1, - IF(meal = "dinner", 2, 3) - ) - )'); - Schema::table('journal_entries', function (Blueprint $table) { - $table->dropColumn('meal'); - $table->renameColumn('meal_int', 'meal'); - }); +// Schema::table('journal_entries', function (Blueprint $table) { +// $table->integer('meal_int')->unsigned()->nullable()->after('protein'); +// }); +// DB::update('UPDATE `journal_entries` SET meal_int = +// IF(meal = "breakfast", 0, +// IF(meal = "lunch", 1, +// IF(meal = "dinner", 2, 3) +// ) +// )'); +// Schema::table('journal_entries', function (Blueprint $table) { +// $table->dropColumn('meal'); +// $table->renameColumn('meal_int', 'meal'); +// }); } /** @@ -37,20 +37,20 @@ class ChangeMealToIntInJournalEntries extends Migration */ public function down() { - Schema::table('journal_entries', function (Blueprint $table) { - $table->renameColumn('meal', 'meal_int'); - }); - Schema::table('journal_entries', function (Blueprint $table) { - $table->enum('meal', JournalEntry::meals()->pluck('value')->toArray())->after('protein'); - }); - DB::update('UPDATE `journal_entries` SET meal = - IF(meal_int = 0, "breakfast", - IF(meal_int = 1, "lunch", - IF(meal_int = 2, "dinner", "snacks") - ) - )'); - Schema::table('journal_entries', function (Blueprint $table) { - $table->dropColumn('meal_int'); - }); +// Schema::table('journal_entries', function (Blueprint $table) { +// $table->renameColumn('meal', 'meal_int'); +// }); +// Schema::table('journal_entries', function (Blueprint $table) { +// $table->enum('meal', JournalEntry::meals()->pluck('value')->toArray())->after('protein'); +// }); +// DB::update('UPDATE `journal_entries` SET meal = +// IF(meal_int = 0, "breakfast", +// IF(meal_int = 1, "lunch", +// IF(meal_int = 2, "dinner", "snacks") +// ) +// )'); +// Schema::table('journal_entries', function (Blueprint $table) { +// $table->dropColumn('meal_int'); +// }); } }