Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes for MySQL integration tests.

Override quoting of object names by setting quoting characters as empty strings.
Removed incorrect correctObjectName code in MySqlDatabase.
Updated test AddNotNullConstraints with default null values.
  • Loading branch information...
commit b8843a72f083a7a000cebe4ea7abc50becb1d41c 1 parent ed1f13b
@damienbiggs damienbiggs authored
View
10 liquibase-core/src/main/java/liquibase/database/AbstractJdbcDatabase.java
@@ -65,7 +65,8 @@
*/
protected String sequenceNextValueFunction;
protected String sequenceCurrentValueFunction;
- protected String quotingCharacter = "\"";
+ protected String quotingStartCharacter = "\"";
+ protected String quotingEndCharacter = "\"";
// List of Database native functions.
protected List<DatabaseFunction> dateFunctions = new ArrayList<DatabaseFunction>();
@@ -276,7 +277,8 @@ public CatalogAndSchema correctSchema(CatalogAndSchema schema) {
public String correctObjectName(String objectName, Class<? extends DatabaseObject> objectType) {
if (quotingStrategy == ObjectQuotingStrategy.QUOTE_ALL_OBJECTS || unquotedObjectsAreUppercased == null
- || objectName == null || (objectName.startsWith(quotingCharacter) && objectName.endsWith(quotingCharacter))) {
+ || objectName == null || (objectName.startsWith(quotingStartCharacter) && objectName.endsWith(
+ quotingEndCharacter))) {
return objectName;
} else if (unquotedObjectsAreUppercased == Boolean.TRUE) {
return objectName.toUpperCase();
@@ -979,9 +981,9 @@ public String escapeObjectName(String objectName, Class<? extends DatabaseObject
if (objectName == null || quotingStrategy == ObjectQuotingStrategy.LEGACY) {
return objectName;
} else if (objectName.contains("-") || startsWithNumeric(objectName) || isReservedWord(objectName)) {
- return quotingCharacter + objectName + quotingCharacter;
+ return quotingStartCharacter + objectName + quotingEndCharacter;
} else if (quotingStrategy == ObjectQuotingStrategy.QUOTE_ALL_OBJECTS) {
- return quotingCharacter + objectName + quotingCharacter;
+ return quotingStartCharacter + objectName + quotingEndCharacter;
}
return objectName;
}
View
8 liquibase-core/src/main/java/liquibase/database/core/MySQLDatabase.java
@@ -20,6 +20,9 @@
public MySQLDatabase() {
super.setCurrentDateTimeFunction("NOW()");
+ // objects in mysql are always case sensitive
+ super.quotingStartCharacter ="";
+ super.quotingEndCharacter="";
}
public String getShortName() {
@@ -37,10 +40,7 @@ public String correctObjectName(String name, Class<? extends DatabaseObject> obj
if (objectType.equals(PrimaryKey.class) && name.equals("PRIMARY")) {
return null;
} else {
- if (name == null) {
- return null;
- }
- return name.toLowerCase(); //todo: handle case sensitive
+ return super.correctObjectName(name, objectType);
}
}
View
26 ...-core/src/main/java/liquibase/diff/output/changelog/core/MissingTableChangeGenerator.java
@@ -5,13 +5,14 @@
import liquibase.change.ConstraintsConfig;
import liquibase.change.core.CreateTableChange;
import liquibase.database.Database;
-import liquibase.diff.compare.DatabaseObjectComparatorFactory;
+import liquibase.database.core.MySQLDatabase;
import liquibase.diff.output.DiffOutputControl;
import liquibase.diff.output.changelog.ChangeGeneratorChain;
import liquibase.diff.output.changelog.MissingObjectChangeGenerator;
import liquibase.statement.DatabaseFunction;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Column;
+import liquibase.structure.core.PrimaryKey;
import liquibase.structure.core.Table;
import java.util.Date;
@@ -35,6 +36,8 @@ public int getPriority(Class<? extends DatabaseObject> objectType, Database data
public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
Table missingTable = (Table) missingObject;
+ PrimaryKey primaryKey = missingTable.getPrimaryKey();
+
// if (control.diffResult.getReferenceSnapshot().getDatabase().isLiquibaseTable(missingTable.getSchema().toCatalogAndSchema(), missingTable.getName())) {
// continue;
// }
@@ -56,19 +59,28 @@ public int getPriority(Class<? extends DatabaseObject> objectType, Database data
columnConfig.setName(column.getName());
columnConfig.setType(column.getType().toString());
- ConstraintsConfig constraintsConfig = null;
-
if (column.isAutoIncrement()) {
columnConfig.setAutoIncrement(true);
}
- if (column.isNullable() != null && !column.isNullable()) {
- if (constraintsConfig == null) {
- constraintsConfig = new ConstraintsConfig();
+ ConstraintsConfig constraintsConfig = null;
+ // In MySQL, the primary key must be specified at creation for an autoincrement column
+ if (column.isAutoIncrement() && primaryKey != null && primaryKey.getColumnNamesAsList().contains(column.getName())) {
+ constraintsConfig = new ConstraintsConfig();
+ constraintsConfig.setPrimaryKey(true);
+ constraintsConfig.setPrimaryKeyTablespace(primaryKey.getTablespace());
+ // MySQL sets some primary key names as PRIMARY which is invalid
+ if (comparisonDatabase instanceof MySQLDatabase && "PRIMARY".equals(primaryKey.getName())) {
+ constraintsConfig.setPrimaryKeyName(null);
+ } else {
+ constraintsConfig.setPrimaryKeyName(primaryKey.getName());
}
-
+ control.setAlreadyHandledMissing(primaryKey);
+ } else if (column.isNullable() != null && !column.isNullable()) {
+ constraintsConfig = new ConstraintsConfig();
constraintsConfig.setNullable(false);
}
+
// if (column.isUnique()) {
// if (constraintsConfig == null) {
// constraintsConfig = new ConstraintsConfig();
View
4 liquibase-integration-tests/src/test/resources/changelogs/common/common.tests.changelog.xml
@@ -149,7 +149,7 @@
</changeSet>
<changeSet id="nullable-1" author="nvoxland">
- <addNotNullConstraint tableName="compoundPKTest" columnName="name" columnDataType="varchar(255)"/>
+ <addNotNullConstraint tableName="compoundPKTest" columnName="name" columnDataType="varchar(255)" defaultNullValue="testValue"/>
</changeSet>
<changeSet id="nullable-2" author="nvoxland">
<dropNotNullConstraint tableName="compoundPKTest" columnName="name" columnDataType="varchar(255)"/>
@@ -317,7 +317,7 @@
</changeSet>
<changeSet id="makeNotnulltest" author="nvoxland">
- <addNotNullConstraint tableName="commonTypesTest" columnName="intColumn" columnDataType="int"/>
+ <addNotNullConstraint tableName="commonTypesTest" columnName="intColumn" columnDataType="int" defaultNullValue="0"/>
</changeSet>
<changeSet id="makenulltest" author="nvoxland">
View
23 ...egration-tests/src/test/resources/changelogs/common/object.quoting.strategy.changelog.xml
@@ -28,19 +28,28 @@
<column name="testId" type="int" />
</createTable>
- <sql>select "iD" from "mixedCase"</sql>
</changeSet>
- <changeSet id="4" author="dbiggs">
+ <changeSet id="4" author="dbiggs" dbms="oracle,h2,hsqldb,postgresql">
+ <comment>Verify databases that use quoting</comment>
+ <sql>select "iD" from "mixedCase"</sql>
+ </changeSet>
+
+ <changeSet id="5" author="dbiggs" dbms="mysql">
+ <comment>Verify mysql, everything is always case sensitive in mysql</comment>
+ <sql>select iD from mixedCase</sql>
+ </changeSet>
+
+ <changeSet id="6" author="dbiggs">
<createIndex tableName="mixedCase" indexName="testIndex">
<column name="testId"/>
</createIndex>
</changeSet>
- <changeSet id="5" author="dbiggs">
- <preConditions>
- <indexExists indexName="testIndex" />
- </preConditions>
- </changeSet>
+ <changeSet id="7" author="dbiggs">
+ <preConditions>
+ <indexExists indexName="testIndex" />
+ </preConditions>
+ </changeSet>
</databaseChangeLog>
View
2  liquibase-integration-tests/src/test/resources/changelogs/common/schema.tests.changelog.xml
@@ -153,7 +153,7 @@
</changeSet>
<changeSet id="25.1" author="nvoxland">
- <addNotNullConstraint schemaName="liquibaseb" tableName="address2" columnName="id" columnDataType="int"/>
+ <addNotNullConstraint schemaName="liquibaseb" tableName="address2" columnName="id" columnDataType="int" defaultNullValue="0"/>
</changeSet>
<changeSet id="25.2" author="nvoxland">
View
2  liquibase-integration-tests/src/test/resources/changelogs/mysql/complete/root.changelog.xml
@@ -200,7 +200,7 @@
</changeSet>
<changeSet id="25.1" author="nvoxland">
- <addNotNullConstraint tableName="address" columnName="id" columnDataType="int"/>
+ <addNotNullConstraint tableName="address" columnName="id" columnDataType="int" defaultNullValue="0"/>
</changeSet>
<changeSet id="25.2" author="nvoxland">
Please sign in to comment.
Something went wrong with that request. Please try again.