如何在MS Server中将Liquibase Maven插件与指定架构集成

时间:2019-03-20 17:52:11

标签: sql-server liquibase

这是我对liquibase maven插件的配置:

  <plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>3.6.3</version>
    <executions>
      <execution>
        <goals>
          <goal>status</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <changeLogFile>src/main/resources/db/changelog/db-changelog-master.xml</changeLogFile>
      <driver>${liquibase.driver}</driver>
      <username>${liquibase.username}</username>
      <password>${liquibase.password}</password>
      <url>${liquibase.url}</url>
      <referenceDriver>${liquibase.driver}</referenceDriver>
      <referenceUsername>${liquibase.username}</referenceUsername>
      <referencePassword>${liquibase.password}</referencePassword>
      <referenceUrl>${liquibase.url}</referenceUrl>
      <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.3.0</version>
      </dependency>
      <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.4.0.jre8</version>
      </dependency>
    </dependencies>
  </plugin>

如果我正在使用

<profile>
  <id>local</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <properties>
    <liquibase.url>jdbc:sqlserver://localhost:1433</liquibase.url>
    <liquibase.driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</liquibase.driver>
    <liquibase.username>SA</liquibase.username>
    <liquibase.password>dev-pa$Sw0rd</liquibase.password>
  </properties>
</profile>

它工作正常。但是,如果我尝试使用:

    <liquibase.url>jdbc:sqlserver://localhost:1433;DatabaseName=eBatch_Retry</liquibase.url>

这给了我例外。

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.6.3:migrate (default-cli) on project dc-database: Error setting up or running Liquibase: liquibase.exception.DatabaseException: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "eBatch_Retry" requested by the login. The login failed. ClientConnectionId:0a136358-788a-4b78-b779-76175467a832 -> [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

模式是使用脚本创建的:

IF (NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'eBatch_Retry')) 
BEGIN
    EXEC ('CREATE SCHEMA [eBatch_Retry]')
END

我正在使用的用户授予数据库中的所有内容。似乎是权限问题,因此我很困惑。

有什么想法可以解决我的问题吗?

1 个答案:

答案 0 :(得分:1)

解决方案是创建数据库,因为架构具有不同的含义。应用下一条指令后,我的liquibase在其中管理了默认架构(dbo)。

CREATE DATABASE eBatch_Retry;

情况:

<liquibase.url>jdbc:sqlserver://localhost:1433;DatabaseName=eBatch_Retry</liquibase.url>