Skip to content

Instantly share code, notes, and snippets.

@igouss
Created July 29, 2021 20:53
Show Gist options
  • Save igouss/823e5de9592e7cdb568d1acddde2f5bf to your computer and use it in GitHub Desktop.
Save igouss/823e5de9592e7cdb568d1acddde2f5bf to your computer and use it in GitHub Desktop.
Gradle execute SQL script in Postgresql database
import groovy.sql.Sql
task dropDatabase {
doLast {
Class.forName("org.postgresql.Driver")
def sql = groovy.sql.Sql.newInstance(
"jdbc:postgresql://localhost:5432/",
${DBA_USER},
${DBA_PASSWORD},
"org.postgresql.Driver"
);
sql.execute(
'''
DROP DATABASE IF EXISTS auditstore;
DROP OWNED BY auditstore;
DROP ROLE IF EXISTS auditstore;
'''
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment