diff --git a/app/Http/Livewire/TemporaryCheckStatus.php b/app/Http/Livewire/TemporaryCheckStatus.php index 18250e7c1..eeba96325 100644 --- a/app/Http/Livewire/TemporaryCheckStatus.php +++ b/app/Http/Livewire/TemporaryCheckStatus.php @@ -10,7 +10,7 @@ class TemporaryCheckStatus extends Component public $application_id; public function checkStatus() { - dd(Application::find(1)->environments); + dd(Application::find(1)->environment); } public function render() { diff --git a/app/Models/Application.php b/app/Models/Application.php index 4cf0556a5..875a6c790 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -4,9 +4,9 @@ class Application extends BaseModel { - public function environments() + public function environment() { - return $this->morphToMany(Environment::class, 'environmentable'); + return $this->belongsTo(Environment::class); } public function destination() { diff --git a/app/Models/Database.php b/app/Models/Database.php index 5aa1f2747..f9bb633b9 100644 --- a/app/Models/Database.php +++ b/app/Models/Database.php @@ -4,8 +4,12 @@ class Database extends BaseModel { - public function environments() + public function environment() { - return $this->morphToMany(Environment::class, 'environmentable'); + return $this->morphTo(); + } + public function destination() + { + return $this->morphTo(); } } diff --git a/app/Models/Environment.php b/app/Models/Environment.php index a8a98cca6..1e32dd666 100644 --- a/app/Models/Environment.php +++ b/app/Models/Environment.php @@ -4,17 +4,13 @@ class Environment extends BaseModel { - public function environmentables() - { - return $this->hasMany(EnvironmentAble::class); - } public function applications() { - return $this->morphedByMany(Application::class, 'environmentable'); + return $this->hasMany(Application::class); } public function databases() { - return $this->morphedByMany(Database::class, 'environmentable'); + return $this->hasMany(Database::class); } } diff --git a/database/migrations/2023_03_27_075444_create_environments_table.php b/database/migrations/2023_03_27_075444_create_environments_table.php index efb1bfcb4..708621f42 100644 --- a/database/migrations/2023_03_27_075444_create_environments_table.php +++ b/database/migrations/2023_03_27_075444_create_environments_table.php @@ -15,9 +15,6 @@ public function up(): void $table->id(); $table->string('uuid')->unique(); $table->string('name')->unique(); - - $table->nullableMorphs('environments_morph'); - $table->foreignId('project_id'); $table->timestamps(); }); diff --git a/database/migrations/2023_03_27_075445_create_environmentables_table.php b/database/migrations/2023_03_27_075445_create_environmentables_table.php deleted file mode 100644 index 36dd52ed1..000000000 --- a/database/migrations/2023_03_27_075445_create_environmentables_table.php +++ /dev/null @@ -1,30 +0,0 @@ -id(); - $table->unsignedBigInteger('environment_id'); - $table->unsignedBigInteger('environmentable_id'); - $table->string('environmentable_type'); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('environmentables'); - } -}; diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.php index de47e0c0a..c5a2570e5 100644 --- a/database/migrations/2023_03_27_081716_create_applications_table.php +++ b/database/migrations/2023_03_27_081716_create_applications_table.php @@ -15,7 +15,10 @@ public function up(): void $table->id(); $table->string('uuid')->unique(); $table->string('name'); - $table->nullableMorphs('destination'); + + $table->morphs('destination'); + $table->foreignId('environment_id'); + $table->timestamps(); }); } diff --git a/database/migrations/2023_03_27_083620_create_databases_table.php b/database/migrations/2023_03_27_083620_create_databases_table.php index cf81de07f..9173e4b11 100644 --- a/database/migrations/2023_03_27_083620_create_databases_table.php +++ b/database/migrations/2023_03_27_083620_create_databases_table.php @@ -15,6 +15,10 @@ public function up(): void $table->id(); $table->string('uuid')->unique(); $table->string('name'); + + $table->morphs('destination'); + $table->foreignId('environment_id'); + $table->timestamps(); }); } diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.php index 26a10b9dc..8a3273987 100644 --- a/database/seeders/ApplicationSeeder.php +++ b/database/seeders/ApplicationSeeder.php @@ -3,13 +3,10 @@ namespace Database\Seeders; use App\Models\Application; -use App\Models\Destination; use App\Models\Environment; -use App\Models\Project; use App\Models\StandaloneDocker; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; +use App\Models\SwarmDocker; use Illuminate\Database\Seeder; -use Illuminate\Support\Facades\DB; class ApplicationSeeder extends Seeder { @@ -20,13 +17,21 @@ public function run(): void { $environment_1 = Environment::find(1); $standalone_docker_1 = StandaloneDocker::find(1); + $swarm_docker_1 = SwarmDocker::find(1); - $application_1 = Application::create([ + Application::create([ 'id' => 1, 'name' => 'My first application', + 'environment_id' => $environment_1->id, 'destination_id' => $standalone_docker_1->id, 'destination_type' => StandaloneDocker::class, ]); - $environment_1->applications()->attach($application_1); + Application::create([ + 'id' => 2, + 'name' => 'My Second application', + 'environment_id' => $environment_1->id, + 'destination_id' => $swarm_docker_1->id, + 'destination_type' => SwarmDocker::class, + ]); } } diff --git a/database/seeders/DBSeeder.php b/database/seeders/DBSeeder.php index adf09e048..950eba2fd 100644 --- a/database/seeders/DBSeeder.php +++ b/database/seeders/DBSeeder.php @@ -4,6 +4,7 @@ use App\Models\Database; use App\Models\Environment; +use App\Models\StandaloneDocker; use Illuminate\Database\Seeder; class DBSeeder extends Seeder @@ -11,11 +12,15 @@ class DBSeeder extends Seeder public function run(): void { $environment_1 = Environment::find(1); - $database_1 = Database::create([ + $standalone_docker_1 = StandaloneDocker::find(1); + Database::create([ 'id' => 1, - 'name'=> "My first database" + 'name'=> "My first database", + 'environment_id' => $environment_1->id, + 'destination_id' => $standalone_docker_1->id, + 'destination_type' => StandaloneDocker::class, ]); - $environment_1->databases()->attach($database_1); + } } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 5950aa5fd..50f96bb4e 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -11,12 +11,16 @@
Environment Name: {{ $environment->name }}
+Application: {{ $application }}
+Application: {{ $application->name }}
+Destination: {{ $application->destination }}
+Destination Class: {{ $application->destination->getMorphClass() }}
Database: {{ $database }}
@empty