Refactor db migrations

This commit is contained in:
Andras Bacsai 2023-08-09 16:47:24 +02:00
parent a3353aac0c
commit 04622a9e3b
16 changed files with 57 additions and 49 deletions

View File

@ -25,4 +25,21 @@ public function configuration()
}
return view('project.database.configuration', ['database' => $database]);
}
public function backups()
{
$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.backups', ['database' => $database]);
}
}

View File

@ -2,9 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ScheduledDatabaseBackup extends Model
class ScheduledDatabaseBackup extends BaseModel
{
protected $guarded = [];

View File

@ -83,4 +83,9 @@ public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
public function scheduledBackups()
{
return $this->morphMany(ScheduledDatabaseBackup::class, 'database');
}
}

View File

@ -17,7 +17,7 @@ public function up(): void
$table->string('description')->nullable();
$table->string('postgres_user')->default('postgres');
$table->string('postgres_password');
$table->text('postgres_password');
$table->string('postgres_db')->default('postgres');
$table->string('postgres_initdb_args')->nullable();
$table->string('postgres_host_auth_method')->nullable();
@ -28,6 +28,7 @@ public function up(): void
$table->string('image')->default('postgres:15-alpine');
$table->boolean('is_public')->default(false);
$table->integer('public_port')->nullable();
$table->text('ports_mappings')->nullable();
$table->string('limits_memory')->default("0");
$table->string('limits_memory_swap')->default("0");

View File

@ -1,21 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('standalone_postgresqls', function (Blueprint $table) {
$table->text('ports_mappings')->nullable();
});
}
public function down(): void
{
Schema::table('standalone_postgresqls', function (Blueprint $table) {
$table->dropColumn('ports_mappings');
});
}
};

View File

@ -9,6 +9,7 @@ public function up(): void
{
Schema::create('scheduled_database_backups', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->boolean('enabled')->default(true);
$table->boolean('keep_locally')->default(true);
$table->string('save_s3')->default(true);

View File

@ -1,21 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('standalone_postgresqls', function (Blueprint $table) {
$table->text('postgres_password')->change();
});
}
public function down(): void
{
Schema::table('standalone_postgresqls', function (Blueprint $table) {
$table->string('postgres_password')->change();
});
}
};

View File

@ -3,6 +3,10 @@
href="{{ route('project.database.configuration', $parameters) }}">
<button>Configuration</button>
</a>
<a class="{{ request()->routeIs('project.database.backups') ? 'text-white' : '' }}"
href="{{ route('project.database.backups', $parameters) }}">
<button>Backups</button>
</a>
{{-- <x-applications.links :application="$application" /> --}}
<div class="flex-1"></div>
{{-- <x-applications.advanced :application="$application" /> --}}

View File

@ -4,7 +4,7 @@
<p>This resource will be deleted. It is not reversible. <br>Please think again.</p>
</x-slot:modalBody>
</x-modal>
<h3>Danger Zone</h3>
<h2>Danger Zone</h2>
<div class="">Woah. I hope you know what are you doing.</div>
<h4 class="pt-4">Delete Resource</h4>
<div class="pb-4">This will stop your containers, delete all related data, etc. Beware! There is no coming

View File

@ -81,7 +81,7 @@
</div>
</div>
@endif
<h3>Danger Zone</h3>
<h2>Danger Zone</h2>
<div class="">Woah. I hope you know what are you doing.</div>
<h4 class="pt-4">Delete Server</h4>
<div class="pb-4">This will remove this server from Coolify. Beware! There is no coming

View File

@ -4,7 +4,7 @@
<p>This team be deleted. It is not reversible. <br>Please think again.</p>
</x-slot:modalBody>
</x-modal>
<h3>Danger Zone</h3>
<h2>Danger Zone</h2>
<div class="pb-4">Woah. I hope you know what are you doing.</div>
<h4 class="pb-4">Delete Team</h4>
@if (session('currentTeam.id') === 0)

View File

@ -0,0 +1,18 @@
<x-layout>
<h1>Backups</h1>
<livewire:project.database.heading :database="$database"/>
<div class="pt-6">
<h2 class="pb-4">Scheduled Backups</h2>
<div class="flex flex-wrap gap-2">
@forelse($database->scheduledBackups as $backup)
<div class="box flex flex-col">
<div>Frequency: {{$backup->frequency}}</div>
<div>Keep locally: {{$backup->keep_locally}}</div>
<div>Sync to S3: {{$backup->save_s3}}</div>
</div>
@empty
<div>No scheduled backups configured.</div>
@endforelse
</div>
</div>
</x-layout>

View File

@ -52,13 +52,18 @@
Route::get('/project/{project_uuid}', [ProjectController::class, 'show'])->name('project.show');
Route::get('/project/{project_uuid}/{environment_name}/new', [ProjectController::class, 'new'])->name('project.resources.new');
Route::get('/project/{project_uuid}/{environment_name}', [ProjectController::class, 'resources'])->name('project.resources');
// Applications
Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}', [ApplicationController::class, 'configuration'])->name('project.application.configuration');
Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}', [DatabaseController::class, 'configuration'])->name('project.database.configuration');
Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment', [ApplicationController::class, 'deployments'])->name('project.application.deployments');
Route::get(
'/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}',
[ApplicationController::class, 'deployment']
)->name('project.application.deployment');
// Databases
Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}', [DatabaseController::class, 'configuration'])->name('project.database.configuration');
Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/backups', [DatabaseController::class, 'backups'])->name('project.database.backups');
});
Route::middleware(['auth'])->group(function () {