Created
July 29, 2021 12:43
-
-
Save Ingco/de02a2c8585a49b847002568dd62ad64 to your computer and use it in GitHub Desktop.
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
shellScript { | |
content = """ | |
psql -v ON_ERROR_STOP=1 --username ${'$'}POSTGRES_USER <<-EOF | |
CREATE EXTENSION IF NOT EXISTS dblink; | |
DO \$$ | |
BEGIN | |
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = ${'$'}DB_USER) THEN | |
CREATE USER ${'$'}DB_USER PASSWORD ${'$'}DB_PASSWORD; | |
ALTER USER ${'$'}DB_USER CREATEDB; | |
END IF; | |
IF NOT EXISTS (SELECT FROM pg_database WHERE datname = ${'$'}DB_NAME) THEN | |
PERFORM dblink_exec('', 'CREATE DATABASE ${'$'}DB_NAME'); | |
GRANT ALL PRIVILEGES ON DATABASE ${'$'}DB_NAME TO ${'$'}DB_USER; | |
END IF; | |
END | |
\$$; | |
EOF | |
""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment