plugins {
    id 'application'
    id 'org.liquibase.gradle' version '2.1.1'
}

repositories {
    mavenCentral()
}

def db_host = System.getenv("DB_HOST") ?: "db"
def db_port = System.getenv("DB_PORT") ?: "3306"
def db_name = System.getenv("CDR_DB_NAME") ?: "cdr"
def liquibase_password = System.getenv("LIQUIBASE_DB_PASSWORD") ?: "lb-notasecret"
applicationDefaultJvmArgs = ["-Xmx2048m","-Xms2048m"]

dependencies {
    liquibaseRuntime 'org.liquibase:liquibase-core:4.31.1'
    liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:4.0.0'
    liquibaseRuntime 'info.picocli:picocli:4.7.6'
    liquibaseRuntime 'com.mysql:mysql-connector-j:9.3.0'
    liquibaseRuntime 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.2'
    liquibaseRuntime 'org.glassfish.jaxb:jaxb-runtime:4.0.5'
}

liquibase {
    activities {
        schema {
            changeLogFile "changelog-schema/db.changelog-master.xml"
            url "jdbc:mysql://${db_host}:${db_port}/${db_name}"
            username "liquibase"
            password "${liquibase_password}"
            classpath "$rootDir"
            showBanner false
        }
        data {
            if (project.hasProperty('contexts')) {
                contexts contexts
            }
            changeLogFile "changelog-data/db.changelog-master.xml"
            url "jdbc:mysql://${db_host}:${db_port}/${db_name}"
            username "liquibase"
            password "${liquibase_password}"
            classpath "$rootDir"
            showBanner false
        }
        add_bigdata_indexes {
            if (project.hasProperty('contexts')) {
                contexts contexts
            }
            changeLogFile "changelog-bigdata/db.changelog-add-indexes.xml"
            url "jdbc:mysql://${db_host}:${db_port}/${db_name}"
            username "liquibase"
            password "${liquibase_password}"
            classpath "$rootDir"
            showBanner false
        }
        drop_bigdata_indexes {
            if (project.hasProperty('contexts')) {
                contexts contexts
            }
            changeLogFile "changelog-bigdata/db.changelog-drop-indexes.xml"
            url "jdbc:mysql://${db_host}:${db_port}/${db_name}"
            username "liquibase"
            password "${liquibase_password}"
            classpath "$rootDir"
            showBanner false
        }
        runList = project.ext.runList
    }
}
