mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-28 02:06:37 -04:00
feat(ui): add sqlite database page
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Project\Database\Sqlite;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\StandaloneSqlite;
|
||||
use App\Support\ValidationPatterns;
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Livewire\Component;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
|
||||
public ?Server $server = null;
|
||||
|
||||
public StandaloneSqlite $database;
|
||||
|
||||
public string $name;
|
||||
|
||||
public ?string $description = null;
|
||||
|
||||
public string $sqliteDatabases;
|
||||
|
||||
public string $image;
|
||||
|
||||
public ?string $customDockerRunOptions = null;
|
||||
|
||||
public bool $isLogDrainEnabled = false;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
try {
|
||||
$this->authorize('view', $this->database);
|
||||
$this->syncData();
|
||||
$this->server = data_get($this->database, 'destination.server');
|
||||
if (! $this->server) {
|
||||
$this->dispatch('error', 'Database destination server is not configured.');
|
||||
|
||||
return;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ValidationPatterns::nameRules(),
|
||||
'description' => ValidationPatterns::descriptionRules(),
|
||||
'sqliteDatabases' => ['required', 'string', 'max:255', 'regex:'.StandaloneSqlite::DATABASES_PATTERN],
|
||||
'image' => 'required|string',
|
||||
'customDockerRunOptions' => 'nullable|string',
|
||||
'isLogDrainEnabled' => 'nullable|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
protected function messages(): array
|
||||
{
|
||||
return array_merge(
|
||||
ValidationPatterns::combinedMessages(),
|
||||
[
|
||||
'sqliteDatabases.required' => 'The Database Files field is required.',
|
||||
'sqliteDatabases.regex' => 'The Database Files must be comma-separated file names containing only letters, numbers, dots, dashes and underscores.',
|
||||
'image.required' => 'The Docker Image field is required.',
|
||||
'image.string' => 'The Docker Image must be a string.',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function syncData(bool $toModel = false): void
|
||||
{
|
||||
if ($toModel) {
|
||||
$this->validate();
|
||||
$this->database->name = $this->name;
|
||||
$this->database->description = $this->description;
|
||||
$this->database->sqlite_databases = $this->sqliteDatabases;
|
||||
$this->database->image = $this->image;
|
||||
$this->database->custom_docker_run_options = $this->customDockerRunOptions;
|
||||
$this->database->is_log_drain_enabled = $this->isLogDrainEnabled;
|
||||
$this->database->save();
|
||||
} else {
|
||||
$this->name = $this->database->name;
|
||||
$this->description = $this->database->description;
|
||||
$this->sqliteDatabases = $this->database->sqlite_databases;
|
||||
$this->image = $this->database->image;
|
||||
$this->customDockerRunOptions = $this->database->custom_docker_run_options;
|
||||
$this->isLogDrainEnabled = $this->database->is_log_drain_enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public function instantSaveAdvanced()
|
||||
{
|
||||
try {
|
||||
$this->authorize('update', $this->database);
|
||||
|
||||
if (! $this->server->isLogDrainEnabled()) {
|
||||
$this->isLogDrainEnabled = false;
|
||||
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
|
||||
|
||||
return;
|
||||
}
|
||||
$this->syncData(true);
|
||||
|
||||
$this->dispatch('success', 'Database updated.');
|
||||
$this->dispatch('success', 'You need to restart the service for the changes to take effect.');
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$this->authorize('update', $this->database);
|
||||
|
||||
$this->sqliteDatabases = str($this->sqliteDatabases)->replace(' ', '')->trim(',')->toString();
|
||||
$this->syncData(true);
|
||||
$this->dispatch('success', 'Database updated.');
|
||||
$this->dispatch('databaseUpdated');
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
} finally {
|
||||
if (is_null($this->database->config_hash)) {
|
||||
$this->database->isConfigurationChanged(true);
|
||||
} else {
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function refresh(): void
|
||||
{
|
||||
$this->database->refresh();
|
||||
$this->syncData();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@
|
||||
<livewire:project.database.dragonfly.general :database="$database" />
|
||||
@elseif ($database->type() === 'standalone-clickhouse')
|
||||
<livewire:project.database.clickhouse.general :database="$database" />
|
||||
@elseif ($database->type() === 'standalone-sqlite')
|
||||
<livewire:project.database.sqlite.general :database="$database" />
|
||||
@endif
|
||||
@elseif ($currentRoute === 'project.database.environment-variables')
|
||||
<livewire:project.shared.environment-variable.all :resource="$database" />
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<div class="application-settings-form">
|
||||
<form wire:submit="submit" class="flex flex-col gap-6">
|
||||
<x-unsaved-bar action="submit" />
|
||||
|
||||
<x-application.settings-section title="Database details"
|
||||
description="Manage the identity and container image for this SQLite database.">
|
||||
<x-slot:actions>
|
||||
<x-status-badge status="Experimental" type="warning" />
|
||||
<x-modal-input title="Resource details" buttonTitle="Details">
|
||||
<livewire:project.shared.resource-details :resource="$database" />
|
||||
</x-modal-input>
|
||||
</x-slot:actions>
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<x-forms.input label="Name" id="name" canGate="update" :canResource="$database" />
|
||||
<x-forms.input label="Description" id="description" canGate="update" :canResource="$database" />
|
||||
<div class="lg:col-span-2">
|
||||
<x-forms.input label="Image" id="image" required canGate="update" :canResource="$database"
|
||||
helper="Use a published peakimages/sqlite image from Docker Hub." />
|
||||
</div>
|
||||
</div>
|
||||
</x-application.settings-section>
|
||||
|
||||
<x-application.settings-section title="Database files"
|
||||
description="Applications use these databases by mounting the data volume.">
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<x-forms.input label="File names" id="sqliteDatabases" placeholder="database.sqlite" required
|
||||
canGate="update" :canResource="$database"
|
||||
helper="Comma-separated file names. Missing files are created in the data volume on the next start. Removing a name does not delete its file. Backups restore into the first file." />
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<x-callout type="info" title="Connecting applications">
|
||||
Mount the data volume from Persistent Storage in the application and open
|
||||
<span class="font-mono"><mount path>/<file name></span>.
|
||||
The application must run as user 65532 or as root to access the files.
|
||||
</x-callout>
|
||||
</div>
|
||||
</x-application.settings-section>
|
||||
|
||||
<x-application.settings-section title="Runtime" description="Configure Docker runtime options.">
|
||||
<x-forms.input
|
||||
helper="Add supported docker run options used when the container starts. Unsupported options can interfere with Coolify automation."
|
||||
placeholder="--cap-add SYS_ADMIN --device=/dev/fuse"
|
||||
id="customDockerRunOptions" label="Custom Docker options" canGate="update"
|
||||
:canResource="$database" />
|
||||
</x-application.settings-section>
|
||||
|
||||
<x-application.settings-section title="Log delivery"
|
||||
description="Forward container logs to the drain configured on the server.">
|
||||
<x-forms.listbox canGate="update" :canResource="$database" id="isLogDrainEnabled" label="Log drain" live onChange="instantSaveAdvanced"
|
||||
:disabled="! auth()->user()->can('update', $database)" :options="[
|
||||
['value' => false, 'label' => 'Do not forward logs'],
|
||||
['value' => true, 'label' => 'Forward logs to the server drain'],
|
||||
]" />
|
||||
</x-application.settings-section>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user