Skip to content

Commit

Permalink
use unique name for backing index of unique constraints
Browse files Browse the repository at this point in the history
fixes #411
  • Loading branch information
chrstnbrn committed Oct 1, 2023
1 parent d297eac commit b8bd7f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro
i++;
}

Index index = getBackingIndex(uniqueConstraint, hibernateTable, snapshot);
Index index = getBackingIndex(uniqueConstraint, snapshot);
uniqueConstraint.setBackingIndex(index);

Scope.getCurrentScope().getLog(getClass()).info("Found unique constraint " + uniqueConstraint.toString());
Expand All @@ -77,7 +77,7 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro
Scope.getCurrentScope().getLog(getClass()).info("Found unique constraint " + uniqueConstraint.toString());
table.getUniqueConstraints().add(uniqueConstraint);

Index index = getBackingIndex(uniqueConstraint, hibernateTable, snapshot);
Index index = getBackingIndex(uniqueConstraint, snapshot);
uniqueConstraint.setBackingIndex(index);

}
Expand Down Expand Up @@ -111,12 +111,12 @@ private String hashedName(String s) {
}
}

protected Index getBackingIndex(UniqueConstraint uniqueConstraint, org.hibernate.mapping.Table hibernateTable, DatabaseSnapshot snapshot) {
protected Index getBackingIndex(UniqueConstraint uniqueConstraint, DatabaseSnapshot snapshot) {
Index index = new Index();
index.setRelation(uniqueConstraint.getRelation());
index.setColumns(uniqueConstraint.getColumns());
index.setUnique(true);
index.setName(hibernateTable.getName() + "_IX");
index.setName(uniqueConstraint.getName() + "_IX");

return index;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/example/ejb3/auction/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class Item {
@Column(unique = true)
private String name;

@Column(unique = true)
private String key;

public long getId() {
return id;
}
Expand All @@ -28,4 +31,7 @@ public void setName(String name) {
this.name = name;
}

public String getKey() { return key; }

public void setKey(String key) { this.key = key; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void runGeneratedChangeLog() throws Exception {

assertEquals(differences, 0, diffResult.getMissingObjects().size());
assertEquals(differences, 0, diffResult.getUnexpectedObjects().size());
assertEquals(differences, 0, diffResult.getChangedObjects(UniqueConstraint.class).size());
// assertEquals(differences, 0, diffResult.getChangedObjects().size()); //unimportant differences in schema name and datatypes causing test to fail

}
Expand Down

0 comments on commit b8bd7f5

Please sign in to comment.