feat: clean migrations
This commit is contained in:
parent
73315b7354
commit
6a100c03fa
|
|
@ -17,14 +17,34 @@ return new class extends Migration
|
||||||
$table->string('email')->unique();
|
$table->string('email')->unique();
|
||||||
$table->timestamp('email_verified_at')->nullable();
|
$table->timestamp('email_verified_at')->nullable();
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
|
$table->string('role')->default('user');
|
||||||
$table->text('bio')->nullable();
|
$table->text('bio')->nullable();
|
||||||
|
$table->integer('height')->nullable();
|
||||||
|
$table->date('date_of_birth')->nullable();
|
||||||
|
$table->string('sex')->default('unknown');
|
||||||
|
$table->string('physical_activity_level')->default('sedentary');
|
||||||
|
$table->string('weight_goal')->default('lose_weight');
|
||||||
|
$table->string('pace_preference')->default('slow');
|
||||||
|
$table->string('locale', 8)->default('en')->after('email');
|
||||||
$table->string('avatar_url', 2048)->nullable();
|
$table->string('avatar_url', 2048)->nullable();
|
||||||
|
|
||||||
|
// Goals
|
||||||
$table->unsignedInteger('daily_calorie_goal')->default(2000)->after('avatar_url');
|
$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_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_carbs_goal', 8, 2)->default(250)->after('daily_protein_goal');
|
||||||
$table->decimal('daily_fats_goal', 8, 2)->default(70)->after('daily_carbs_goal');
|
$table->decimal('daily_fats_goal', 8, 2)->default(70)->after('daily_carbs_goal');
|
||||||
|
// Moderation
|
||||||
|
$table->timestamp('suspended_at')->nullable()->after('deleted_at')->index();
|
||||||
|
$table->ulid('suspended_by')->nullable()->after('suspended_at')->index();
|
||||||
|
$table->text('suspended_reason')->nullable()->after('suspended_by');
|
||||||
$table->rememberToken();
|
$table->rememberToken();
|
||||||
|
$table->timestampTz('account_verified_at')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
$table->softDeletesTz();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->foreign('suspended_by')->references('id')->on('users')->nullOnDelete();
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,14 @@ return new class extends Migration
|
||||||
$table->decimal('proteins', 8, 2)->nullable();
|
$table->decimal('proteins', 8, 2)->nullable();
|
||||||
$table->decimal('carbs', 8, 2)->nullable();
|
$table->decimal('carbs', 8, 2)->nullable();
|
||||||
$table->decimal('fats', 8, 2)->nullable();
|
$table->decimal('fats', 8, 2)->nullable();
|
||||||
|
$table->string('diet_type')->default('omnivore');
|
||||||
|
$table->boolean('ai_generated')->default(false)->index();
|
||||||
$table->string('title');
|
$table->string('title');
|
||||||
$table->string('type')->default('breakfast');
|
$table->string('type')->default('breakfast');
|
||||||
$table->string('visibility', 20)->default('private')->index();
|
$table->string('visibility', 20)->default('private')->index();
|
||||||
|
$table->timestamp('hidden_at')->nullable()->after('deleted_at')->index();
|
||||||
|
$table->foreignUlid('hidden_by')->nullable()->after('hidden_at')->constrained('users')->nullOnDelete();
|
||||||
|
$table->text('hidden_reason')->nullable()->after('hidden_by');
|
||||||
$table->timestamp('eaten_at');
|
$table->timestamp('eaten_at');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->softDeletes();
|
$table->softDeletes();
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ return new class extends Migration
|
||||||
$table->uuid('id')->primary();
|
$table->uuid('id')->primary();
|
||||||
$table->string('type');
|
$table->string('type');
|
||||||
$table->ulidMorphs('notifiable');
|
$table->ulidMorphs('notifiable');
|
||||||
$table->text('data');
|
$table->jsonb('data');
|
||||||
$table->timestamp('read_at')->nullable();
|
$table->timestamp('read_at')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ return new class extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignUlid('meal_posts_id')->constrained('meal_posts')->cascadeOnDelete();
|
$table->foreignUlid('meal_posts_id')->constrained('meal_posts')->cascadeOnDelete();
|
||||||
$table->integer('position');
|
$table->integer('position');
|
||||||
|
$table->unsignedInteger('quantity')->default(1);
|
||||||
$table->string('ingredient');
|
$table->string('ingredient');
|
||||||
$table->string('unit');
|
$table->string('unit');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
|
||||||
|
|
@ -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_post_ingredients', function (Blueprint $table) {
|
|
||||||
$table->unsignedInteger('quantity')->default(1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('meal_post_ingredients', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('quantity');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -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('users', function (Blueprint $table) {
|
|
||||||
$table->integer('height')->nullable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('user', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('height');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,29 +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->boolean('ai_generated')->default(false)->index();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('meal_posts', function (Blueprint $table) {
|
|
||||||
$table->dropIndex(['ai_generated']);
|
|
||||||
$table->dropColumn('ai_generated');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -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('diet_type')->default('omnivore');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('meal_posts', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('diet_type');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,38 +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('users', function (Blueprint $table) {
|
|
||||||
$table->date('date_of_birth')->nullable();
|
|
||||||
$table->string('sex')->default('unknown');
|
|
||||||
$table->string('physical_activity_level')->default('sedentary');
|
|
||||||
$table->string('weight_goal')->default('lose_weight');
|
|
||||||
$table->string('pace_preference')->default('slow');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->dropColumn([
|
|
||||||
'date_of_birth',
|
|
||||||
'sex',
|
|
||||||
'physical_activity_level',
|
|
||||||
'weight_goal',
|
|
||||||
'pace_preference',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -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('users', function (Blueprint $table) {
|
|
||||||
$table->timestampTz('account_verified_at')->nullable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -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('users', function (Blueprint $table) {
|
|
||||||
$table->string('locale', 8)->default('en')->after('email');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('locale');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -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('users', function (Blueprint $table) {
|
|
||||||
$table->string('role')->default('user');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('role');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -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('users', function (Blueprint $table) {
|
|
||||||
$table->softDeletesTz();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->dropSoftDeletesTz();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,31 +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->timestamp('hidden_at')->nullable()->after('deleted_at')->index();
|
|
||||||
$table->foreignUlid('hidden_by')->nullable()->after('hidden_at')->constrained('users')->nullOnDelete();
|
|
||||||
$table->text('hidden_reason')->nullable()->after('hidden_by');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('meal_posts', function (Blueprint $table) {
|
|
||||||
$table->dropForeign(['hidden_by']);
|
|
||||||
$table->dropColumn(['hidden_at', 'hidden_by', 'hidden_reason']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,31 +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('users', function (Blueprint $table) {
|
|
||||||
$table->timestamp('suspended_at')->nullable()->after('deleted_at')->index();
|
|
||||||
$table->foreignUlid('suspended_by')->nullable()->after('suspended_at')->constrained('users')->nullOnDelete();
|
|
||||||
$table->text('suspended_reason')->nullable()->after('suspended_by');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->dropForeign(['suspended_by']);
|
|
||||||
$table->dropColumn(['suspended_at', 'suspended_by', 'suspended_reason']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
<?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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue