Igor's Blog
Programming, DIY, Games, Hacks, and Tech

If you've ever worked on a PL/SQL project or any project with a good amount of database related work you probably have had to deal with multiple SQL files and their deployment across systems. This is exactly what I've come across recently. Even in the early stages of my PL/SQL project I had 11 separate SQL files that would need to be deployed to system and performance test environments, then propagated to production, production support, etc. To help with managing all this I decided that building a single 'super SQL' file would work best and I ended up using Maven to do it.
sqldev_ddl.png


Maven isn't exactly suitable for PL/SQL or SQL development, but it is possible to reuse its concepts and apply them in this case anyway. I went about creating the Maven directory structure as per usual approach, my SQL files went into ${project.basedir}/src/main/sql and then I had a pom.xml in the project root directory.

I didn't actually want to do anything too smart with Maven. All I was after was the ability to merge the individual SQL files into one big super SQL file. This file would be the distributable that would get applied across various environments.

After lots of reading about the easiest way to merge files in Maven I hit a bit of a roadblock since most of the focus was on merging ZIP, JAR or Property files, not what I was after. Eventually I found the Maven Merge Plugin which did exactly what I wanted, a simple merge (concatenation actually) of files. So that's what I went with.

I had a look at the source code for the plugin and didn't really like its 'how to run' part so ended up doing something different in my pom.xml file. I simply bound the plugin 'merge' goal to the 'package' phase so to run it all I had to do was...
 Maven
mvn clean package




This is what my pom.xml looked like...
 Maven POM
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>net.igorkromin</groupId>
<artifactId>SqlMergeExample</artifactId>
<name>${project.artifactId}</name>
<version>1.0</version>
<description>SqlMergeExample</description>
<packaging>pom</packaging>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}</outputDirectory>
<plugins>
<plugin>
<groupId>org.zcore.maven</groupId>
<artifactId>merge-maven-plugin</artifactId>
<version>0.0.3</version>
<executions>
<execution>
<id>merge</id>
<phase>package</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<mergers>
<merger>
<target>${project.build.outputDirectory}/super.sql</target>
<sources>
<source>src/main/sql/tbl_mytable1.sql</source>
<source>src/main/sql/pkg_mypackcage1.sql</source>
...
</sources>
</merger>
</mergers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>


You can see that packaging is set to POM, that is because we are not compiling any Java, etc. The rest is fairly straight forward, there is no dependency section like described in the plugin's readme, that's not required - Maven will figure it out for you.

The main part is really all those lines. The files are concatenated together using the order that they appear in the pom.xml file.

That's all there is to it really, just list all the files, run the package phase and you will have a super SQL file in the usual target directory.

-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...

Recent Blog Posts

How to enable the full stack trace in Maven's Surefire plugin for JUnit testing

Twelve elements of the Burst Mining Pool interface explained

TPG FTTB settings for the Billion BiPAC 8700AXL 1600 modem router

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

How to fix SoapUI javax.net.ssl.SSLHandshakeException calling WebLogic 12.2 web services on Java 8

Woolworths (WOW) shares disappeared from Computer Share Investor Centre

Connecting the Dell UltraSharp U3415W monitor to a MacBookPro via USB-C

How to add/change PHP versions appearing in MAMP preferences

Fix the ORA-00904: ORA_ROWSCN: invalid identifier error in SQLDeveloper with a few easy steps

G Suite Gmail is broken on Safari due to new Google Content Security Policy settings

Recent Galleries

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer
Travel ┬ÁBlog

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Don't forget to
my Facebook page for more great articles!
Don't show this again