-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from adangel:index-prefix
Support createIndex with specifying index prefix length (#148) #157 * index-prefix: Verify that index prefix length works also without liquibase-percona Support createIndex with specifying index prefix length (#148)
- Loading branch information
Showing
8 changed files
with
209 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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-createIndexPrefix</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.xml</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>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> |
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,31 @@ | ||
/* | ||
* Licensed 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. | ||
*/ | ||
|
||
def con, s; | ||
try { | ||
def props = new Properties(); | ||
props.setProperty("user", config_user) | ||
props.setProperty("password", config_password) | ||
con = new com.mysql.cj.jdbc.Driver().connect("jdbc:mysql://${config_host}:${config_port}?useSSL=false&allowPublicKeyRetrieval=true", 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 |
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,22 @@ | ||
<?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-4.2.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"> | ||
<createIndex indexName="emailIdx" tableName="person" unique="true"> | ||
<column name="email(10)"/> | ||
</createIndex> | ||
</changeSet> | ||
</databaseChangeLog> |
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,70 @@ | ||
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("Executing: pt-online-schema-change --alter-foreign-keys-method=auto --nocheck-unique-key-change --alter=\"ADD UNIQUE INDEX emailIdx (email(10))\" --password=*** --execute h=${config_host},P=${config_port},u=${config_user},D=testdb,t=person") | ||
assert buildLogText.contains("Altering `testdb`.`person`...") | ||
assert buildLogText.contains("Successfully altered `testdb`.`person`.") | ||
assert buildLogText.contains("Index emailIdx created") | ||
assert buildLogText.contains("ChangeSet test-changelog.xml::2::Alice ran successfully") | ||
|
||
File sql = new File( basedir, 'target/liquibase/migrate.sql' ) | ||
assert sql.exists() | ||
def sqlText = sql.text; | ||
assert sqlText.contains("pt-online-schema-change --alter-foreign-keys-method=auto --nocheck-unique-key-change --alter=\"ADD UNIQUE INDEX emailIdx (email(10))\"") | ||
assert !sqlText.contains("password=${config_password}") | ||
|
||
// Verify that index prefix length works also without liquibase-percona | ||
// See also https://github.com/liquibase/liquibase/issues/2191 | ||
assert sqlText.contains("CREATE UNIQUE INDEX emailIdx ON person(email(10));") | ||
|
||
def con, s; | ||
try { | ||
def props = new Properties(); | ||
props.setProperty("user", config_user) | ||
props.setProperty("password", config_password) | ||
con = new com.mysql.cj.jdbc.Driver().connect("jdbc:mysql://${config_host}:${config_port}/${config_dbname}?useSSL=false&allowPublicKeyRetrieval=true", props) | ||
s = con.createStatement(); | ||
r = s.executeQuery("SHOW INDEX FROM person") | ||
assert r.next() | ||
assert r.next() // we need the second row | ||
assertColumn(r, true, "emailIdx", "email", 10) | ||
r.close() | ||
} finally { | ||
s?.close(); | ||
con?.close(); | ||
} | ||
|
||
def assertColumn(resultset, unique, keyName, columnName, subPart) { | ||
assert keyName == resultset.getString(3) | ||
|
||
if (unique) { | ||
assert 0 == resultset.getInt(2) | ||
} else { | ||
assert 1 == resultset.getInt(2) | ||
} | ||
|
||
assert subPart == resultset.getInt(8); | ||
|
||
assert columnName == resultset.getString(5); | ||
} |
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