forked from liquibase/liquibase-percona
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support rollback for formatted SQL changelogs
Fixes liquibase#361
- Loading branch information
Showing
6 changed files
with
181 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under | ||
the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may | ||
obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to | ||
in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under | ||
the License. --> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>@[email protected]</groupId> | ||
<artifactId>liquibase-percona-it-addColumnWithRollbackSqlChangelog</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>my-app</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.liquibase</groupId> | ||
<artifactId>liquibase-maven-plugin</artifactId> | ||
<version>@liquibase.version@</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>@mysql.version@</version> | ||
</dependency> | ||
</dependencies> | ||
<configuration> | ||
<changeLogFile>test-changelog.sql</changeLogFile> | ||
<driver>com.mysql.jdbc.Driver</driver> | ||
<url>jdbc:mysql://@config_host@:@config_port@/@config_dbname@?useSSL=false&allowPublicKeyRetrieval=true</url> | ||
<username>@config_user@</username> | ||
<password>@config_password@</password> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>update</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>update</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>rollbackSQL</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>rollbackSQL</goal> | ||
</goals> | ||
<configuration> | ||
<rollbackCount>3</rollbackCount> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>rollback</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>rollback</goal> | ||
</goals> | ||
<configuration> | ||
<rollbackCount>3</rollbackCount> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
14 changes: 14 additions & 0 deletions
14
src/it/addColumnWithRollbackSqlChangelog/test-changelog.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--liquibase formatted sql | ||
|
||
--changeset Alice:1 | ||
--rollback DROP TABLE person; | ||
CREATE TABLE person (name VARCHAR(255) NOT NULL, CONSTRAINT PK_PERSON PRIMARY KEY (name)); | ||
|
||
--changeset Alice:2 | ||
--rollback ALTER TABLE person DROP COLUMN address; | ||
ALTER TABLE person ADD address VARCHAR(255) NULL; | ||
|
||
--changeset Alice:3 | ||
--liquibasePercona:usePercona="false" | ||
--rollback ALTER TABLE person DROP COLUMN email; | ||
ALTER TABLE person ADD email VARCHAR(255) NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
File buildLog = new File( basedir, 'build.log' ) | ||
assert buildLog.exists() | ||
def buildLogText = buildLog.text; | ||
|
||
// changeset 3: email has usePercona="false" | ||
assert buildLogText.contains("Rolling Back Changeset: test-changelog.sql::3::Alice") | ||
assert !buildLogText.contains("Executing: pt-online-schema-change --alter-foreign-keys-method=auto --nocheck-unique-key-change --alter=\"DROP COLUMN email\" --password=*** --execute h=${config_host},P=${config_port},u=${config_user},D=testdb,t=person"); | ||
// changeset 2: address | ||
assert buildLogText.contains("Rolling Back Changeset: test-changelog.sql::2::Alice") | ||
assert buildLogText.contains("Executing: pt-online-schema-change --alter-foreign-keys-method=auto --nocheck-unique-key-change --alter=\"DROP COLUMN address\" --password=*** --execute h=${config_host},P=${config_port},u=${config_user},D=testdb,t=person"); | ||
// changeset 1: table | ||
assert buildLogText.contains("Rolling Back Changeset: test-changelog.sql::1::Alice") | ||
|
||
|
||
File sql = new File( basedir, 'target/liquibase/migrate.sql' ) | ||
assert sql.exists() | ||
def sqlText = sql.text; | ||
assert sqlText.contains("pt-online-schema-change") | ||
// changeset 3: email has usePercona="false" | ||
assert !sqlText.contains("-- pt-online-schema-change --alter-foreign-keys-method=auto --nocheck-unique-key-change --alter=\"DROP COLUMN email\" --password=*** --execute h=${config_host},P=${config_port},u=${config_user},D=testdb,t=person;"); | ||
// changeset 2: address | ||
assert sqlText.contains("-- pt-online-schema-change --alter-foreign-keys-method=auto --nocheck-unique-key-change --alter=\"DROP COLUMN address\" --password=*** --execute h=${config_host},P=${config_port},u=${config_user},D=testdb,t=person;"); | ||
assert !sqlText.contains("password=${config_password}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/test/resources/liquibase/ext/percona/changelog/test-changelog.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
--liquibase formatted sql | ||
|
||
--changeset Alice:1 | ||
--rollback DROP TABLE person; | ||
CREATE TABLE person (name VARCHAR(255) NOT NULL, CONSTRAINT PK_PERSON PRIMARY KEY (name)); | ||
|
||
--changeset Alice:2 | ||
--liquibasePercona:usePercona="false" | ||
--rollback ALTER TABLE person DROP COLUMN address; | ||
ALTER TABLE person ADD address VARCHAR(255) NULL; | ||
|
||
--changeset Alice:3 | ||
-- liquibasePercona:perconaOptions="--foo" | ||
--rollback ALTER TABLE person DROP COLUMN email; | ||
ALTER TABLE person ADD email VARCHAR(255) NULL; |