Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

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...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Tiny Arcade revision 6 kit assembly and decal application

Jersey JAX-RS filters and interceptors execution order for a simple GET request

How to stop macOS adding shadows to window screenshots

How to run Atari Lynx games on the SNES Classic Mini

Maven dependency scopes with relation to WAR file packaging and the WEB-INF/lib directory

Hacking the Sonoff B1 WiFi LED bulb to run custom firmware

What does an idle WebLogic server run on the hour to cause a CPU spike

How to open the Sonoff B1 wifi LED bulb to access its internal circuitry

Australian release SNES mini classic unboxing and a quick play through

Troubleshooting high CPU usage for JVM threads

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

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

Blogs and Friends

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

Blog Activity

Blog Activity