Add projects, environments, applications, databases

This commit is contained in:
Andras Bacsai 2023-03-27 10:44:31 +02:00
parent ca0a3974e4
commit 1c87146a50
22 changed files with 402 additions and 9 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace App\Http\Controllers;
class HomeController extends Controller
{
public function show()
{
$projects = session('currentTeam')->projects;
return view('home', ['projects' => $projects]);
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
class Application extends BaseModel
{
public function environments()
{
return $this->morphToMany(Environment::class, 'environmentable');
}
}

11
app/Models/Database.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
class Database extends BaseModel
{
public function environments()
{
return $this->morphToMany(Environment::class, 'environmentable');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Models;
class Environment extends BaseModel
{
public function environmentables()
{
return $this->hasMany(EnvironmentAble::class);
}
public function applications()
{
return $this->morphedByMany(Application::class, 'environmentable');
}
public function databases()
{
return $this->morphedByMany(Database::class, 'environmentable');
}
}

13
app/Models/Project.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace App\Models;
class Project extends BaseModel
{
public function environments() {
return $this->hasMany(Environment::class);
}
public function settings() {
return $this->hasOne(ProjectSetting::class);
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace App\Models;
class ProjectSetting extends BaseModel
{
}

View File

@ -10,4 +10,7 @@ class Team extends BaseModel
protected $fillable = [
'name',
];
public function projects() {
return $this->hasMany(Project::class);
}
}

View File

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

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('project_settings', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->string('wildcard_domain')->nullable();
$table->foreignId('project_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('project_settings');
}
};

View File

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

View File

@ -0,0 +1,30 @@
<?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');
}
};

View File

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

View File

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

View File

@ -0,0 +1,25 @@
<?php
namespace Database\Seeders;
use App\Models\Application;
use App\Models\Environment;
use App\Models\Project;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class ApplicationSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$environment_1 = Environment::find(1);
$application_1 = Application::create([
'id' => 1,
'name' => 'My first application',
]);
$environment_1->applications()->attach($application_1);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\Database;
use App\Models\Environment;
use Illuminate\Database\Seeder;
class DBSeeder extends Seeder
{
public function run(): void
{
$environment_1 = Environment::find(1);
$database_1 = Database::create([
'id' => 1,
'name'=> "My first database"
]);
$environment_1->databases()->attach($database_1);
}
}

View File

@ -14,6 +14,11 @@ public function run(): void
TeamSeeder::class,
ServerSeeder::class,
PrivateKeySeeder::class,
ProjectSeeder::class,
ProjectSettingSeeder::class,
EnvironmentSeeder::class,
ApplicationSeeder::class,
DBSeeder::class,
]);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Seeders;
use App\Models\Environment;
use App\Models\Project;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class EnvironmentSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$project_1 = Project::find(1);
Environment::create([
'id' => 1,
'name' => 'production',
'project_id' => $project_1->id,
]);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\Project;
use App\Models\Team;
use Illuminate\Database\Seeder;
class ProjectSeeder extends Seeder
{
public function run(): void
{
$root_team = Team::find(1);
Project::create([
'id' => 1,
'name' => "My first project",
'description' => "This is a test project in development",
'team_id' => $root_team->id,
]);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Database\Seeders;
use App\Models\Project;
use App\Models\ProjectSetting;
use Illuminate\Database\Seeder;
class ProjectSettingSeeder extends Seeder
{
public function run(): void
{
$first_project = Project::find(1);
ProjectSetting::create([
'id' => 1,
'wildcard_domain' => 'testing-host.localhost',
'project_id' => $first_project->id,
]);
}
}

View File

@ -1,10 +1,10 @@
<nav>
<a href="/">Home</a>
@guest
<a href="/login">Login</a>
<a href="/register">Register</a>
@endguest
@auth
<a href="/">Home</a>
<a href="/demo">Demo</a>
<a href="/profile">Profile</a>
<form action="/logout" method="POST">

View File

@ -2,9 +2,23 @@
<h1>
Coolify v4 🎉
</h1>
@guest
<p>
To see the demo, please <a href='/login'>login<a> or <a href='/register'>register<a>.
</p>
@endguest
<h2>Projects</h2>
<ul>
@forelse ($projects as $project)
<li>
<p>Project Name: {{ $project->name }}</p>
<p>Project Settings:{{ $project->settings }}</p>
<h2>Environments</h2>
@forelse ($project->environments as $environment)
<p>Environment Name: {{ $environment->name }}</p>
<p>Applications: {{ $environment->applications }}</p>
<p>Databases: {{ $environment->databases }}</p>
@empty
<p>No environments found</p>
@endforelse
</li>
@empty
<li>No projects found</li>
@endforelse
</ul>
</x-layout>

View File

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;
/*
@ -13,11 +14,10 @@
|
*/
Route::get('/', function () {
return view('home');
});
Route::middleware(['auth'])->group(function () {
Route::get('/', [HomeController::class, 'show']);
Route::get('/profile', function () {
return view('profile');
});