Igor's Blog

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

comments powered by Disqus
Other posts you may like...
Programming, DIY, Games, Hacks, and Tech

Recent Blog Posts

Swapping HDD logic boards between different brand disks - is it possible?

A guide for plotting your hard drive for Burstcoin mining on a Mac using mjminer

Replacing a broken hard drive in a Samsung Story Station

Fix Java applications slow start and net connection times on macOS sierra

Pierre Cardin Leather Computer Bag (PC2278)

How to stop SSH remote host disconnecting your session

Using PayPal PHP SDK on Google App Engine

Use the Touch Bar to lock your Mac with a single button press

Multi module builds with Maven 3.5 and the parent-child pom version management

Google App Engine local dev server DataStore becoming corrupted after a bad GQL statement is run

Recent Galleries

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

DIY indoor apartment grow light wiring

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 feel obliged, but you could follow me for more great content!
     
Don't show this again