Quick tip of the day:
Use Gradle plugins to package up functionality for easy reuse. For example, we developed a simple “database” plugin to handle the common tasks associated with building and upgrading a database. Things like:
- build – create a new database from scratch. Runs the CREATE DATABASE and sqlcmd’s the full DDL
- upgrade – checks the current version, looks for (and generates from the model if needed) and upgrade script, and runs it.
- clean – DROP DATABASE – get ready for something new.
- load – part of “build”, load static initial data from CSV files into the newly created database structure.
Now, all we do to enable a database in our environment is add a build.gradle file to the database directory (with ddl/, sp/, and data/ subdirectories) with:
apply plugin: 'Database'
Away we go!