chore(postgresql): create role and user statements do not use if not exists

This commit is contained in:
Michele Cereda
2024-07-05 22:42:31 +02:00
parent 47803a5ee8
commit ff292ceb6c
2 changed files with 9 additions and 2 deletions

View File

@@ -110,7 +110,6 @@
# remove anything involving 'rdsadmin'
# remove changes to protected RDS users
# remove protected 'superuser' and 'replication' assignments
# add 'IF NOT EXISTS' to creation statements
vars:
# **Hack notice**: Ansible has issues with splitting on new lines if this template is quoted differently
permissions_dump_content_as_lines: "{{ dump_file.content | ansible.builtin.b64decode | split('\n') }}"
@@ -125,7 +124,6 @@
| reject('match', '.*rdsadmin.*')
| reject('match', '^(CREATE|ALTER) ROLE rds_')
| map('regex_replace', '(NO)(SUPERUSER|REPLICATION)\s?', '')
| map('regex_replace', '(CREATE \w+ \w+)(.*)', '\1 IF NOT EXISTS\2')
}}
- name: Manipulate dictionaries

View File

@@ -69,6 +69,15 @@ select usename FROM pg_catalog.pg_user;
-- Check the current user has SuperUser permissions
SHOW is_superuser
-- Create roles
-- Does *not* support IF NOT EXISTS
CREATE ROLE miriam;
CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';
-- Create users
-- Does *not* support IF NOT EXISTS
CREATE USER mike;
-- Grant users SuperUser permissions
-- Executing user must be already SuperUser
ALTER USER joel WITH SUPERUSER;