6

我想就sql-mvn-plugin寻求一些帮助。根据文档,如果 pom.xml 文件没有关于文件顺序的任何内容 - orderFile标记 - 则文件将按照列出的确切顺序执行。但事实并非如此!如果我删除orderFile标记,则默认情况下将按升序执行文件。

老实说,我想在安装过程中使用这个插件来创建数据库和导入数据。由于我正在处理 20 多个表 - 脚本、表和序列以及约束被分成单独的文件 - 我无法处理没有有意义名称的文件。它本身就是地狱,使用这个插件将毫无价值。另一方面,我不想在 maven 之外进行这一步,因为在我的脑海中,maven 是构建、测试和部署我的应用程序的工具,也是避免脚本地狱的工具。

正如您在下面的示例中看到的,执行顺序没有定义,尽管在执行过程中执行的第一个文件是 *procedures/test_activate_all_partners.sql*,它是文件顺序中的倒数第二个!在我的理解中,第一个执行的文件应该是 *tables/datapoint_component_types/table.sql*。

我的 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>

输出:

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>

提前感谢您的帮助!

4

1 回答 1

9

也许我误解了一些事情,但文档的摘录说:

包含要加载的 SQL 语句的文件。如果您想使用类似 ant 的文件模式,请仅使用 Fileset,否则使用srcFiles. 该顺序基于扫描目录时的匹配事件(不是包含的顺序!)

这意味着您应该使用srcFiles而不是includes. 意思是这样的:

<configuration>
  <srcFiles>
    <srcFile>first.sql</srcFile>
    <srcFile>second.sql</srcFile>
    <srcFile>a.sql</srcFile>
    ..
  </srcFiles>
  .
</configuration>

顺便说一句:配置中的绝对路径:

d:/PRIVAT/Projects/java/bigProject/

应该避免。

于 2013-01-07T08:33:01.363 回答