Skip to content

Commit 252f16a

Browse files
devondragonclaude
andcommitted
feat: add database constraints and indexes to PasswordHistoryEntry
- Add @column annotations with proper constraints for passwordHash and entryDate - Set passwordHash max length to 255 characters (sufficient for bcrypt hashes) - Mark both passwordHash and entryDate as non-nullable fields - Add database indexes on user_id and entry_date for query performance - Improve query performance for findByUserOrderByEntryDateDesc operations These changes ensure data integrity at the database level and optimize password history lookups which are performed on every password change. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent db1ea20 commit 252f16a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/com/digitalsanctuary/spring/user/persistence/model/PasswordHistoryEntry.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import java.time.LocalDateTime;
44

5+
import jakarta.persistence.Column;
56
import jakarta.persistence.Entity;
67
import jakarta.persistence.FetchType;
78
import jakarta.persistence.GeneratedValue;
89
import jakarta.persistence.GenerationType;
910
import jakarta.persistence.Id;
11+
import jakarta.persistence.Index;
1012
import jakarta.persistence.JoinColumn;
1113
import jakarta.persistence.ManyToOne;
1214
import jakarta.persistence.Table;
@@ -19,7 +21,10 @@
1921
*/
2022
@Data
2123
@Entity
22-
@Table(name = "password_history_entry")
24+
@Table(name = "password_history_entry", indexes = {
25+
@Index(name = "idx_user_id", columnList = "user_id"),
26+
@Index(name = "idx_entry_date", columnList = "entry_date")
27+
})
2328
public class PasswordHistoryEntry {
2429

2530
/** The id. */
@@ -33,9 +38,11 @@ public class PasswordHistoryEntry {
3338
private User user;
3439

3540
/** The hashed password. */
41+
@Column(length = 255, nullable = false)
3642
private String passwordHash;
3743

3844
/** The timestamp when the password was stored. */
45+
@Column(name = "entry_date", nullable = false)
3946
private LocalDateTime entryDate;
4047

4148
/**

0 commit comments

Comments
 (0)