mirror of https://github.com/kcal-app/kcal.git
Remove development migrations
This commit is contained in:
parent
08b8c63622
commit
465c466a93
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Food;
|
||||
use App\Models\Recipe;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFoodAmountsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('food_amounts', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class MakeRecipeDescriptionOptional extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('recipes', function (Blueprint $table) {
|
||||
$table->string('description')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('recipes', function (Blueprint $table) {
|
||||
$table->string('description')->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Food;
|
||||
use App\Models\Recipe;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ConvertNamesLowercase extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
foreach (Recipe::all() as $recipe) {
|
||||
$recipe->name = Str::lower($recipe->name);
|
||||
$recipe->save();
|
||||
}
|
||||
foreach (Food::all() as $recipe) {
|
||||
$recipe->name = Str::lower($recipe->name);
|
||||
$recipe->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddFoodAmountDetailColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('food_amounts', function (Blueprint $table) {
|
||||
$table->string('detail')->nullable()->after('unit');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('food_amounts', function (Blueprint $table) {
|
||||
$table->dropColumn('detail');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRecipeSourceColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('recipes', function (Blueprint $table) {
|
||||
$table->string('source')->nullable()->after('description');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('recipes', function (Blueprint $table) {
|
||||
$table->dropColumn('source');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ConvertFoodAmountsToIngredientAmounts extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('ingredient_amounts')->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddSourceAndNotesToFoods extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('foods', function (Blueprint $table) {
|
||||
$table->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']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddServingUnitNameFieldToFoods extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('foods', function (Blueprint $table) {
|
||||
$table->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']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ConvertCholesterolAndSodiumToMg extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::update("UPDATE `foods` SET `cholesterol` = `cholesterol` * 1000;");
|
||||
DB::update("UPDATE `foods` SET `sodium` = `sodium` * 1000;");
|
||||
DB::update("UPDATE `journal_entries` SET `cholesterol` = `cholesterol` * 1000;");
|
||||
DB::update("UPDATE `journal_entries` SET `sodium` = `sodium` * 1000;");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::update("UPDATE `foods` SET `cholesterol` = `cholesterol`/1000;");
|
||||
DB::update("UPDATE `foods` SET `sodium` = `sodium`/1000;");
|
||||
DB::update("UPDATE `journal_entries` SET `cholesterol` = `cholesterol`/1000;");
|
||||
DB::update("UPDATE `journal_entries` SET `sodium` = `sodium`/1000;");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddWeightColumnToRecipes extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('recipes', function (Blueprint $table) {
|
||||
$table->unsignedFloat('weight')->nullable()->after('servings');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('recipes', function (Blueprint $table) {
|
||||
$table->dropColumn('weight');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropFoodAmountsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('food_amounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Models\JournalEntry;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCascadeConstraints extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Recipe steps.
|
||||
Schema::rename('recipe_steps', 'recipe_steps_old');
|
||||
Schema::create('recipe_steps', function (Blueprint $table) {
|
||||
$table->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()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue