feat: migrations
Laravel CI-CD / Tests Unitaires (push) Successful in 1m28s Details
Laravel CI-CD / Deploy with Kamal (push) Successful in 1m47s Details

This commit is contained in:
Leon Morival 2026-05-22 12:43:30 +02:00
parent 071d147888
commit 73315b7354
6 changed files with 51 additions and 84 deletions

View File

@ -19,6 +19,10 @@ return new class extends Migration
$table->string('password');
$table->text('bio')->nullable();
$table->string('avatar_url', 2048)->nullable();
$table->unsignedInteger('daily_calorie_goal')->default(2000)->after('avatar_url');
$table->decimal('daily_protein_goal', 8, 2)->default(120)->after('daily_calorie_goal');
$table->decimal('daily_carbs_goal', 8, 2)->default(250)->after('daily_protein_goal');
$table->decimal('daily_fats_goal', 8, 2)->default(70)->after('daily_carbs_goal');
$table->rememberToken();
$table->timestamps();
});

View File

@ -18,6 +18,8 @@ return new class extends Migration
$table->decimal('carbs', 8, 2)->nullable();
$table->decimal('fats', 8, 2)->nullable();
$table->string('title');
$table->string('type')->default('breakfast');
$table->string('visibility', 20)->default('private')->index();
$table->timestamp('eaten_at');
$table->timestamps();
$table->softDeletes();

View File

@ -1,26 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('meal_posts', function (Blueprint $table): void {
$table
->string('visibility', 20)
->default('private')
->index();
});
}
public function down(): void
{
Schema::table('meal_posts', function (Blueprint $table): void {
$table->dropIndex(['visibility']);
$table->dropColumn('visibility');
});
}
};

View File

@ -1,30 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table): void {
$table->unsignedInteger('daily_calorie_goal')->default(2000)->after('avatar_url');
$table->decimal('daily_protein_goal', 8, 2)->default(120)->after('daily_calorie_goal');
$table->decimal('daily_carbs_goal', 8, 2)->default(250)->after('daily_protein_goal');
$table->decimal('daily_fats_goal', 8, 2)->default(70)->after('daily_carbs_goal');
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table): void {
$table->dropColumn([
'daily_calorie_goal',
'daily_protein_goal',
'daily_carbs_goal',
'daily_fats_goal',
]);
});
}
};

View File

@ -1,28 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('meal_posts', function (Blueprint $table) {
$table->string('type')->default('breakfast');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('meal_posts', function (Blueprint $table) {
$table->dropColumn('type');
});
}
};

View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (DB::connection()->getDriverName() !== 'pgsql') {
return;
}
DB::statement('ALTER TABLE notifications ALTER COLUMN notifiable_id TYPE char(26) USING notifiable_id::text');
DB::statement('ALTER TABLE notifications ALTER COLUMN data TYPE jsonb USING data::jsonb');
}
/**
* Reverse the migrations.
*/
public function down(): void
{
if (DB::connection()->getDriverName() !== 'pgsql') {
return;
}
DB::statement('ALTER TABLE notifications ALTER COLUMN data TYPE text USING data::text');
DB::statement(<<<'SQL'
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM notifications
WHERE notifiable_id !~ '^[0-9]+$'
) THEN
ALTER TABLE notifications
ALTER COLUMN notifiable_id TYPE bigint USING notifiable_id::bigint;
END IF;
END $$;
SQL);
}
};