org.leberrigaud.maven.plugins.database.SqlServer.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 SqlServer implements Database
{
final static String PORT = '1433'
final String driver = 'net.sourceforge.jtds.jdbc.Driver'
final def url(def host = 'localhost', def port = PORT)
{ "jdbc:jtds:sqlserver://$host:${port ? port : PORT}/master" }
List create(String username, String password, String dbName, String schema)
{
def sql = []
sql.addAll([
"CREATE LOGIN $username WITH PASSWORD = '$password'",
"CREATE USER $username FOR LOGIN $username"
])
sql.addAll([
"CREATE DATABASE $dbName",
"ALTER AUTHORIZATION ON DATABASE::$dbName TO $username",
"ALTER USER $username WITH DEFAULT_SCHEMA = ${schema ?: dbName}",
])
if (schema)
{
sql.addAll([
"USE $dbName",
"CREATE SCHEMA $schema",
])
}
sql
}
List drop(String username, String password, String dbName, String schema)
{
[
"DROP DATABASE $dbName",
"DROP LOGIN $username",
"DROP USER $username"
]
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy