mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-16 12:33:03 +00:00
feat: init postgresql database
This commit is contained in:
25
app/Actions/Database/StartPostgresql.php
Normal file
25
app/Actions/Database/StartPostgresql.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Database;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\Team;
|
||||
use App\Models\Postgresql;
|
||||
|
||||
class StartPostgresql
|
||||
{
|
||||
public function __invoke(Server $server, Postgresql $database)
|
||||
{
|
||||
$activity = remote_process([
|
||||
"echo 'Creating required Docker networks...'",
|
||||
"echo 'Creating required Docker networks...'",
|
||||
"echo 'Creating required Docker networks...'",
|
||||
"sleep 4",
|
||||
"echo 'Creating required Docker networks...'",
|
||||
"echo 'Creating required Docker networks...'",
|
||||
|
||||
], $server);
|
||||
return $activity;
|
||||
}
|
||||
}
|
||||
@@ -84,4 +84,4 @@ class ApplicationController extends Controller
|
||||
'deployment_uuid' => $deploymentUuid,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,9 @@ class Controller extends BaseController
|
||||
$s3s = S3Storage::ownedByCurrentTeam()->get();
|
||||
$resources = 0;
|
||||
foreach ($projects as $project) {
|
||||
ray($project->postgresqls);
|
||||
$resources += $project->applications->count();
|
||||
$resources += $project->postgresqls->count();
|
||||
}
|
||||
|
||||
return view('dashboard', [
|
||||
|
||||
30
app/Http/Controllers/DatabaseController.php
Normal file
30
app/Http/Controllers/DatabaseController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ApplicationDeploymentQueue;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class DatabaseController extends Controller
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
public function configuration()
|
||||
{
|
||||
$project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
||||
if (!$project) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
|
||||
if (!$environment) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
$database = $environment->databases->where('uuid', request()->route('database_uuid'))->first();
|
||||
if (!$database) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
return view('project.database.configuration', ['database' => $database]);
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,4 @@ class ActivityMonitor extends Component
|
||||
]);
|
||||
$this->activity->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
namespace App\Http\Livewire\Dev;
|
||||
|
||||
use App\Models\S3Storage;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -14,7 +14,6 @@ class S3Test extends Component
|
||||
public $file;
|
||||
public function mount() {
|
||||
$this->s3 = S3Storage::first();
|
||||
ray($this->s3);
|
||||
}
|
||||
public function save() {
|
||||
try {
|
||||
@@ -33,6 +33,7 @@ class General extends Component
|
||||
|
||||
protected $rules = [
|
||||
'application.name' => 'required',
|
||||
'application.description' => 'nullable',
|
||||
'application.fqdn' => 'nullable',
|
||||
'application.git_repository' => 'required',
|
||||
'application.git_branch' => 'required',
|
||||
@@ -49,6 +50,7 @@ class General extends Component
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'application.name' => 'name',
|
||||
'application.description' => 'description',
|
||||
'application.fqdn' => 'FQDN',
|
||||
'application.git_repository' => 'Git repository',
|
||||
'application.git_branch' => 'Git branch',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Application;
|
||||
namespace App\Http\Livewire\Project\Application;
|
||||
|
||||
use App\Jobs\ApplicationContainerStatusJob;
|
||||
use App\Models\Application;
|
||||
23
app/Http/Livewire/Project/Database/Heading.php
Normal file
23
app/Http/Livewire/Project/Database/Heading.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Database;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Actions\Database\StartPostgresql;
|
||||
|
||||
class Heading extends Component
|
||||
{
|
||||
public $database;
|
||||
public array $parameters;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->parameters = getRouteParameters();
|
||||
}
|
||||
public function start() {
|
||||
if ($this->database->type() === 'postgresql') {
|
||||
$activity = resolve(StartPostgresql::class)($this->database->destination->server, $this->database);
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
app/Http/Livewire/Project/Database/Postgresql/General.php
Normal file
39
app/Http/Livewire/Project/Database/Postgresql/General.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Database\Postgresql;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
public $database;
|
||||
protected $rules = [
|
||||
'database.name' => 'required',
|
||||
'database.description' => 'nullable',
|
||||
'database.postgres_user' => 'required',
|
||||
'database.postgres_password' => 'required',
|
||||
'database.postgres_db' => 'required',
|
||||
'database.postgres_initdb_args' => 'nullable',
|
||||
'database.postgres_host_auth_method' => 'nullable',
|
||||
'database.init_scripts' => 'nullable',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'database.name' => 'Name',
|
||||
'database.description' => 'Description',
|
||||
'database.postgres_user' => 'Postgres User',
|
||||
'database.postgres_password' => 'Postgres Password',
|
||||
'database.postgres_db' => 'Postgres DB',
|
||||
'database.postgres_initdb_args' => 'Postgres Initdb Args',
|
||||
'database.postgres_host_auth_method' => 'Postgres Host Auth Method',
|
||||
'database.init_scripts' => 'Init Scripts',
|
||||
];
|
||||
public function submit() {
|
||||
try {
|
||||
$this->validate();
|
||||
$this->database->save();
|
||||
$this->emit('success', 'Database updated successfully.');
|
||||
} catch (\Exception $e) {
|
||||
return general_error_handler(err: $e, that: $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,12 @@ class Environment extends Model
|
||||
set: fn (string $value) => strtolower($value),
|
||||
);
|
||||
}
|
||||
public function can_delete_environment() {
|
||||
return $this->applications()->count() == 0 && $this->postgresqls()->count() == 0;
|
||||
}
|
||||
public function databases() {
|
||||
return $this->postgresqls();
|
||||
}
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
@@ -25,12 +31,12 @@ class Environment extends Model
|
||||
{
|
||||
return $this->hasMany(Application::class);
|
||||
}
|
||||
public function databases()
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->hasMany(Database::class);
|
||||
return $this->hasMany(Postgresql::class);
|
||||
}
|
||||
public function services()
|
||||
{
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
app/Models/Postgresql.php
Normal file
25
app/Models/Postgresql.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Postgresql extends BaseModel
|
||||
{
|
||||
use HasFactory;
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
'postgres_password' => 'encrypted',
|
||||
];
|
||||
public function type() {
|
||||
return 'postgresql';
|
||||
}
|
||||
public function environment()
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
public function destination()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,8 @@ class Project extends BaseModel
|
||||
{
|
||||
return $this->hasManyThrough(Application::class, Environment::class);
|
||||
}
|
||||
}
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->hasManyThrough(Postgresql::class, Environment::class);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,10 @@ class S3Storage extends BaseModel
|
||||
{
|
||||
use HasFactory;
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
'key' => 'encrypted',
|
||||
'secret' => 'encrypted',
|
||||
];
|
||||
|
||||
static public function ownedByCurrentTeam(array $select = ['*'])
|
||||
{
|
||||
|
||||
@@ -13,9 +13,9 @@ class StandaloneDocker extends BaseModel
|
||||
{
|
||||
return $this->morphMany(Application::class, 'destination');
|
||||
}
|
||||
public function databases()
|
||||
public function postgresqls()
|
||||
{
|
||||
return $this->morphMany(Database::class, 'destination');
|
||||
return $this->morphMany(Postgresql::class, 'destination');
|
||||
}
|
||||
public function server()
|
||||
{
|
||||
@@ -25,4 +25,4 @@ class StandaloneDocker extends BaseModel
|
||||
{
|
||||
return $this->applications->count() > 0 || $this->databases->count() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class Modal extends Component
|
||||
*/
|
||||
public function __construct(
|
||||
public string $modalId,
|
||||
public string $modalTitle,
|
||||
public string|null $modalTitle = null,
|
||||
public string|null $modalBody = null,
|
||||
public string|null $modalSubmit = null,
|
||||
public bool $yesOrNo = false,
|
||||
@@ -30,4 +30,4 @@ class Modal extends Component
|
||||
{
|
||||
return view('components.modal');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user