conditional application of SQL

nutmixnutmix Posts: 5 New member
edited May 21, 2024 12:23PM in Flyway (General Discussion)
I cant find any documentation on what can and cant go into a DB change script, but coming from liquibase, I am sure there is a way to conditionally apply SQL based on params or env prams, I just cant find it.

E.g. for stage and  prod (which is on RDS) we need:

CREATE EXTENSION IF NOT EXISTS aws_s3 WITH SCHEMA public;

and 

...             aws_commons.create_s3_uri(bucket_name, zip_filename, region),

but on dev (local postgres)

we must NOT do that stuff.

Any pointers on how to conditionally include specific lines of the script?  Or maybe liquibase has conditional script inclusion, so we need to separate into multiple scripts?
Tagged:

Best Answer

  • nutmixnutmix Posts: 5 New member
    edited May 21, 2024 3:21PM Answer ✓
    Unfortunately enterprise version is completely out of reach, but this does seem to work on free version:

    do $$ BEGIN

    if (select 1 from pg_catalog.pg_user p where p.usename = 'rdsadmin') then

    CREATE EXTENSION IF NOT EXISTS aws_s3 WITH SCHEMA public;

    end if;

    end $$;

Answers

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file