Add Service

This commit is contained in:
Andras Bacsai 2023-03-28 08:28:03 +02:00
parent f7dd65d1e1
commit f4daffaa89
10 changed files with 114 additions and 27 deletions

View File

@ -12,5 +12,9 @@ public function databases()
{
return $this->hasMany(Database::class);
}
public function services()
{
return $this->hasMany(Service::class);
}
}

16
app/Models/Service.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace App\Models;
class Service extends BaseModel
{
public function environment()
{
return $this->belongsTo(Environment::class);
}
public function destination()
{
return $this->morphTo();
}
}

View File

@ -0,0 +1,32 @@
<?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('services', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('name');
$table->morphs('destination');
$table->foreignId('environment_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('services');
}
};

View File

@ -28,7 +28,7 @@ public function run(): void
]);
Application::create([
'id' => 2,
'name' => 'My Second application',
'name' => 'My second application (Swarm)',
'environment_id' => $environment_1->id,
'destination_id' => $swarm_docker_1->id,
'destination_type' => SwarmDocker::class,

View File

@ -20,7 +20,5 @@ public function run(): void
'destination_id' => $standalone_docker_1->id,
'destination_type' => StandaloneDocker::class,
]);
}
}

View File

@ -23,6 +23,7 @@ public function run(): void
KubernetesSeeder::class,
ApplicationSeeder::class,
DBSeeder::class,
ServiceSeeder::class,
]);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Database\Seeders;
use App\Models\Environment;
use App\Models\Service;
use App\Models\StandaloneDocker;
use Illuminate\Database\Seeder;
class ServiceSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$environment_1 = Environment::find(1);
$standalone_docker_1 = StandaloneDocker::find(1);
Service::create([
'id' => 1,
'name'=> "My first database",
'environment_id' => $environment_1->id,
'destination_id' => $standalone_docker_1->id,
'destination_type' => StandaloneDocker::class,
]);
}
}

View File

@ -9,7 +9,7 @@
<p>Project Settings:{{ $project->settings }}</p>
<h2>Environments</h2>
@forelse ($project->environments as $environment)
<p>Environment Name: {{ $environment->name }}</p>
<h1>Environment: {{ $environment->name }}</h1>
<h2>Applications</h2>
@forelse ($environment->applications as $application)
<h3>{{ $application->name }}</h3>
@ -22,9 +22,18 @@
@forelse ($environment->databases as $database)
<h3>{{ $database->name }}</h3>
<p>Database: {{ $database }}</p>
<p>Destination Class: {{ $database->destination->getMorphClass() }}</p>
@empty
<li>No database found</li>
@endforelse
<h2>Services</h2>
@forelse ($environment->services as $service)
<h3>{{ $service->name }}</h3>
<p>Service: {{ $service }}</p>
<p>Destination Class: {{ $service->destination->getMorphClass() }}</p>
@empty
<li>No service found</li>
@endforelse
@empty
<p>No environments found</p>
@endforelse