feat: workout sesssions
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\WorkoutSource;
|
||||
use App\Models\User;
|
||||
use App\Models\WorkoutSessions;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @extends Factory<WorkoutSessions>
|
||||
*/
|
||||
class WorkoutSessionsFactory extends Factory
|
||||
{
|
||||
protected $model = WorkoutSessions::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'external_id' => null,
|
||||
'source' => WorkoutSource::MANUAL,
|
||||
'type' => $this->faker->randomElement(['running', 'cycling', 'strength']),
|
||||
'title' => $this->faker->words(3, true),
|
||||
'duration_seconds' => $this->faker->numberBetween(600, 7200),
|
||||
'calories_burned' => $this->faker->numberBetween(50, 1200),
|
||||
'distance_meters' => $this->faker->numberBetween(0, 50000),
|
||||
'started_at' => Carbon::now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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::create('workout_sessions', function (Blueprint $table) {
|
||||
$table->ulid('id')->primary();
|
||||
$table->foreignUlid('user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->string('external_id')->nullable();
|
||||
$table->string('source')->default('manual');
|
||||
$table->string('type');
|
||||
$table->string('title');
|
||||
$table->integer('duration_seconds');
|
||||
$table->integer('calories_burned');
|
||||
$table->bigInteger('distance_meters');
|
||||
$table->timestampTz('started_at')->nullable();
|
||||
|
||||
$table->unique(['source', 'external_id']);
|
||||
|
||||
$table->timestampsTz();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('workout_sessions');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user