org.leberrigaud.maven.plugins.database.Postgres.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of database-maven-plugin Show documentation
Show all versions of database-maven-plugin Show documentation
A maven plugin to create and drop databases and their associated users.
package org.leberrigaud.maven.plugins.database
final class Postgres implements Database
{
String driverClass()
{
'org.postgresql.Driver'
}
String defaultPort()
{
'5432'
}
boolean supportsSchema()
{
true
}
String defaultRootUsername()
{
'postgres'
}
String adminDbName()
{
'postgres'
}
String url(DatabaseConfiguration config)
{
"jdbc:postgresql://$config.host:${config.getPort(defaultPort())}/$config.databaseName"
}
List create(DatabaseConfiguration config)
{
[
"create user $config.username with password '$config.password'",
"create database $config.databaseName",
"grant all privileges on database $config.databaseName to $config.username"
]
}
List update(DatabaseConfiguration config)
{
def sql = []
if (config.databaseSchema)
sql.add("create schema ${config.databaseSchema} authorization $config.username")
sql
}
List drop(DatabaseConfiguration config)
{
[
"drop database $config.databaseName",
"drop role $config.username"
]
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy