Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Multiple Init script fixes and some other Postgres fixes #3950

Merged
merged 12 commits into from
Dec 18, 2024
Prev Previous commit
Next Next commit
remove old init script on server if it is renamed
  • Loading branch information
peaklabs-dev committed Oct 18, 2024
commit 159c4aa7ac02fdae6849d8c6db7a7a837dd8f01a
18 changes: 17 additions & 1 deletion app/Livewire/Project/Database/Postgresql/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,29 @@ public function save_init_script($script)
$initScripts = collect($this->database->init_scripts ?? []);

$existingScript = $initScripts->firstWhere('filename', $script['filename']);
$oldScript = $initScripts->firstWhere('index', $script['index']);

if ($existingScript && $existingScript['index'] !== $script['index']) {
$this->dispatch('error', 'A script with this filename already exists.');

return;
}

$container_name = $this->database->uuid;
$configuration_dir = database_configuration_dir().'/'.$container_name;

if ($oldScript && $oldScript['filename'] !== $script['filename']) {
$old_file_path = "$configuration_dir/docker-entrypoint-initdb.d/{$oldScript['filename']}";
$delete_command = "rm -f $old_file_path";
try {
instant_remote_process([$delete_command], $this->server);
} catch (\Exception $e) {
$this->dispatch('error', 'Failed to remove old init script from server: '.$e->getMessage());

return;
}
}

$index = $initScripts->search(function ($item) use ($script) {
return $item['index'] === $script['index'];
});
Expand All @@ -153,7 +169,7 @@ public function save_init_script($script)
->all();

$this->database->save();
$this->dispatch('success', 'Init script saved.');
$this->dispatch('success', 'Init script saved and updated.');
}

public function delete_init_script($script)
Expand Down