gpt4 book ai didi

sql-maven-plugin 按照 pom.xml 中列出的确切顺序执行文件

转载 作者:行者123 更新时间:2023-12-04 14:15:15 25 4
gpt4 key购买 nike

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

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

正如您在下面的示例中看到的那样,执行顺序未定义,尽管在执行期间执行了第一个文件 *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>

提前感谢您的任何帮助!

最佳答案

也许我误解了一个东西而是一个 excerpt from the docs说:

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!)



这意味着您应该使用 srcFiles而不是 includes .意思是这样的:
<configuration>
<srcFiles>
<srcFile>first.sql</srcFile>
<srcFile>second.sql</srcFile>
<srcFile>a.sql</srcFile>
..
</srcFiles>
.
</configuration>

顺便说一句:您配置中的绝对路径:
d:/PRIVAT/Projects/java/bigProject/

应该避免。

关于sql-maven-plugin 按照 pom.xml 中列出的确切顺序执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14184473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com