Skip to content

Commit

Permalink
Generated indexes are not including "desc"
Browse files Browse the repository at this point in the history
DAT-3773
  • Loading branch information
nvoxland committed Jan 3, 2020
1 parent edba083 commit 897a3ca
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
Expand Up @@ -15,10 +15,7 @@
import liquibase.structure.core.PrimaryKey;
import liquibase.structure.core.Table;
import liquibase.structure.core.UniqueConstraint;
import liquibase.util.ISODateFormat;
import liquibase.util.ObjectUtil;
import liquibase.util.StringUtils;
import liquibase.util.NowAndTodayUtil;
import liquibase.util.*;

import java.math.BigInteger;
import java.text.NumberFormat;
Expand Down Expand Up @@ -71,8 +68,8 @@ public class ColumnConfig extends AbstractLiquibaseSerializable {
*/
public ColumnConfig(Column columnSnapshot) {
setName(columnSnapshot.getName());
setComputed(((columnSnapshot.getComputed() != null) && columnSnapshot.getComputed()) ? Boolean.TRUE : null);
setDescending(((columnSnapshot.getDescending() != null) && columnSnapshot.getDescending()) ? Boolean.TRUE : null);
setComputed(BooleanUtils.isTrue(columnSnapshot.getComputed()) ? Boolean.TRUE : null);
setDescending(BooleanUtils.isTrue(columnSnapshot.getDescending()) ? Boolean.TRUE : null);
if (columnSnapshot.getType() != null) {
setType(columnSnapshot.getType().toString());
}
Expand Down
5 changes: 3 additions & 2 deletions liquibase-core/src/main/java/liquibase/diff/DiffResult.java
Expand Up @@ -9,6 +9,7 @@
import liquibase.structure.core.Catalog;
import liquibase.structure.core.Column;
import liquibase.structure.core.Schema;
import liquibase.util.BooleanUtils;

import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -95,7 +96,7 @@ public <T extends DatabaseObject> T getMissingObject(T example, CompareControl.S
}

public void addMissingObject(DatabaseObject obj) {
if ((obj instanceof Column) && (((Column) obj).getComputed() != null) && ((Column) obj).getComputed()) {
if ((obj instanceof Column) && (BooleanUtils.isTrue(((Column) obj).getComputed()) || BooleanUtils.isTrue(((Column) obj).getDescending()))) {
return; //not really missing, it's a virtual column
}
missingObjects.add(obj);
Expand Down Expand Up @@ -197,4 +198,4 @@ public boolean areEqual() throws DatabaseException, IOException {
public Set<Class<? extends DatabaseObject>> getComparedTypes() {
return compareControl.getComparedTypes();
}
}
}
Expand Up @@ -35,6 +35,9 @@ public String[] hash(DatabaseObject databaseObject, Database accordingTo, Databa
if (BooleanUtils.isTrue(column.getComputed())) {
hash += ":computed";
}
if (BooleanUtils.isTrue(column.getDescending())) {
hash += ":descending";
}
return new String[] {hash.toLowerCase(Locale.US)};
}

Expand All @@ -60,6 +63,10 @@ public boolean isSameObject(DatabaseObject databaseObject1, DatabaseObject datab
return false;
}

if (BooleanUtils.isTrue(thisColumn.getDescending()) != BooleanUtils.isTrue(otherColumn.getDescending())) {
return false;
}

return true;
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
import liquibase.diff.output.changelog.UnexpectedObjectChangeGenerator;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.*;
import liquibase.util.BooleanUtils;

public class UnexpectedColumnChangeGenerator extends AbstractChangeGenerator implements UnexpectedObjectChangeGenerator {
@Override
Expand Down Expand Up @@ -42,7 +43,7 @@ public Change[] fixUnexpected(DatabaseObject unexpectedObject, DiffOutputControl
// continue;
// }

if ((column.getComputed() != null) && column.getComputed()) { //not really a column to drop, probably part of an index or something
if (BooleanUtils.isTrue(column.getComputed()) || BooleanUtils.isTrue(column.getDescending()) ) { //not really a column to drop, probably part of an index or something
return null;
}
if (column.getRelation() instanceof View) {
Expand Down
Expand Up @@ -12,6 +12,8 @@
import liquibase.structure.DatabaseObject;
import liquibase.structure.DatabaseObjectCollection;
import liquibase.structure.DatabaseObjectComparator;
import liquibase.structure.core.Column;
import liquibase.util.BooleanUtils;
import liquibase.util.ISODateFormat;
import liquibase.util.StringUtils;
import org.yaml.snakeyaml.nodes.Node;
Expand Down Expand Up @@ -53,7 +55,10 @@ public void write(DatabaseSnapshot snapshot, OutputStream out) throws IOExceptio
@Override
protected Object toMap(final LiquibaseSerializable object) {
if (object instanceof DatabaseObject) {
if (alreadySerializingObject) {
if (object instanceof Column && (BooleanUtils.isTrue(((Column) object).getDescending()) || BooleanUtils.isTrue(((Column) object).getComputed()))) {
//not really a "real" column that has a snapshot to reference, just serialize it
return super.toMap(object);
} else if (alreadySerializingObject) {
String snapshotId = ((DatabaseObject) object).getSnapshotId();
if (snapshotId == null) {
String name = ((DatabaseObject) object).getName();
Expand Down
Expand Up @@ -20,6 +20,7 @@
import liquibase.structure.DatabaseObject;
import liquibase.structure.DatabaseObjectCollection;
import liquibase.structure.core.*;
import liquibase.util.BooleanUtils;
import liquibase.util.ISODateFormat;
import liquibase.util.ObjectUtil;
import liquibase.util.StringUtils;
Expand Down Expand Up @@ -356,7 +357,7 @@ private void includeNestedObjects(DatabaseObject object) throws DatabaseExceptio
if ((fieldValue != null) && !((Collection) fieldValue).isEmpty()) {
final Column column = (Column) ((Collection) fieldValue).iterator().next();
String columnName = column.getName();
if ((column.getDescending() != null && column.getDescending()) || columnName.endsWith(" ASC") || columnName.endsWith(" DESC") || columnName.endsWith(" RANDOM")) {
if (BooleanUtils.isTrue(column.getDescending()) || columnName.endsWith(" ASC") || columnName.endsWith(" DESC") || columnName.endsWith(" RANDOM")) {
continue;
}
}
Expand Down
Expand Up @@ -21,6 +21,7 @@
import liquibase.statement.core.RawSqlStatement;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.*;
import liquibase.util.BooleanUtils;
import liquibase.util.SqlUtil;
import liquibase.util.StringUtils;

Expand Down Expand Up @@ -51,7 +52,7 @@ public ColumnSnapshotGenerator() {

@Override
protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException {
if ((((Column) example).getComputed() != null) && ((Column) example).getComputed()) {
if (BooleanUtils.isTrue(((Column) example).getComputed()) || BooleanUtils.isTrue(((Column) example).getDescending())) {
return example;
}
Database database = snapshot.getDatabase();
Expand Down
12 changes: 12 additions & 0 deletions liquibase-core/src/main/java/liquibase/structure/core/Column.java
Expand Up @@ -8,11 +8,13 @@
import liquibase.serializer.AbstractLiquibaseSerializable;
import liquibase.structure.AbstractDatabaseObject;
import liquibase.structure.DatabaseObject;
import liquibase.util.BooleanUtils;
import liquibase.util.StringUtils;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class Column extends AbstractDatabaseObject {

Expand Down Expand Up @@ -456,5 +458,15 @@ public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throw
this.generationType = parsedNode.getChildValue(null, "generationType", String.class);
}
}

@Override
public Set<String> getSerializableFields() {
final Set<String> fields = super.getSerializableFields();
//if this is a computed or indexed column, don't have the serializer try to traverse down to the relation since it may not be a "real" object with an objectId
if (BooleanUtils.isTrue(getDescending()) || BooleanUtils.isTrue(getComputed())) {
fields.remove("relation");
}
return fields;
}
}

0 comments on commit 897a3ca

Please sign in to comment.