Я новичок в liquibase и пытаюсь запустить какой-нибудь тест (версия 3.6.3).
- Я создал пустую базу данных с именем 'liquibase_testing'
- Я создал файл migrations.xml, который выглядит следующим образом:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<includeAll path="migrations" relativeToChangelogFile="true"/>
</databaseChangeLog>
Я создал простой скрипт CREATE TABLE и сохранил его в каталоге
migrations
как
001-liquibase-testing-create-names-table.sql
.Это выглядит так:
CREATE TABLE dbo.names (
name_id int identity,
first_name nvarchar(100),
last_name nvarchar(100),
primary key clustered (name_id)
)
Я запустил миграцию liquibase с помощью cli следующим образом:
./_liquibase/liquibase-3.6.3-bin/liquibase
--driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
--classpath=./_jdbc/sqljdbc_7.2/enu/mssql-jdbc-7.2.0.jre8.jar
--changeLogFile=./liquibase_testing/resources/migrations.xml
--url="jdbc:sqlserver://myDbServer;database=liquibase_testing"
--username=liquibase_testing
--password=password
--logLevel=debug
migrate
И я получаю эту ошибку:
Starting Liquibase at Thu, 14 Feb 2019 12:54:52 EST (version 3.6.3 built at 2019-01-29 11:34:48)
Unexpected error running Liquibase: There is already an object named 'names' in the database. [Failed SQL: CREATE TABLE dbo.names (
name_id int identity,
first_name nvarchar(100),
last_name nvarchar(100),
primary key clustered (name_id)
)]
liquibase.exception.MigrationFailedException: Migration failed for change set liquibase_testing/resources/migrations/001-liquibase-testing-create-names-table.sql::raw::includeAll:
Reason: liquibase.exception.DatabaseException: There is already an object named 'names' in the database. [Failed SQL: CREATE TABLE dbo.names (
name_id int identity,
first_name nvarchar(100),
last_name nvarchar(100),
primary key clustered (name_id)
)]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:637)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83)
at liquibase.Liquibase.update(Liquibase.java:202)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.integration.commandline.Main.doMigration(Main.java:1220)
at liquibase.integration.commandline.Main.run(Main.java:199)
at liquibase.integration.commandline.Main.main(Main.java:137)
Caused by: liquibase.exception.DatabaseException: There is already an object named 'names' in the database. [Failed SQL: CREATE TABLE dbo.names (
name_id int identity,
first_name nvarchar(100),
last_name nvarchar(100),
primary key clustered (name_id)
)]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:356)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:57)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:125)
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1229)
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1211)
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:600)
... 7 common frames omitted
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: There is already an object named 'names' in the database.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:256)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1621)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:868)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:768)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2930)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:744)
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:352)
... 12 common frames omitted
For more information, please use the --logLevel flag
Итак, таблица names
создается, но затемпо какой-то причине Liquibase пытается создать его во второй раз и терпит неудачу.Я запустил трассировку профилировщика в базе данных и вижу 2 CREATE TABLE
вызовов.