All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.leberrigaud.maven.plugins.database.SqlServer.groovy Maven / Gradle / Ivy

There is a newer version: 0.10
Show newest version
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