fix indexing after deletion and make sure init script is removed form the server
This commit is contained in:
		| @@ -144,11 +144,13 @@ class General extends Component | |||||||
|             $initScripts->push($script); |             $initScripts->push($script); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $this->database->init_scripts = $initScripts->values()->map(function ($item, $index) { |         $this->database->init_scripts = $initScripts->values() | ||||||
|  |             ->map(function ($item, $index) { | ||||||
|                 $item['index'] = $index; |                 $item['index'] = $index; | ||||||
| 
 | 
 | ||||||
|                 return $item; |                 return $item; | ||||||
|         })->all(); |             }) | ||||||
|  |             ->all(); | ||||||
| 
 | 
 | ||||||
|         $this->database->save(); |         $this->database->save(); | ||||||
|         $this->dispatch('success', 'Init script saved.'); |         $this->dispatch('success', 'Init script saved.'); | ||||||
| @@ -159,13 +161,33 @@ class General extends Component | |||||||
|         $collection = collect($this->database->init_scripts); |         $collection = collect($this->database->init_scripts); | ||||||
|         $found = $collection->firstWhere('filename', $script['filename']); |         $found = $collection->firstWhere('filename', $script['filename']); | ||||||
|         if ($found) { |         if ($found) { | ||||||
|             $this->database->init_scripts = $collection->filter(fn ($s) => $s['filename'] !== $script['filename'])->toArray(); |             $container_name = $this->database->uuid; | ||||||
|             $this->database->save(); |             $configuration_dir = database_configuration_dir().'/'.$container_name; | ||||||
|             $this->refresh(); |             $file_path = "$configuration_dir/docker-entrypoint-initdb.d/{$script['filename']}"; | ||||||
|             $this->dispatch('success', 'Init script deleted.'); | 
 | ||||||
|  |             $command = "rm -f $file_path"; | ||||||
|  |             try { | ||||||
|  |                 instant_remote_process([$command], $this->server); | ||||||
|  |             } catch (\Exception $e) { | ||||||
|  |                 $this->dispatch('error', 'Failed to remove init script from server: '.$e->getMessage()); | ||||||
| 
 | 
 | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             $updatedScripts = $collection->filter(fn ($s) => $s['filename'] !== $script['filename']) | ||||||
|  |                 ->values() | ||||||
|  |                 ->map(function ($item, $index) { | ||||||
|  |                     $item['index'] = $index; | ||||||
|  | 
 | ||||||
|  |                     return $item; | ||||||
|  |                 }) | ||||||
|  |                 ->all(); | ||||||
|  | 
 | ||||||
|  |             $this->database->init_scripts = $updatedScripts; | ||||||
|  |             $this->database->save(); | ||||||
|  |             $this->refresh(); | ||||||
|  |             $this->dispatch('success', 'Init script deleted from the database and the server.'); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function refresh(): void |     public function refresh(): void | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|         <x-forms.button type="submit">Save</x-forms.button> |         <x-forms.button type="submit">Save</x-forms.button> | ||||||
|         <x-modal-confirmation title="Confirm init-script deletion?" buttonTitle="Delete" isErrorButton |         <x-modal-confirmation title="Confirm init-script deletion?" buttonTitle="Delete" isErrorButton | ||||||
|             submitAction="delete" :actions="[
 |             submitAction="delete" :actions="[
 | ||||||
|                 'The init-script of this database will be permanently deleted.', |                 'The init-script of this database will be permanently deleted form the database and the server.', | ||||||
|                 'If you are actively using this init-script, it could cause errors on redeployment.', |                 'If you are actively using this init-script, it could cause errors on redeployment.', | ||||||
|             ]" confirmationText="{{ $filename }}" |             ]" confirmationText="{{ $filename }}" | ||||||
|             confirmationLabel="Please confirm the execution of the actions by entering the init-script name below" |             confirmationLabel="Please confirm the execution of the actions by entering the init-script name below" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 peaklabs-dev
					peaklabs-dev