mysql – 如果存在表,则dropwizard hibernate liquibase迁移失败

我在我的本地数据库上运行了一个迁移,它运行良好.我正在使用另一个.yml文件用于同一模式的另一个数据库,但失败并显示错误

! com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'myTable' already exists

我怎样才能做到这一点?

liquibase包装器是否适用于mysql架构?我能够使用此文档http://www.dropwizard.io/0.7.1/docs/manual/migrations.html转储迁移

这是migrations.xml文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet author="(generated)" id="1501263805585-1">
        <createTable catalogName="deployer" schemaName="deployer" tableName="AuthData">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-2">
        <createTable catalogName="deployer" schemaName="deployer" tableName="DeployStatus">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="message" type="VARCHAR(255)"/>
            <column name="statusDate" type="VARCHAR(255)"/>
            <column name="statusType" type="VARCHAR(255)"/>
            <column name="deploy_id" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-3">
        <createTable catalogName="deployer" schemaName="deployer" tableName="Service">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="applicationData" type="VARCHAR(255)"/>
            <column name="artifactID" type="VARCHAR(255)"/>
            <column name="deployStatus" type="INT"/>
            <column name="deployedFrom" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="diskBytes" type="BIGINT"/>
            <column name="env" type="VARCHAR(255)"/>
            <column name="executionLevel" type="INT"/>
            <column name="groupID" type="VARCHAR(255)"/>
            <column name="imageTag" type="VARCHAR(255)"/>
            <column name="item" type="INT"/>
            <column name="jobFqn" type="VARCHAR(255)"/>
            <column name="jobStatus" type="INT"/>
            <column name="jobUUID" type="VARCHAR(255)"/>
            <column name="memBytes" type="BIGINT"/>
            <column name="namespace" type="VARCHAR(255)"/>
            <column name="numInstances" type="INT">
                <constraints nullable="false"/>
            </column>
            <column name="requestStatus" type="INT"/>
            <column name="taskID" type="VARCHAR(255)"/>
            <column name="version" type="VARCHAR(255)"/>
            <column name="environment_id" type="BIGINT"/>
            <column name="networkServiceConfig_id" type="BIGINT"/>
            <column name="userRequest_id" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-4">
        <createTable catalogName="deployer" schemaName="deployer" tableName="ServiceAppStatus">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="deployEnded" type="VARCHAR(255)"/>
            <column name="deployStarted" type="VARCHAR(255)"/>
            <column name="requestReceived" type="VARCHAR(255)"/>
            <column name="statusType" type="INT"/>
            <column name="undeployEnded" type="VARCHAR(255)"/>
            <column name="undeployStarted" type="VARCHAR(255)"/>
            <column name="service_id" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-5">
        <createTable catalogName="deployer" schemaName="deployer" tableName="ServiceDeploy">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="artifactId" type="VARCHAR(255)"/>
            <column name="deploymentArtifacts" type="VARCHAR(255)"/>
            <column name="executionLevel" type="INT"/>
            <column name="groupId" type="VARCHAR(255)"/>
            <column name="item" type="INT"/>
            <column name="serviceTag" type="VARCHAR(255)"/>
            <column name="url" type="VARCHAR(255)"/>
            <column name="versionId" type="VARCHAR(255)"/>
            <column name="deploy_id" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-6">
        <createTable catalogName="deployer" schemaName="deployer" tableName="ServiceDeploy_dependentIds">
            <column name="ServiceDeploy_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="dependentIds" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="spalshik (generated)" id="1501263805585-7">
        <createTable catalogName="deployer" schemaName="deployer" tableName="ServiceRoutes_routes">
            <column name="ServiceRoutes_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="routes" type="VARCHAR(255)"/>
            <column name="routes_KEY" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-8">
        <createTable catalogName="deployer" schemaName="deployer" tableName="ServiceStatus">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="message" type="VARCHAR(255)"/>
            <column name="statusDate" type="VARCHAR(255)"/>
            <column name="statusType" type="INT"/>
            <column name="serviceDeploy_id" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-9">
        <createTable catalogName="deployer" schemaName="deployer" tableName="Service_dependentIds">
            <column name="Service_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="dependentIds" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-10">
        <createTable catalogName="deployer" schemaName="deployer" tableName="Service_endPoints">
            <column name="Service_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="endPoints" type="VARCHAR(255)"/>
            <column name="endPoints_KEY" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-11">
        <createTable catalogName="deployer" schemaName="deployer" tableName="UserData">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-12">
        <createTable catalogName="deployer" schemaName="deployer" tableName="UserRequestStatus">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="ended" type="VARCHAR(255)"/>
            <column name="received" type="VARCHAR(255)"/>
            <column name="started" type="VARCHAR(255)"/>
            <column name="statusType" type="VARCHAR(255)"/>
            <column name="userRequest_id" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-13">
        <createTable catalogName="deployer" schemaName="deployer" tableName="deployer">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="started" type="datetime"/>
            <column name="status" type="VARCHAR(255)"/>
            <column name="version" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-14">
        <createTable catalogName="deployer" schemaName="deployer" tableName="deploys">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="callerId" type="VARCHAR(255)"/>
            <column name="context" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-15">
        <createTable catalogName="deployer" schemaName="deployer" tableName="ephemeralEnvironments">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="environmentType" type="INT"/>
            <column name="name" type="VARCHAR(255)"/>
            <column name="requestStatus" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-16">
        <createTable catalogName="deployer" schemaName="deployer" tableName="networkServiceConfig">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="endpoint" type="VARCHAR(255)"/>
            <column name="host" type="VARCHAR(255)"/>
            <column name="port" type="INT">
                <constraints nullable="false"/>
            </column>
            <column name="url" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="spalshik (generated)" id="1501263805585-17">
        <createTable catalogName="deployer" schemaName="deployer" tableName="routes">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="apceraInternalAdminRoute" type="VARCHAR(255)"/>
            <column name="apceraInternalRoute" type="VARCHAR(255)"/>
            <column name="mwRoute" type="VARCHAR(255)"/>
            <column name="paasRoute" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-18">
        <createTable catalogName="deployer" schemaName="deployer" tableName="serviceRoutes">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="name" type="VARCHAR(255)"/>
            <column name="port" type="INT">
                <constraints nullable="false"/>
            </column>
            <column name="service_id" type="BIGINT"/>
            <column name="serviceRoutes_id" type="BIGINT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-19">
        <createTable catalogName="deployer" schemaName="deployer" tableName="userRequest">
            <column name="userRequest_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-20">
        <createTable catalogName="deployer" schemaName="deployer" tableName="userRequests">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="authData" type="TINYBLOB"/>
            <column name="environment_id" type="BIGINT"/>
            <column name="namespace" type="VARCHAR(255)"/>
            <column name="requestReceived" type="VARCHAR(255)"/>
            <column name="sentFromHost" type="VARCHAR(255)"/>
            <column name="userRequestPath" type="VARCHAR(255)"/>
            <column name="userRequestStatus" type="INT"/>
        </createTable>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-21">
        <addPrimaryKey catalogName="deployer" columnNames="ServiceRoutes_id, routes_KEY" constraintName="PRIMARY" schemaName="deployer" tableName="ServiceRoutes_routes"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-22">
        <addPrimaryKey catalogName="deployer" columnNames="Service_id, endPoints_KEY" constraintName="PRIMARY" schemaName="deployer" tableName="Service_endPoints"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-23">
        <addPrimaryKey catalogName="deployer" columnNames="userRequest_id" constraintName="PRIMARY" schemaName="deployer" tableName="userRequest"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-24">
        <addForeignKeyConstraint baseColumnNames="service_id" baseTableCatalogName="deployer" baseTableName="serviceRoutes" baseTableSchemaName="deployer" constraintName="FK_3ktuugpv4fggfyewoh2g2ychb" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="Service" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-25">
        <addForeignKeyConstraint baseColumnNames="Service_id" baseTableCatalogName="deployer" baseTableName="Service_endPoints" baseTableSchemaName="deployer" constraintName="FK_42dx83vof8wtbh7t0qnqv0o4n" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="Service" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-26">
        <addForeignKeyConstraint baseColumnNames="service_id" baseTableCatalogName="deployer" baseTableName="ServiceAppStatus" baseTableSchemaName="deployer" constraintName="FK_5qyc3fk6i1p75c6y6bshgqf4r" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="Service" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-27">
        <addForeignKeyConstraint baseColumnNames="userRequest_id" baseTableCatalogName="deployer" baseTableName="UserRequestStatus" baseTableSchemaName="deployer" constraintName="FK_5tjecs7hj3m7us8hsn98trj1h" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="userRequests" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-28">
        <addForeignKeyConstraint baseColumnNames="ServiceRoutes_id" baseTableCatalogName="deployer" baseTableName="ServiceRoutes_routes" baseTableSchemaName="deployer" constraintName="FK_9u9qpnbb2n5yqmj94winl2yd5" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="serviceRoutes" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-29">
        <addForeignKeyConstraint baseColumnNames="deploy_id" baseTableCatalogName="deployer" baseTableName="DeployStatus" baseTableSchemaName="deployer" constraintName="FK_9x0gysgvns0gdfi092q1qe73j" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="deploys" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-30">
        <addForeignKeyConstraint baseColumnNames="networkServiceConfig_id" baseTableCatalogName="deployer" baseTableName="Service" baseTableSchemaName="deployer" constraintName="FK_b63wbyv84yy825er8lt6h6eij" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="networkServiceConfig" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-31">
        <addForeignKeyConstraint baseColumnNames="environment_id" baseTableCatalogName="deployer" baseTableName="Service" baseTableSchemaName="deployer" constraintName="FK_hn3ubyorvnaiio8opayvwud88" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="ephemeralEnvironments" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-32">
        <addForeignKeyConstraint baseColumnNames="ServiceDeploy_id" baseTableCatalogName="deployer" baseTableName="ServiceDeploy_dependentIds" baseTableSchemaName="deployer" constraintName="FK_imf7a562xiqh41nh0kmfxs22k" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="ServiceDeploy" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-33">
        <addForeignKeyConstraint baseColumnNames="Service_id" baseTableCatalogName="deployer" baseTableName="Service_dependentIds" baseTableSchemaName="deployer" constraintName="FK_ncklvx0g74ul9b81kp63qbx1c" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="Service" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-34">
        <addForeignKeyConstraint baseColumnNames="deploy_id" baseTableCatalogName="deployer" baseTableName="ServiceDeploy" baseTableSchemaName="deployer" constraintName="FK_qf43uf6tcqqsat39vx9g6uggl" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="deploys" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-35">
        <addForeignKeyConstraint baseColumnNames="userRequest_id" baseTableCatalogName="deployer" baseTableName="userRequest" baseTableSchemaName="deployer" constraintName="FK_quovo4p0lawd4rkt2xmwtb44e" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="Service" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-36">
        <addForeignKeyConstraint baseColumnNames="serviceRoutes_id" baseTableCatalogName="deployer" baseTableName="serviceRoutes" baseTableSchemaName="deployer" constraintName="FK_quw469h9qpk2pjpyd7nis6jey" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="Service" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-37">
        <addForeignKeyConstraint baseColumnNames="environment_id" baseTableCatalogName="deployer" baseTableName="userRequests" baseTableSchemaName="deployer" constraintName="FK_rbe9okb4x1k77xluy1tibohw6" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="ephemeralEnvironments" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-38">
        <addForeignKeyConstraint baseColumnNames="userRequest_id" baseTableCatalogName="deployer" baseTableName="Service" baseTableSchemaName="deployer" constraintName="FK_rvx1c6um92vde9so5v3x9pkry" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="userRequests" referencedTableSchemaName="deployer"/>
    </changeSet>
    <changeSet author="(generated)" id="1501263805585-39">
        <addForeignKeyConstraint baseColumnNames="serviceDeploy_id" baseTableCatalogName="deployer" baseTableName="ServiceStatus" baseTableSchemaName="deployer" constraintName="FK_tfv2a1us83fj83cgks8ye5eqi" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="deployer" referencedTableName="ServiceDeploy" referencedTableSchemaName="deployer"/>
    </changeSet>
