-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Privileges for
public
Schema in PostgreSQL 15+ (#339)
- Loading branch information
Showing
3 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE __database__ TO __username__;"; then | ||
USER_TO_LINK='__username__' | ||
DB_NAME='__database__' | ||
DB_VERSION='__version__' | ||
|
||
if ! sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"$DB_NAME\" TO $USER_TO_LINK;"; then | ||
echo 'VITO_SSH_ERROR' && exit 1 | ||
fi | ||
|
||
echo "Linking to __database__ finished" | ||
# Check if PostgreSQL version is 15 or greater | ||
if [ "$DB_VERSION" -ge 15 ]; then | ||
if ! sudo -u postgres psql -d "$DB_NAME" -c "GRANT USAGE, CREATE ON SCHEMA public TO $USER_TO_LINK;"; then | ||
echo 'VITO_SSH_ERROR' && exit 1 | ||
fi | ||
fi | ||
|
||
echo "Linking to $DB_NAME finished" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
USER_TO_REVOKE='__username__' | ||
DB_VERSION='__version__' | ||
|
||
DATABASES=$(sudo -u postgres psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;") | ||
|
||
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;" | ||
|
||
# Check if PostgreSQL version is 15 or greater | ||
if [ "$DB_VERSION" -ge 15 ]; then | ||
sudo -u postgres psql -d "$DB" -c "REVOKE USAGE, CREATE ON SCHEMA public FROM $USER_TO_REVOKE;" | ||
fi | ||
done | ||
|
||
echo "Privileges revoked from $USER_TO_REVOKE" |