Skip to content

Commit a18c0d7

Browse files
committed
Refactor ProjectEntity to use UUID as primary key and update related database migrations and repository
1 parent bab3305 commit a18c0d7

7 files changed

Lines changed: 23 additions & 12 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ db-port-forward:
394394

395395
db-docker-build-db:
396396
@echo "$(BLUE)Building Docker image for database...$(NC)"
397-
@docker build --file ../../ods-core/ods-api-service/docker/Dockerfile.database --tag $(PROJECT_NAME)-db:18 ../../ods-core/ods-api-service/docker/
397+
@docker build --file ../ods-core/ods-api-service/docker/Dockerfile.database --tag $(PROJECT_NAME)-db:18 ../ods-core/ods-api-service/docker/
398398
@echo "$(GREEN)✓ Database Docker image built: $(PROJECT_NAME)-db:$(DOCKER_TAG)$(NC)"
399399

400400
db-docker-run-db: db-docker-build-db

persistence/src/main/java/org/opendevstack/apiservice/persistence/entity/ProjectEntity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import jakarta.persistence.PreUpdate;
1010
import jakarta.persistence.Table;
1111
import java.time.OffsetDateTime;
12+
import java.util.UUID;
1213
import lombok.AllArgsConstructor;
1314
import lombok.Builder;
1415
import lombok.Getter;
@@ -41,9 +42,9 @@
4142
public class ProjectEntity {
4243

4344
@Id
44-
@GeneratedValue(strategy = GenerationType.IDENTITY)
45+
@GeneratedValue(strategy = GenerationType.UUID)
4546
@Column(name = "id", nullable = false, updatable = false)
46-
private Long id;
47+
private UUID id;
4748

4849
/**
4950
* Human-readable unique identifier (e.g. {@code MY-PROJECT}). Maps to the

persistence/src/main/java/org/opendevstack/apiservice/persistence/repository/ProjectRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.List;
44
import java.util.Optional;
5+
import java.util.UUID;
56
import org.opendevstack.apiservice.persistence.entity.ProjectEntity;
67
import org.springframework.data.jpa.repository.JpaRepository;
78
import org.springframework.stereotype.Repository;
@@ -18,7 +19,7 @@
1819
* </p>
1920
*/
2021
@Repository
21-
public interface ProjectRepository extends JpaRepository<ProjectEntity, Long> {
22+
public interface ProjectRepository extends JpaRepository<ProjectEntity, UUID> {
2223

2324
/**
2425
* Finds a project by its unique business key regardless of soft-delete status. Use

persistence/src/main/resources/db/changelog/migrations/001_create_projects_table.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
-- Description: Creates the `projects` table, which is the central entity of the
55
-- ods-api-service. Each row represents a managed project identified by
66
-- a unique, Atlassian project key (e.g. "MY-PROJECT").
7+
CREATE EXTENSION IF NOT EXISTS pgcrypto;
8+
79
CREATE TABLE IF NOT EXISTS projects (
8-
id BIGSERIAL PRIMARY KEY,
10+
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
911
project_key VARCHAR(100) NOT NULL,
1012
project_name VARCHAR(255),
1113
description VARCHAR(255),

persistence/src/main/resources/db/changelog/migrations/002_create_client_apps_table.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
--changeset ods:002-create-client-apps
44
-- Description: Creates the `client_apps` table, representing registered Azure AD
55
-- clients that are authorised to call the service APIs.
6+
CREATE EXTENSION IF NOT EXISTS pgcrypto;
7+
68
CREATE TABLE IF NOT EXISTS client_apps (
7-
id BIGSERIAL PRIMARY KEY,
9+
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
810
client_id VARCHAR(36) NOT NULL,
911
client_name VARCHAR(255),
1012
permissions TEXT[] NOT NULL DEFAULT '{}',
@@ -32,8 +34,8 @@ COMMENT ON COLUMN client_apps.enabled IS 'When FALSE the client is denied ac
3234
-- Description: Each API client can be configured with one or more project flavors
3335
-- that control how projects are created (key pattern, template, owner, etc.).
3436
CREATE TABLE IF NOT EXISTS client_app_project_flavors (
35-
id BIGSERIAL PRIMARY KEY,
36-
client_app_id BIGINT NOT NULL,
37+
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
38+
client_app_id UUID NOT NULL,
3739
name VARCHAR(50) NOT NULL,
3840
project_key_pattern VARCHAR(100) NOT NULL,
3941
template_id INT,
@@ -53,7 +55,7 @@ CREATE INDEX IF NOT EXISTS idx_client_app_project_flavors_client_app_id
5355
ON client_app_project_flavors (client_app_id);
5456

5557
COMMENT ON TABLE client_app_project_flavors IS 'Project flavor configurations per API client';
56-
COMMENT ON COLUMN client_app_project_flavors.client_app_id IS 'FK to client_apps.id';
58+
COMMENT ON COLUMN client_app_project_flavors.client_app_id IS 'FK to client_apps.id (UUID)';
5759
COMMENT ON COLUMN client_app_project_flavors.name IS 'Flavor name (e.g. DLSS, AMP)';
5860
COMMENT ON COLUMN client_app_project_flavors.project_key_pattern IS 'printf-style pattern used to generate the project key (e.g. DLSS%06d)';
5961
COMMENT ON COLUMN client_app_project_flavors.template_id IS 'ODS/Jira template identifier';

persistence/src/test/java/org/opendevstack/apiservice/persistence/repository/ProjectRepositoryTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
class ProjectRepositoryTest {
3838

3939
@Container
40-
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16-alpine")
40+
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:18-alpine")
4141
.withDatabaseName("devstack_test")
4242
.withUsername("test")
4343
.withPassword("test");
@@ -47,8 +47,11 @@ static void postgresProperties(DynamicPropertyRegistry registry) {
4747
registry.add("spring.datasource.url", postgres::getJdbcUrl);
4848
registry.add("spring.datasource.username", postgres::getUsername);
4949
registry.add("spring.datasource.password", postgres::getPassword);
50-
// Override ddl-auto for tests: let Hibernate create the schema from entities
51-
registry.add("spring.jpa.hibernate.ddl-auto", () -> "create-drop");
50+
registry.add("spring.datasource.hikari.maximum-pool-size", () -> "2");
51+
registry.add("spring.datasource.hikari.minimum-idle", () -> "0");
52+
// Let Hibernate create the schema once for the container lifecycle and avoid
53+
// delayed drop-on-close work during JVM shutdown.
54+
registry.add("spring.jpa.hibernate.ddl-auto", () -> "create");
5255
}
5356

5457
@Autowired

persistence/src/test/resources/application-local.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ spring.datasource.username=ods_api_service
44
spring.datasource.password=ods_api_service
55
spring.datasource.driver-class-name=org.postgresql.Driver
66
spring.datasource.hikari.connection-timeout=30000
7+
spring.datasource.hikari.maximum-pool-size=2
8+
spring.datasource.hikari.minimum-idle=0
79
spring.datasource.hikari.idle-timeout=600000
810
spring.datasource.hikari.max-lifetime=1800000

0 commit comments

Comments
 (0)