configurations {
    liquibaseRuntime.extendsFrom sourceSets.main.compileClasspath
}

dependencies {
  implementation "org.liquibase:liquibase-core"
  liquibaseRuntime "org.liquibase:liquibase-core"
  // Dependency required to parse options. Refer to https://github.com/liquibase/liquibase-gradle-plugin/tree/Release_2.2.0#news.
  liquibaseRuntime "info.picocli:picocli:4.7.7"
  liquibaseRuntime "org.postgresql:postgresql"
  liquibaseRuntime "org.liquibase.ext:liquibase-hibernate6:${liquibaseVersion}"
  // jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}

project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
if (!project.hasProperty("runList")) {
 project.ext.runList = "main"
}

liquibase {
  activities {
    main {
      driver "org.postgresql.Driver"
      url "jdbc:postgresql://localhost:5432/smartbooking"
      username "smartbooking"
      changelogFile "src/main/resources/config/liquibase/master.xml"
      logLevel "debug"
      classpath "src/main/resources/"
    }
    diffLog {
      driver "org.postgresql.Driver"
      url "jdbc:postgresql://localhost:5432/smartbooking"
      username "smartbooking"
      changelogFile project.ext.diffChangelogFile
      referenceUrl "hibernate:spring:it.sw.pa.comune.artegna.domain?dialect=org.hibernate.dialect.PostgreSQLDialect&hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
      logLevel "debug"
      classpath "$buildDir/classes/java/main"
    }
  }

  runList = project.ext.runList
}

liquibaseDiff.dependsOn(compileJava)
liquibaseDiffChangelog.dependsOn(compileJava)

ext {
  if (project.hasProperty("no-liquibase")) {
    springProfiles += ",no-liquibase"
  }
}
