Fix styling

This commit is contained in:
Thijmen
2024-06-10 20:43:34 +00:00
committed by github-actions[bot]
parent 41fb6a1fc9
commit d86274cc37
429 changed files with 5307 additions and 2831 deletions

View File

@@ -8,26 +8,30 @@ use Livewire\Component;
class Execution extends Component
{
public $database;
public ?ScheduledDatabaseBackup $backup;
public $executions;
public $s3s;
public function mount()
{
$backup_uuid = request()->route('backup_uuid');
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
if (! $database) {
return redirect()->route('dashboard');
}
$backup = $database->scheduledBackups->where('uuid', $backup_uuid)->first();
if (!$backup) {
if (! $backup) {
return redirect()->route('dashboard');
}
$executions = collect($backup->executions)->sortByDesc('created_at');
@@ -36,6 +40,7 @@ class Execution extends Component
$this->executions = $executions;
$this->s3s = currentTeam()->s3s;
}
public function render()
{
return view('livewire.project.database.backup.execution');

View File

@@ -7,25 +7,26 @@ use Livewire\Component;
class Index extends Component
{
public $database;
public function mount()
{
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
if (! $database) {
return redirect()->route('dashboard');
}
// No backups
if (
$database->getMorphClass() === 'App\Models\StandaloneRedis' ||
$database->getMorphClass() === 'App\Models\StandaloneKeydb' ||
$database->getMorphClass() === 'App\Models\StandaloneDragonfly'||
$database->getMorphClass() === 'App\Models\StandaloneDragonfly' ||
$database->getMorphClass() === 'App\Models\StandaloneClickhouse'
) {
return redirect()->route('project.database.configuration', [
@@ -36,6 +37,7 @@ class Index extends Component
}
$this->database = $database;
}
public function render()
{
return view('livewire.project.database.backup.index');

View File

@@ -9,8 +9,11 @@ use Spatie\Url\Url;
class BackupEdit extends Component
{
public ?ScheduledDatabaseBackup $backup;
public $s3s;
public ?string $status = null;
public array $parameters;
protected $rules = [
@@ -21,6 +24,7 @@ class BackupEdit extends Component
'backup.s3_storage_id' => 'nullable|integer',
'backup.databases_to_backup' => 'nullable',
];
protected $validationAttributes = [
'backup.enabled' => 'Enabled',
'backup.frequency' => 'Frequency',
@@ -29,6 +33,7 @@ class BackupEdit extends Component
'backup.s3_storage_id' => 'S3 Storage',
'backup.databases_to_backup' => 'Databases to Backup',
];
protected $messages = [
'backup.s3_storage_id' => 'Select a S3 Storage',
];
@@ -50,7 +55,8 @@ class BackupEdit extends Component
$url = Url::fromString($previousUrl);
$url = $url->withoutQueryParameter('selectedBackupId');
$url = $url->withFragment('backups');
$url = $url->getPath() . "#{$url->getFragment()}";
$url = $url->getPath()."#{$url->getFragment()}";
return redirect($url);
} else {
return redirect()->route('project.database.backup.index', $this->parameters);
@@ -74,11 +80,11 @@ class BackupEdit extends Component
private function custom_validate()
{
if (!is_numeric($this->backup->s3_storage_id)) {
if (! is_numeric($this->backup->s3_storage_id)) {
$this->backup->s3_storage_id = null;
}
$isValid = validate_cron_expression($this->backup->frequency);
if (!$isValid) {
if (! $isValid) {
throw new \Exception('Invalid Cron / Human expression');
}
$this->validate();

View File

@@ -8,14 +8,18 @@ use Livewire\Component;
class BackupExecutions extends Component
{
public ?ScheduledDatabaseBackup $backup = null;
public $executions = [];
public $setDeletableBackup;
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:team.{$userId},BackupCreated" => 'refreshBackupExecutions',
"deleteBackup"
'deleteBackup',
];
}
@@ -27,11 +31,13 @@ class BackupExecutions extends Component
$this->dispatch('success', 'Failed backups cleaned up.');
}
}
public function deleteBackup($exeuctionId)
{
$execution = $this->backup->executions()->where('id', $exeuctionId)->first();
if (is_null($execution)) {
$this->dispatch('error', 'Backup execution not found.');
return;
}
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === 'App\Models\ServiceDatabase') {
@@ -43,10 +49,12 @@ class BackupExecutions extends Component
$this->dispatch('success', 'Backup deleted.');
$this->refreshBackupExecutions();
}
public function download_file($exeuctionId)
{
return redirect()->route('download.backup', $exeuctionId);
}
public function refreshBackupExecutions(): void
{
if ($this->backup) {

View File

@@ -8,6 +8,7 @@ use Livewire\Component;
class BackupNow extends Component
{
public $backup;
public function backup_now()
{
dispatch(new DatabaseBackupJob(

View File

@@ -12,8 +12,11 @@ use Livewire\Component;
class General extends Component
{
public Server $server;
public StandaloneClickhouse $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $listeners = ['refresh'];
@@ -29,6 +32,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -39,19 +43,23 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -61,18 +69,21 @@ class General extends Component
return handleError($e, $this);
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -85,7 +96,8 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
@@ -95,7 +107,6 @@ class General extends Component
$this->database->refresh();
}
public function submit()
{
try {

View File

@@ -7,18 +7,19 @@ use Livewire\Component;
class Configuration extends Component
{
public $database;
public function mount()
{
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
if (! $project) {
return redirect()->route('dashboard');
}
$environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
if (!$environment) {
if (! $environment) {
return redirect()->route('dashboard');
}
$database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
if (!$database) {
if (! $database) {
return redirect()->route('dashboard');
}
$this->database = $database;
@@ -27,6 +28,7 @@ class Configuration extends Component
$this->dispatch('configurationChanged');
}
}
public function render()
{
return view('livewire.project.database.configuration');

View File

@@ -9,20 +9,27 @@ use Livewire\Component;
class CreateScheduledBackup extends Component
{
public $database;
public $frequency;
public bool $enabled = true;
public bool $save_s3 = false;
public $s3_storage_id;
public Collection $s3s;
protected $rules = [
'frequency' => 'required|string',
'save_s3' => 'required|boolean',
];
protected $validationAttributes = [
'frequency' => 'Backup Frequency',
'save_s3' => 'Save to S3',
];
public function mount()
{
$this->s3s = currentTeam()->s3s;
@@ -36,8 +43,9 @@ class CreateScheduledBackup extends Component
try {
$this->validate();
$isValid = validate_cron_expression($this->frequency);
if (!$isValid) {
if (! $isValid) {
$this->dispatch('error', 'Invalid Cron / Human expression.');
return;
}
$payload = [
@@ -51,9 +59,9 @@ class CreateScheduledBackup extends Component
];
if ($this->database->type() === 'standalone-postgresql') {
$payload['databases_to_backup'] = $this->database->postgres_db;
} else if ($this->database->type() === 'standalone-mysql') {
} elseif ($this->database->type() === 'standalone-mysql') {
$payload['databases_to_backup'] = $this->database->mysql_database;
} else if ($this->database->type() === 'standalone-mariadb') {
} elseif ($this->database->type() === 'standalone-mariadb') {
$payload['databases_to_backup'] = $this->database->mariadb_database;
}

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneDragonfly $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -28,6 +31,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -37,19 +41,23 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -59,6 +67,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -75,18 +84,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -99,16 +111,17 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();
}
public function render()
{
return view('livewire.project.database.dragonfly.general');

View File

@@ -18,11 +18,13 @@ use Livewire\Component;
class Heading extends Component
{
public $database;
public array $parameters;
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:user.{$userId},DatabaseStatusChanged" => 'activityFinished',
];
@@ -48,7 +50,9 @@ class Heading extends Component
GetContainersStatus::run($this->database->destination->server);
// dispatch_sync(new ContainerStatusJob($this->database->destination->server));
$this->database->refresh();
if ($showNotification) $this->dispatch('success', 'Database status updated.');
if ($showNotification) {
$this->dispatch('success', 'Database status updated.');
}
}
public function mount()
@@ -69,25 +73,25 @@ class Heading extends Component
if ($this->database->type() === 'standalone-postgresql') {
$activity = StartPostgresql::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-redis') {
} elseif ($this->database->type() === 'standalone-redis') {
$activity = StartRedis::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-mongodb') {
} elseif ($this->database->type() === 'standalone-mongodb') {
$activity = StartMongodb::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-mysql') {
} elseif ($this->database->type() === 'standalone-mysql') {
$activity = StartMysql::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-mariadb') {
} elseif ($this->database->type() === 'standalone-mariadb') {
$activity = StartMariadb::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-keydb') {
} elseif ($this->database->type() === 'standalone-keydb') {
$activity = StartKeydb::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-dragonfly') {
} elseif ($this->database->type() === 'standalone-dragonfly') {
$activity = StartDragonfly::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
} else if ($this->database->type() === 'standalone-clickhouse') {
} elseif ($this->database->type() === 'standalone-clickhouse') {
$activity = StartClickhouse::run($this->database);
$this->dispatch('activityMonitor', $activity->id);
}

View File

@@ -2,40 +2,57 @@
namespace App\Livewire\Project\Database;
use Livewire\Component;
use App\Models\Server;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
class Import extends Component
{
public bool $unsupported = false;
public $resource;
public $parameters;
public $containers;
public bool $scpInProgress = false;
public bool $importRunning = false;
public ?string $filename = null;
public ?string $filesize = null;
public bool $isUploading = false;
public int $progress = 0;
public bool $error = false;
public Server $server;
public string $container;
public array $importCommands = [];
public string $postgresqlRestoreCommand = 'pg_restore -U $POSTGRES_USER -d $POSTGRES_DB';
public string $mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';
public string $mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';
public string $mongodbRestoreCommand = 'mongorestore --authenticationDatabase=admin --username $MONGO_INITDB_ROOT_USERNAME --password $MONGO_INITDB_ROOT_PASSWORD --uri mongodb://localhost:27017 --gzip --archive=';
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
];
}
public function mount()
{
$this->parameters = get_route_parameters();
@@ -45,7 +62,7 @@ class Import extends Component
public function getContainers()
{
$this->containers = collect();
if (!data_get($this->parameters, 'database_uuid')) {
if (! data_get($this->parameters, 'database_uuid')) {
abort(404);
}
$resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(), 'id'));
@@ -74,16 +91,18 @@ class Import extends Component
if ($this->filename == '') {
$this->dispatch('error', 'Please select a file to import.');
return;
}
try {
$uploadedFilename = "upload/{$this->resource->uuid}/restore";
$path = Storage::path($uploadedFilename);
if (!Storage::exists($uploadedFilename)) {
if (! Storage::exists($uploadedFilename)) {
$this->dispatch('error', 'The file does not exist or has been deleted.');
return;
}
$tmpPath = '/tmp/' . basename($uploadedFilename);
$tmpPath = '/tmp/'.basename($uploadedFilename);
instant_scp($path, $tmpPath, $this->server);
Storage::delete($uploadedFilename);
$this->importCommands[] = "docker cp {$tmpPath} {$this->container}:{$tmpPath}";
@@ -110,7 +129,7 @@ class Import extends Component
$this->importCommands[] = "docker exec {$this->container} sh -c 'rm {$tmpPath}'";
$this->importCommands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";
if (!empty($this->importCommands)) {
if (! empty($this->importCommands)) {
$activity = remote_process($this->importCommands, $this->server, ignore_errors: true);
$this->dispatch('activityMonitor', $activity->id);
}

View File

@@ -8,14 +8,18 @@ use Livewire\Component;
class InitScript extends Component
{
public array $script;
public int $index;
public string|null $filename;
public string|null $content;
public ?string $filename;
public ?string $content;
protected $rules = [
'filename' => 'required|string',
'content' => 'required|string',
];
protected $validationAttributes = [
'filename' => 'Filename',
'content' => 'Content',

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneKeydb $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -29,6 +32,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -39,20 +43,24 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -62,11 +70,12 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
$this->validate();
if ($this->database->keydb_conf === "") {
if ($this->database->keydb_conf === '') {
$this->database->keydb_conf = null;
}
$this->database->save();
@@ -81,18 +90,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -105,10 +117,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneMariadb $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -32,6 +35,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -52,14 +56,17 @@ class General extends Component
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -69,6 +76,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -88,18 +96,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -112,10 +123,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneMongodb $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -31,6 +34,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -50,15 +54,17 @@ class General extends Component
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -68,6 +74,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -90,18 +97,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -114,10 +124,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public StandaloneMysql $database;
public Server $server;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -32,6 +35,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -52,14 +56,16 @@ class General extends Component
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -69,6 +75,7 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
@@ -88,18 +95,21 @@ class General extends Component
}
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -112,10 +122,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -14,10 +14,15 @@ use function Aws\filter;
class General extends Component
{
public StandalonePostgresql $database;
public Server $server;
public string $new_filename;
public string $new_content;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $listeners = ['refresh', 'save_init_script', 'delete_init_script'];
@@ -38,6 +43,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -53,20 +59,23 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -76,18 +85,21 @@ class General extends Component
return handleError($e, $this);
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -100,10 +112,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function save_init_script($script)
{
$this->database->init_scripts = filter($this->database->init_scripts, fn ($s) => $s['filename'] !== $script['filename']);
@@ -121,6 +135,7 @@ class General extends Component
$this->database->save();
$this->refresh();
$this->dispatch('success', 'Init script deleted.');
return;
}
}
@@ -139,9 +154,10 @@ class General extends Component
$found = collect($this->database->init_scripts)->firstWhere('filename', $this->new_filename);
if ($found) {
$this->dispatch('error', 'Filename already exists.');
return;
}
if (!isset($this->database->init_scripts)) {
if (! isset($this->database->init_scripts)) {
$this->database->init_scripts = [];
}
$this->database->init_scripts = array_merge($this->database->init_scripts, [
@@ -149,7 +165,7 @@ class General extends Component
'index' => count($this->database->init_scripts),
'filename' => $this->new_filename,
'content' => $this->new_content,
]
],
]);
$this->database->save();
$this->dispatch('success', 'Init script added.');

View File

@@ -14,8 +14,11 @@ class General extends Component
protected $listeners = ['refresh'];
public Server $server;
public StandaloneRedis $database;
public ?string $db_url = null;
public ?string $db_url_public = null;
protected $rules = [
@@ -29,6 +32,7 @@ class General extends Component
'database.public_port' => 'nullable|integer',
'database.is_log_drain_enabled' => 'nullable|boolean',
];
protected $validationAttributes = [
'database.name' => 'Name',
'database.description' => 'Description',
@@ -39,20 +43,24 @@ class General extends Component
'database.is_public' => 'Is Public',
'database.public_port' => 'Public Port',
];
public function mount()
{
$this->db_url = $this->database->get_db_url(true);
if ($this->database->is_public) {
$this->db_url_public = $this->database->get_db_url();
}
$this->server = data_get($this->database,'destination.server');
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced() {
public function instantSaveAdvanced()
{
try {
if (!$this->server->isLogDrainEnabled()) {
if (! $this->server->isLogDrainEnabled()) {
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->database->save();
@@ -62,11 +70,12 @@ class General extends Component
return handleError($e, $this);
}
}
public function submit()
{
try {
$this->validate();
if ($this->database->redis_conf === "") {
if ($this->database->redis_conf === '') {
$this->database->redis_conf = null;
}
$this->database->save();
@@ -75,18 +84,21 @@ class General extends Component
return handleError($e, $this);
}
}
public function instantSave()
{
try {
if ($this->database->is_public && !$this->database->public_port) {
if ($this->database->is_public && ! $this->database->public_port) {
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return;
}
if ($this->database->is_public) {
if (!str($this->database->status)->startsWith('running')) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return;
}
StartDatabaseProxy::run($this->database);
@@ -99,10 +111,12 @@ class General extends Component
}
$this->database->save();
} catch (\Throwable $e) {
$this->database->is_public = !$this->database->is_public;
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
}
public function refresh(): void
{
$this->database->refresh();

View File

@@ -8,12 +8,19 @@ use Livewire\Component;
class ScheduledBackups extends Component
{
public $database;
public $parameters;
public $type;
public ?ScheduledDatabaseBackup $selectedBackup;
public $selectedBackupId;
public $s3s;
protected $listeners = ['refreshScheduledBackups'];
protected $queryString = ['selectedBackupId'];
public function mount(): void
@@ -29,13 +36,16 @@ class ScheduledBackups extends Component
}
$this->s3s = currentTeam()->s3s;
}
public function setSelectedBackup($backupId) {
public function setSelectedBackup($backupId)
{
$this->selectedBackupId = $backupId;
$this->selectedBackup = $this->database->scheduledBackups->find($this->selectedBackupId);
if (is_null($this->selectedBackup)) {
$this->selectedBackupId = null;
}
}
public function delete($scheduled_backup_id): void
{
$this->database->scheduledBackups->find($scheduled_backup_id)->delete();