</databaseChangeLog>

如何使用dropwizard liquibase命令行生成更改日志

然后,如何运行迁移以仅迁移先前架构中的更改,以便我看不到“表已存在”错误?

每次我对Entity对象进行更改时,changelog创建都是手动进程吗?或者,当我使用doc中的’db migrate’命令时,dropwizard包装器是否识别所做的更改并更新它们?

解决方法:

添加如下的前置条件

<preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="Your_Table_Name"/>
            </not>
        </preConditions>     

例如

 <changeSet author="(generated)" id="1501263805585-5">  
 <preConditions onFail="MARK_RAN">
                <not>
                    <tableExists tableName="ServiceDeploy"/>
                </not>
            </preConditions>  
        <createTable catalogName="deployer" schemaName="deployer" tableName="ServiceDeploy">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="artifactId" type="VARCHAR(255)"/>
            <column name="deploymentArtifacts" type="VARCHAR(255)"/>
            <column name="executionLevel" type="INT"/>
            <column name="groupId" type="VARCHAR(255)"/>
            <column name="item" type="INT"/>
            <column name="serviceTag" type="VARCHAR(255)"/>
            <column name="url" type="VARCHAR(255)"/>
            <column name="versionId" type="VARCHAR(255)"/>
            <column name="deploy_id" type="BIGINT"/>
        </createTable>
    </changeSet>     
上一篇:java – 使用List of List值解析Yaml时的Jackson异常


下一篇:mysql – Dropwizard Hibernate配置