From ff292ceb6cf204fe893d4c561887e8911f9ce923 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 5 Jul 2024 22:42:31 +0200 Subject: [PATCH] chore(postgresql): create role and user statements do not use if not exists --- snippets/ansible/tasks.yml | 2 -- snippets/postgresql.sql | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/snippets/ansible/tasks.yml b/snippets/ansible/tasks.yml index 5a9b132..ca24eb5 100644 --- a/snippets/ansible/tasks.yml +++ b/snippets/ansible/tasks.yml @@ -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 diff --git a/snippets/postgresql.sql b/snippets/postgresql.sql index b1cb2f2..e18a0b4 100644 --- a/snippets/postgresql.sql +++ b/snippets/postgresql.sql @@ -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;