Skip to content

Commit

Permalink
Switch back to mysql connector 5.1.x, so that the integration
Browse files Browse the repository at this point in the history
tests run with java7, too.
Add additional test for mysql connection 6.x, which only runs
on java8.
References #10
  • Loading branch information
adangel committed Dec 17, 2016
1 parent 7383283 commit f097a31
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ integration test.
* Support for MySQL Connector 6.0.x in addition to 5.1.x.
* Fixed [#7](https://github.com/adangel/liquibase-percona/issues/7): Foreign key constraints of AddColumn is ignored
* Fixed [#8](https://github.com/adangel/liquibase-percona/issues/8): Support addForeignKeyConstraintChange, addUniqueConstraintChange
* Fixed [#10](https://github.com/adangel/liquibase-percona/issues/10): Build fails with java7: UnsupportedClassVersion when running DatabaseConnectionUtilTest.testGetPasswordMySQL\_6\_0\_4
* Fixed [#10](https://github.com/adangel/liquibase-percona/issues/10): Build fails with java7: UnsupportedClassVersion when running DatabaseConnectionUtilTest.testGetPasswordMySQL\_6

### Version 1.2.1 (2016-09-13)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<liquibase.version>3.5.1</liquibase.version>
<mysql.version>6.0.4</mysql.version>
<mysql.version>5.1.40</mysql.version>

<config_host>127.0.0.1</config_host>
<!--
Expand Down
5 changes: 5 additions & 0 deletions src/it/allChangesLiquibase35MySQL6/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#
# MySQL Connection 6 requires java8
#
invoker.java.version = 1.8+
64 changes: 64 additions & 0 deletions src/it/allChangesLiquibase35MySQL6/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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>@project.groupId@.it</groupId>
<artifactId>liquibase-percona-it-allChangesLiquibase35MySQL6</artifactId>
<description>Using a new mysql connector</description>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>

<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.1</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>6.0.5</version>
</dependency>
</dependencies>
<configuration>
<changeLogFile>test-changelog.xml</changeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://@config_host@:@config_port@/@config_dbname@</url>
<username>@config_user@</username>
<password>@config_password@</password>
</configuration>
<executions>
<execution>
<id>updateSQL</id>
<phase>pre-integration-test</phase>
<goals>
<goal>updateSQL</goal>
</goals>
</execution>
<execution>
<id>update</id>
<phase>pre-integration-test</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
17 changes: 17 additions & 0 deletions src/it/allChangesLiquibase35MySQL6/setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def con, s;
try {
def props = new Properties();
props.setProperty("user", config_user)
props.setProperty("password", config_password)
con = new com.mysql.jdbc.Driver().connect("jdbc:mysql://${config_host}:${config_port}", props)
s = con.createStatement();
s.execute("DROP DATABASE IF EXISTS `${config_dbname}`")
s.execute("CREATE DATABASE `${config_dbname}`")
} finally {
s?.close();
con?.close();
}

println "Prepared empty database `${config_dbname}`"

return true
60 changes: 60 additions & 0 deletions src/it/allChangesLiquibase35MySQL6/test-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

<changeSet id="1" author="Alice">
<createTable tableName="person">
<column name="name" type="varchar(255)">
<constraints primaryKey="true"/>
</column>
<column name="email" type="varchar(255)"/>
</createTable>
</changeSet>

<changeSet id="2" author="Alice">
<addColumn tableName="person">
<column name="age" type="int"/>
</addColumn>
</changeSet>

<changeSet id="3" author="Alice">
<dropColumn tableName="person" columnName="age"/>
</changeSet>

<changeSet id="4" author="Alice">
<createIndex indexName="emailIdx" tableName="person" unique="true">
<column name="email"/>
</createIndex>
</changeSet>

<changeSet id="5" author="Alice">
<dropIndex indexName="emailIdx" tableName="person"/>
</changeSet>

<changeSet id="6" author="Alice">
<modifyDataType tableName="person" columnName="email" newDataType="VARCHAR(400)"/>
</changeSet>

<changeSet id="7" author="Alice">
<createTable tableName="address">
<column name="id" type="varchar(255)">
<constraints primaryKey="true"/>
</column>
<column name="person_id" type="varchar(255)"/>
<column name="street" type="varchar(255)"/>
</createTable>
</changeSet>

<changeSet id="8" author="Alice">
<addForeignKeyConstraint constraintName="fk_person_address"
referencedTableName="person" referencedColumnNames="name"
baseTableName="address" baseColumnNames="person_id"/>
</changeSet>

<changeSet id="9" author="Alice">
<dropForeignKeyConstraint baseTableName="address" constraintName="fk_person_address" />
</changeSet>
</databaseChangeLog>
44 changes: 44 additions & 0 deletions src/it/allChangesLiquibase35MySQL6/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.sql.ResultSet;


/*
* 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;
assert buildLogText.contains("liquibase: test-changelog.xml: test-changelog.xml::2::Alice: Executing: pt-online-schema-change --alter=\"ADD COLUMN age INT NULL\" --alter-foreign-keys-method=auto --host=${config_host} --port=${config_port} --user=${config_user} --password=*** --execute D=testdb,t=person")
assert buildLogText.contains("liquibase: test-changelog.xml: test-changelog.xml::3::Alice: Executing: pt-online-schema-change --alter=\"DROP COLUMN age\"")
assert buildLogText.contains("liquibase: test-changelog.xml: test-changelog.xml::4::Alice: Executing: pt-online-schema-change --alter=\"ADD UNIQUE INDEX emailIdx (email)\"")
assert buildLogText.contains("liquibase: test-changelog.xml: test-changelog.xml::5::Alice: Executing: pt-online-schema-change --alter=\"DROP INDEX emailIdx\"")
assert buildLogText.contains("liquibase: test-changelog.xml: test-changelog.xml::6::Alice: Executing: pt-online-schema-change --alter=\"MODIFY email VARCHAR(400)\"")
assert buildLogText.contains("liquibase: test-changelog.xml: test-changelog.xml::8::Alice: Executing: pt-online-schema-change --alter=\"ADD CONSTRAINT fk_person_address FOREIGN KEY (person_id) REFERENCES person (name)\"")
assert buildLogText.contains("liquibase: test-changelog.xml: test-changelog.xml::9::Alice: Executing: pt-online-schema-change --alter=\"DROP FOREIGN KEY _fk_person_address\"")

File sql = new File( basedir, 'target/liquibase/migrate.sql' )
assert sql.exists()
def sqlText = sql.text;
assert sqlText.contains("pt-online-schema-change --alter=\"ADD COLUMN age INT NULL\"")
assert sqlText.contains("pt-online-schema-change --alter=\"DROP COLUMN age\"")
assert sqlText.contains("pt-online-schema-change --alter=\"ADD UNIQUE INDEX emailIdx (email)\"")
assert sqlText.contains("pt-online-schema-change --alter=\"DROP INDEX emailIdx\"")
assert sqlText.contains("pt-online-schema-change --alter=\"MODIFY email VARCHAR(400)\"")
assert sqlText.contains("pt-online-schema-change --alter=\"ADD CONSTRAINT fk_person_address FOREIGN KEY (person_id) REFERENCES person (name)\"")
assert sqlText.contains("pt-online-schema-change --alter=\"DROP FOREIGN KEY _fk_person_address\"")
assert !sqlText.contains("password=${config_password}")
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static Class<?> loadClass(String name) {
}

@Test
public void testGetPasswordMySQL_5_1_38() throws Exception {
public void testGetPasswordMySQL_5_1() throws Exception {
// with MySQL Connector 5.1.38, we use JDBC4Connection and its superclass ConnectionImpl
// to get hold of the password.
Class<?> connectionImpl = loadClass("com.mysql.jdbc.ConnectionImpl");
Expand All @@ -78,7 +78,7 @@ public void testGetPasswordMySQL_5_1_38() throws Exception {
}

@Test
public void testGetPasswordMySQL_6_0_4() throws Exception {
public void testGetPasswordMySQL_6() throws Exception {
assumeJava8();
// with MySQL Connector 6.0.4, the packages changed.
Class<?> connectionImpl = loadClass("com.mysql.cj.jdbc.ConnectionImpl");
Expand Down

0 comments on commit f097a31

Please sign in to comment.