I would like to ask some help regarding sql-mvn-plugin. According to the documentation if the pom.xml file does not have anything about the file order - orderFile tag - than the files will be executed in the exact order as they are listed. But it is not true! If I remove the orderFile tag than the files will be executed by ascending by default.
To be honest, I wanted to use this plugin to create the database and import data during installation. Due to the fact I'm working more than 20 tables - the scripts, the table and the sequence and the constraints, are separated into individual files - I can not work files which do not have meaningful name. It would be the hell itself and using this plugin would be worthless. On the other hand I don't want to have this step outside from maven because in my head the maven is the tool to build, to test and deploy my application and the tool to avoid the script hell.
As you can see in the sample below the execution order is not defined, and despite this fact during execution the first file which is executed the *procedures/test_activate_all_partners.sql*, which is the penultimate in the file order! In my understanding the first executed file should be the *tables/datapoint_component_types/table.sql*.
My pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
</dependencies>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/database</url>
<username>postgres</username>
<password>postgres</password>
</configuration>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<delimiter>/</delimiter>
<delimiterType>normal</delimiterType>
<autocommit>true</autocommit>
<fileset>
<!-- at home -->
<basedir>d:/PRIVAT/Projects/java/bigProject/</basedir>
<includes>
<!-- tables -->
<include>tables/datapoint_component_types/table.sql</include>
<include>tables/datapoint_datapoint_components/table.sql</include>
<include>tables/datapoint_java_result_types/table.sql</include>
<include>tables/datapoint_postgres_result_types/table.sql</include>
<include>tables/datapoint_result_types/table.sql</include>
<include>tables/datapoints/table.sql</include>
<include>tables/datatype_descs/table.sql</include>
<include>tables/datatypes/table.sql</include>
<include>tables/disabled_period/table.sql</include>
<include>tables/file_extensions/table.sql</include>
<include>tables/logs/table.sql</include>
<include>tables/partner_datatypes/table.sql</include>
<include>tables/partner_processes/table.sql</include>
<include>tables/partner_protocols/table.sql</include>
<include>tables/partner_protocols_attributes_details/table.sql</include>
<include>tables/partners/table.sql</include>
<include>tables/process_step/table.sql</include>
<include>tables/process_step_actions/table.sql</include>
<include>tables/process_steps_param/table.sql</include>
<include>tables/process_steps_partner_processes/table.sql</include>
<include>tables/processes/table.sql</include>
<include>tables/protocol_attributes/table.sql</include>
<include>tables/protocols/table.sql</include>
<include>tables/result_tables/table.sql</include>
<include>tables/valid_period/table.sql</include>
<!-- constrains -->
<include>tables/datapoint_component_types/sequences.sql</include>
<include>tables/datapoint_datapoint_components/sequences.sql</include>
<include>tables/datapoint_java_result_types/sequences.sql</include>
<include>tables/datapoint_postgres_result_types/sequences.sql</include>
<include>tables/datapoint_result_types/sequences.sql</include>
<include>tables/datapoints/sequences.sql</include>
<include>tables/datatype_descs/sequences.sql</include>
<include>tables/datatypes/sequences.sql</include>
<include>tables/disabled_period/sequences.sql</include>
<include>tables/file_extensions/sequences.sql</include>
<include>tables/logs/sequences.sql</include>
<include>tables/partner_datatypes/sequences.sql</include>
<include>tables/partner_processes/sequences.sql</include>
<include>tables/partner_protocols/sequences.sql</include>
<include>tables/partner_protocols_attributes_details/sequences.sql</include>
<include>tables/partners/sequences.sql</include>
<include>tables/process_step/sequences.sql</include>
<include>tables/process_step_actions/sequences.sql</include>
<include>tables/process_steps_param/sequences.sql</include>
<include>tables/process_steps_partner_processes/sequences.sql</include>
<include>tables/processes/sequences.sql</include>
<include>tables/protocol_attributes/sequences.sql</include>
<include>tables/protocols/sequences.sql</include>
<include>tables/result_tables/sequences.sql</include>
<include>tables/valid_period/sequences.sql</include>
<!-- sequences -->
<include>tables/datapoint_component_types/constraints.sql</include>
<include>tables/datapoint_datapoint_components/constraints.sql</include>
<include>tables/datapoint_java_result_types/constraints.sql</include>
<include>tables/datapoint_postgres_result_types/constraints.sql</include>
<include>tables/datapoint_result_types/constraints.sql</include>
<include>tables/datapoints/constraints.sql</include>
<include>tables/datatype_descs/constraints.sql</include>
<include>tables/datatypes/constraints.sql</include>
<include>tables/disabled_period/constraints.sql</include>
<include>tables/file_extensions/constraints.sql</include>
<include>tables/logs/constraints.sql</include>
<include>tables/partner_datatypes/constraints.sql</include>
<include>tables/partner_processes/constraints.sql</include>
<include>tables/partner_protocols/constraints.sql</include>
<include>tables/partner_protocols_attributes_details/constraints.sql</include>
<include>tables/partners/constraints.sql</include>
<include>tables/process_step/constraints.sql</include>
<include>tables/process_step_actions/constraints.sql</include>
<include>tables/process_steps_param/constraints.sql</include>
<include>tables/process_steps_partner_processes/constraints.sql</include>
<include>tables/processes/constraints.sql</include>
<include>tables/protocol_attributes/constraints.sql</include>
<include>tables/protocols/constraints.sql</include>
<include>tables/result_tables/constraints.sql</include>
<include>tables/valid_period/constraints.sql</include>
<!-- procedures -->
<include>procedures/test_activate_all_partners.sql</include>
<!-- testdata -->
<include>testdata/data.sql</include>
</includes>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
The output:
d:/PRIVAT/Projects/java/bigProject>mvn sql:execute
[INFO] Scanning for projects...
...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EJB 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (default-cli) @ DiLibCoreEJB ---
[INFO] Executing file: sql\procedures\test_activate_all_partners.sql
[INFO] Executing file: sql\tables\datapoints\constraints.sql
[ERROR] Failed to execute:
ALTER TABLE
datapoints
ADD
CONSTRAINT datapoints_pkey PRIMARY KEY (datapoint_id );
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.503s
[INFO] Finished at: Sun Jan 06 17:49:40 CET 2013
[INFO] Final Memory: 4M/77M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default-cli) on project DiLibCoreEJB: ERROR: relation "datapoints" does not exist -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
d:/PRIVAT/Projects/java/bigProject>
Thanks for any help in advance!
Maybe I misunderstand a things but an excerpt from the docs says:
File(s) containing SQL statements to load. Only use a Fileset if you want to use ant-like filepatterns, otherwise use
srcFiles
. The order is based on a matching occurrence while scanning the directory (not the order of includes!)
which means that you should use srcFiles
instead of includes
. Means something like this:
<configuration>
<srcFiles>
<srcFile>first.sql</srcFile>
<srcFile>second.sql</srcFile>
<srcFile>a.sql</srcFile>
..
</srcFiles>
.
</configuration>
BTW: absolute path in you configuration:
d:/PRIVAT/Projects/java/bigProject/
should be avoided.