Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

wip

Andras Bacsai7eeaf37873b7
diff --git a/app/Http/Livewire/TemporaryCheckStatus.php b/app/Http/Livewire/TemporaryCheckStatus.php
index 18250e7c16..eeba96325f 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 4cf0556a5f..875a6c7900 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -4,9 +4,9 @@ namespace App\Models;
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 5aa1f27471..f9bb633b95 100644
--- a/app/Models/Database.php
+++ b/app/Models/Database.php
@@ -4,8 +4,12 @@ namespace App\Models;
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 a8a98cca6e..1e32dd6664 100644
--- a/app/Models/Environment.php
+++ b/app/Models/Environment.php
@@ -4,17 +4,13 @@ namespace App\Models;
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 efb1bfcb4f..708621f427 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 @@ return new class extends Migration
$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 36dd52ed1c..0000000000
--- a/database/migrations/2023_03_27_075445_create_environmentables_table.php
+++ /dev/null
@@ -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
-{
- /**
- * Run the migrations.
- */
- public function up(): void
- {
- Schema::create('environmentables', function (Blueprint $table) {
- $table->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 de47e0c0ac..c5a2570e5c 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 @@ return new class extends Migration
$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 cf81de07f5..9173e4b117 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 @@ return new class extends Migration
$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 26a10b9dcd..8a32739877 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 @@ class ApplicationSeeder extends Seeder
{
$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 adf09e0489..950eba2fd3 100644
--- a/database/seeders/DBSeeder.php
+++ b/database/seeders/DBSeeder.php
@@ -4,6 +4,7 @@ namespace Database\Seeders;
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 5950aa5fd3..50f96bb4eb 100644
--- a/resources/views/home.blade.php
+++ b/resources/views/home.blade.php
@@ -11,12 +11,16 @@
<h2>Environments</h2>
@forelse ($project->environments as $environment)
<p>Environment Name: {{ $environment->name }}</p>
+ <h2>Applications</h2>
@forelse ($environment->applications as $application)
- <p>Application: {{ $application }}</p>
+ <p>Application: {{ $application->name }}</p>
+ <p>Destination: {{ $application->destination }}</p>
+ <p>Destination Class: {{ $application->destination->getMorphClass() }}</p>
<livewire:temporary-check-status :application_id="$application->id" />
@empty
<li>No application found</li>
@endforelse
+ <h2>Databases</h2>
@forelse ($environment->databases as $database)
<p>Database: {{ $database }}</p>
@empty