Add token version
This commit is contained in:
@@ -37,6 +37,9 @@ public class User {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Boolean active = true;
|
private Boolean active = true;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Integer tokenVersion = 0;
|
||||||
|
|
||||||
@CreationTimestamp
|
@CreationTimestamp
|
||||||
@Column(name = "created_at", updatable = false)
|
@Column(name = "created_at", updatable = false)
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
@@ -52,7 +55,7 @@ public class User {
|
|||||||
public User() {
|
public User() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(Long id, String username, String password, String email, String fullName, String avatarUrl, Role role, Boolean active, LocalDateTime createdAt, LocalDateTime updatedAt) {
|
public User(Long id, String username, String password, String email, String fullName, String avatarUrl, Role role, Boolean active, Integer tokenVersion, LocalDateTime createdAt, LocalDateTime updatedAt) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
@@ -61,6 +64,7 @@ public class User {
|
|||||||
this.avatarUrl = avatarUrl;
|
this.avatarUrl = avatarUrl;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
this.active = active;
|
this.active = active;
|
||||||
|
this.tokenVersion = tokenVersion;
|
||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
this.updatedAt = updatedAt;
|
this.updatedAt = updatedAt;
|
||||||
}
|
}
|
||||||
@@ -129,6 +133,14 @@ public class User {
|
|||||||
this.active = active;
|
this.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getTokenVersion() {
|
||||||
|
return tokenVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokenVersion(Integer tokenVersion) {
|
||||||
|
this.tokenVersion = tokenVersion;
|
||||||
|
}
|
||||||
|
|
||||||
public LocalDateTime getCreatedAt() {
|
public LocalDateTime getCreatedAt() {
|
||||||
return createdAt;
|
return createdAt;
|
||||||
}
|
}
|
||||||
@@ -169,6 +181,7 @@ public class User {
|
|||||||
", avatarUrl='" + avatarUrl + '\'' +
|
", avatarUrl='" + avatarUrl + '\'' +
|
||||||
", role=" + role +
|
", role=" + role +
|
||||||
", active=" + active +
|
", active=" + active +
|
||||||
|
", tokenVersion=" + tokenVersion +
|
||||||
", createdAt=" + createdAt +
|
", createdAt=" + createdAt +
|
||||||
", updatedAt=" + updatedAt +
|
", updatedAt=" + updatedAt +
|
||||||
'}';
|
'}';
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN tokenVersion INT NOT NULL DEFAULT 0 AFTER active;
|
||||||
@@ -77,4 +77,19 @@ class RunConfigValidationTest {
|
|||||||
assertTrue(migrationContent.contains("active BOOLEAN") || migrationContent.contains("active boolean"),
|
assertTrue(migrationContent.contains("active BOOLEAN") || migrationContent.contains("active boolean"),
|
||||||
"Baseline migration should contain the users.active column definition.");
|
"Baseline migration should contain the users.active column definition.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void userTokenVersionMigrationExists() {
|
||||||
|
File migrationFile = new File("src/main/resources/db/migration/V5__user_token_version.sql");
|
||||||
|
assertTrue(migrationFile.exists(), "User tokenVersion migration should exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void userTokenVersionMigrationAddsColumn() throws Exception {
|
||||||
|
File migrationFile = new File("src/main/resources/db/migration/V5__user_token_version.sql");
|
||||||
|
String migrationContent = new String(java.nio.file.Files.readAllBytes(migrationFile.toPath()));
|
||||||
|
|
||||||
|
assertTrue(migrationContent.contains("ADD COLUMN tokenVersion INT NOT NULL DEFAULT 0"),
|
||||||
|
"User tokenVersion migration should add the tokenVersion column with default 0.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/test/java/com/petshop/backend/entity/UserEntityTest.java
Normal file
24
src/test/java/com/petshop/backend/entity/UserEntityTest.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package com.petshop.backend.entity;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class UserEntityTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void tokenVersionDefaultsToZero() {
|
||||||
|
User user = new User();
|
||||||
|
|
||||||
|
assertEquals(0, user.getTokenVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void tokenVersionCanBeUpdated() {
|
||||||
|
User user = new User();
|
||||||
|
|
||||||
|
user.setTokenVersion(3);
|
||||||
|
|
||||||
|
assertEquals(3, user.getTokenVersion());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user