Skip to content

patio-team/dwbh-gradle-fixtures

Repository files navigation

Gradle Plugin Portal Travis License

DWBH FIXTURES GRADLE PLUGIN

This plugin allows you to execute sql files against a configured database. It differentiates between sql files to load data and those sql to clean data.

Installation

Using the new plugins DSL:

plugins {
   id 'net.kaleidos.dwbh.gradle-fixtures-plugin' version "0.1.2"
}

or

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "net.kaleidos.dwbh:gradle-fixtures-plugin:0.1.2"
  }
}

apply plugin: 'net.kaleidos.dwbh.gradle-fixtures-plugin'

Configuration:

Although the plugin defines by default where to find the sql files to load/clean data and where to find the database configuration file, you can use the fixtures extension to override those values:

fixtures {
   loadDir = 'customDir/load'
   cleanDir = 'customDir/clean'
   configFile = 'customDir/db.yml'
}

Here are the definitions of each field:

Name Description default
loadDir Where to put the fixtures SQL files fixtures/load
cleanDir Directory where to find the sql files to clean fixtures fixtures/clean
configFile File to get the database connection from fixtures/fixtures.yml

Database dependencies

To include your database dependency, you can add the driver dependency in your project's dependencies block, e.g:

dependencies {
  fixtures 'org.postgresql:postgresql:42.2.5'
}

Loading fixtures

Once you have configured the plugin you can just execute:

./gradlew fixtures-load

And all sql files found at the loadDir will be executed against the configured database. Sql files are executed in order by name.

Cleaning fixtures

You can execute:

./gradlew fixtures-clean

And all sql files found at the cleanDir will be executed against the configured database. In this case sql files are executed in reverse order.

Acknowledgments

Thanks to Kaleidos Open Source to make this project possible.