mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
fix dashes on the name and better error handling (#336)
This commit is contained in:
@ -2,10 +2,26 @@
|
||||
|
||||
namespace App\SSH\Services\Database;
|
||||
|
||||
use App\Exceptions\SSHError;
|
||||
|
||||
class Postgresql extends AbstractDatabase
|
||||
{
|
||||
protected function getScriptsDir(): string
|
||||
{
|
||||
return 'postgresql';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function create(string $name): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
$this->getScript($this->getScriptsDir().'/create.sh', [
|
||||
'name' => $name,
|
||||
'ssh_user' => $this->service->server->ssh_user,
|
||||
]),
|
||||
'create-database'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
if ! sudo -u postgres psql -c "CREATE ROLE __username__ WITH LOGIN PASSWORD '__password__';"; then
|
||||
if ! sudo -u postgres psql -c "CREATE ROLE \"__username__\" WITH LOGIN PASSWORD '__password__';"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
if ! sudo -u postgres psql -c "CREATE DATABASE __name__"; then
|
||||
if ! sudo -u postgres psql -c "CREATE DATABASE \"__name__\""; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
if ! sudo -u postgres psql -c "DROP USER __username__"; then
|
||||
if ! sudo -u postgres psql -c "DROP USER \"__username__\""; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
if ! sudo -u postgres psql -c "DROP DATABASE __name__"; then
|
||||
if ! sudo -u postgres psql -c "DROP DATABASE \"__name__\""; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE __database__ TO __username__;"; then
|
||||
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"__database__\" TO \"__username__\";"; then
|
||||
echo 'VITO_SSH_ERROR' && exit 1
|
||||
fi
|
||||
|
||||
|
@ -4,7 +4,7 @@ DATABASES=$(sudo -u postgres psql -t -c "SELECT datname FROM pg_database WHERE d
|
||||
|
||||
for DB in $DATABASES; do
|
||||
echo "Revoking privileges in database: $DB"
|
||||
sudo -u postgres psql -d "$DB" -c "REVOKE ALL PRIVILEGES ON DATABASE \"$DB\" FROM $USER_TO_REVOKE;"
|
||||
sudo -u postgres psql -d "$DB" -c "REVOKE ALL PRIVILEGES ON DATABASE \"$DB\" FROM \"$USER_TO_REVOKE\";"
|
||||
done
|
||||
|
||||
echo "Privileges revoked from $USER_TO_REVOKE"
|
||||
|
Reference in New Issue
Block a user