Skip to content

Feature/entity edit#2

Open
simonforsberg wants to merge 9 commits intomainfrom
feature/entity-edit
Open

Feature/entity edit#2
simonforsberg wants to merge 9 commits intomainfrom
feature/entity-edit

Conversation

@simonforsberg
Copy link
Copy Markdown
Contributor

@simonforsberg simonforsberg commented Mar 30, 2026

Updated entities:

  • General column constraints
  • Refined mappings

Introduced and refactored enum's:

  • Role
  • AuditAction
  • TicketStatus

@coderabbitai review

Summary by CodeRabbit

  • New Features
    • Ticket status tracking with predefined statuses (Open, In Progress, Resolved, Closed)
    • Audit action logging for clearer activity records
    • Added ticket update timestamps and distinct reporter/investigator roles
  • Bug Fixes
    • Strengthened data validation: required fields and message length limits
    • Enforced unique, constrained usernames and consistent password field mapping

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

Updated JPA entity mappings: added non-null/length constraints, replaced String fields with enums, refactored Ticket relationships and lifecycle hooks, added enums, moved Role enum, and adjusted CI workflow configuration.

Changes

Cohort / File(s) Summary
Enums & Package Moves
src/main/java/org/example/alfs/enums/AuditAction.java, src/main/java/org/example/alfs/enums/TicketStatus.java, src/main/java/org/example/alfs/enums/Role.java
Added AuditAction and TicketStatus enums; moved existing Role enum into org.example.alfs.enums.
Attachment Constraints
src/main/java/org/example/alfs/entities/Attachment.java
Added @Column(nullable = false) to fileName and s3Key.
AuditLog Enum Mapping
src/main/java/org/example/alfs/entities/AuditLog.java
Changed action from String to AuditAction with @Enumerated(EnumType.STRING).
Ticket Restructure & Lifecycle
src/main/java/org/example/alfs/entities/Ticket.java
Changed status to TicketStatus (EnumType.STRING), added updatedAt with @PreUpdate, defaulted status to OPEN in @PrePersist, tightened title and description column definitions, and replaced assignedHandler with reporter and investigator (@ManyToOne with explicit join columns).
TicketComment Mapping
src/main/java/org/example/alfs/entities/TicketComment.java
Renamed DB table to ticket_comments and added @Column(nullable = false, length = 2000) to message.
User Field & Mapping Changes
src/main/java/org/example/alfs/entities/User.java
Renamed passwordHashpassword (removed explicit password_hash column name), set username to @Column(nullable = false, unique = true, length = 100), and updated Role import to org.example.alfs.enums.Role.
CI Workflow
.github/workflows/CI.yml
Removed push trigger on main, simplified Maven command, renamed JDK step title, removed dependency-submission step, and adjusted YAML formatting.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Feature/entities #1: Initial PR introducing the JPA entities that this change further modifies (mappings, enums, and constraints).

Poem

🐇 I hopped through schemas, nibbling null away,
Enums stitched feathers where loose strings lay,
Two handlers now bound, timestamps keep time,
A tidy database—my carrot and rhyme! 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/entity edit' is vague and generic, failing to specify which entities were modified or what the primary nature of the changes are. Revise the title to be more descriptive, such as 'Add enum types and refine entity column mappings' or 'Update JPA entities with enhanced constraints and enums', clearly indicating the main changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/entity-edit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/main/java/org/example/alfs/entities/Ticket.java (2)

31-32: Use @Lob for large text fields instead of vendor-specific columnDefinition = "TEXT" for better portability across JPA providers.

The description field on line 31 should be annotated with @Lob and optionally @Basic(fetch = FetchType.LAZY) to leverage JPA's standard mechanism for large-value columns.

♻️ Proposed refactor
-    `@Column`(columnDefinition = "TEXT")
+    `@Lob`
+    `@Basic`(fetch = FetchType.LAZY)
     private String description;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/example/alfs/entities/Ticket.java` around lines 31 - 32,
Replace the vendor-specific `@Column`(columnDefinition = "TEXT") on the
Ticket.description field with JPA-standard large-object mapping: annotate the
description field with `@Lob` and, if lazy loading is desired, also add
`@Basic`(fetch = FetchType.LAZY); update imports accordingly and remove the
columnDefinition usage so the JPA provider chooses the proper large-text type.

60-66: Use LAZY fetch on reporter and investigator relations.

Default EAGER loading will fetch User entities on every Ticket query. Since these relations are optional (null if anonymous/unassigned) and may not be needed in all query contexts, LAZY loading prevents unnecessary joins.

♻️ Proposed refactor
-    `@ManyToOne`
+    `@ManyToOne`(fetch = FetchType.LAZY)
     `@JoinColumn`(name = "reporter_id", nullable = true)  // null if anonymous
     private User reporter;

-    `@ManyToOne`
+    `@ManyToOne`(fetch = FetchType.LAZY)
     `@JoinColumn`(name = "investigator_id", nullable = true)
     private User investigator;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/example/alfs/entities/Ticket.java` around lines 60 - 66,
The Ticket entity currently uses default (EAGER) fetching on the reporter and
investigator `@ManyToOne` relations; change both to lazy loading by adding fetch =
FetchType.LAZY on the `@ManyToOne` annotations for the reporter and investigator
fields in the Ticket class and import javax.persistence.FetchType (or jakarta
equivalent). Update any code that assumes non-proxied User access (e.g.,
serialization or equals/hashCode) to handle lazy proxies if necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/example/alfs/entities/AuditLog.java`:
- Around line 26-27: The AuditLog.entity's action field is missing a DB-level
non-null constraint; update the AuditLog class by annotating the action field
(the field named action with `@Enumerated`(EnumType.STRING)) to include a `@Column`
with nullable=false and an appropriate length (e.g., length=50) so the enum
string is stored as non-null in the schema; ensure the `@Column` annotation is
applied alongside the existing `@Enumerated` annotation to enforce the constraint
at persistence time.

In `@src/main/java/org/example/alfs/entities/Ticket.java`:
- Around line 34-35: The Ticket entity's status field (private TicketStatus
status annotated with `@Enumerated`(EnumType.STRING)) can still become null via
updates or setters because the constraint is only enforced in `@PrePersist`; add a
database-level NOT NULL and ensure JPA mapping reflects it by annotating the
status field with a non-null column (e.g., `@Column`(nullable = false) or
equivalent) and update your DB migration (Flyway/Liquibase) to add a NOT NULL
constraint for the tickets table status column so all persistence paths are
enforced.

In `@src/main/java/org/example/alfs/entities/TicketComment.java`:
- Line 14: The schema change renames the table backing the entity TicketComment
(see `@Table`(name = "ticket_comments")), but no migration was added; create and
add an explicit migration that renames the existing table ticket_comment to
ticket_comments (or creates ticket_comments and migrates data) using your chosen
tool (Flyway or Liquibase), include DDL to rename the table and any
index/constraint renames, and ensure the migration file is versioned and applied
before the application starts so TicketComment can map to the new table name
without runtime failures.

---

Nitpick comments:
In `@src/main/java/org/example/alfs/entities/Ticket.java`:
- Around line 31-32: Replace the vendor-specific `@Column`(columnDefinition =
"TEXT") on the Ticket.description field with JPA-standard large-object mapping:
annotate the description field with `@Lob` and, if lazy loading is desired, also
add `@Basic`(fetch = FetchType.LAZY); update imports accordingly and remove the
columnDefinition usage so the JPA provider chooses the proper large-text type.
- Around line 60-66: The Ticket entity currently uses default (EAGER) fetching
on the reporter and investigator `@ManyToOne` relations; change both to lazy
loading by adding fetch = FetchType.LAZY on the `@ManyToOne` annotations for the
reporter and investigator fields in the Ticket class and import
javax.persistence.FetchType (or jakarta equivalent). Update any code that
assumes non-proxied User access (e.g., serialization or equals/hashCode) to
handle lazy proxies if necessary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: decd778b-7d5f-4dd3-b078-dcf8f6f2dd4a

📥 Commits

Reviewing files that changed from the base of the PR and between ab800a4 and e20da81.

📒 Files selected for processing (8)
  • src/main/java/org/example/alfs/entities/Attachment.java
  • src/main/java/org/example/alfs/entities/AuditLog.java
  • src/main/java/org/example/alfs/entities/Ticket.java
  • src/main/java/org/example/alfs/entities/TicketComment.java
  • src/main/java/org/example/alfs/entities/User.java
  • src/main/java/org/example/alfs/enums/AuditAction.java
  • src/main/java/org/example/alfs/enums/Role.java
  • src/main/java/org/example/alfs/enums/TicketStatus.java

*/
@Entity
@Table(name="ticket_comment")
@Table(name = "ticket_comments")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether rename migration and table references are present
rg -nP 'ticket_comment\b|ticket_comments\b|ALTER TABLE|RENAME TABLE' -g '*.sql' -C2
rg -nP 'ticket_comment(s)?' -C2

Repository: ithsjava25/project-backend-alfs

Length of output: 611


🏁 Script executed:

# Check what migration framework is used
cat pom.xml 2>/dev/null | grep -A5 -B5 "flyway\|liquibase\|hibernate" | head -30

Repository: ithsjava25/project-backend-alfs

Length of output: 57


🏁 Script executed:

# Search for migration files in various formats
find . -type f \( -name "*.sql" -o -name "*.yml" -o -name "*.yaml" -o -name "V*.sql" -o -name "db.migration*" \) 2>/dev/null | head -20

Repository: ithsjava25/project-backend-alfs

Length of output: 101


🏁 Script executed:

# Check for references to the singular "ticket_comment" table name
rg -i "ticket_comment\b" --type-list | head -5
rg -i "ticket_comment\b" -C3 2>/dev/null | head -50

Repository: ithsjava25/project-backend-alfs

Length of output: 464


🏁 Script executed:

# Check git history for this file to see if table name changed
cd . && git log --oneline -- src/main/java/org/example/alfs/entities/TicketComment.java 2>/dev/null | head -10
git show HEAD:src/main/java/org/example/alfs/entities/TicketComment.java 2>/dev/null | grep -A2 "@Table" | head -5

Repository: ithsjava25/project-backend-alfs

Length of output: 238


🏁 Script executed:

cat pom.xml | head -100

Repository: ithsjava25/project-backend-alfs

Length of output: 3567


🏁 Script executed:

# Check repository structure to understand where migrations/db setup might be
find . -type f -name "*.java" | grep -i "migrat\|config\|database\|schema" | head -20

Repository: ithsjava25/project-backend-alfs

Length of output: 57


🏁 Script executed:

# Check if there's a resources directory with db scripts
find . -path "*/resources/*" -type f | head -30

Repository: ithsjava25/project-backend-alfs

Length of output: 118


🏁 Script executed:

# Look at the previous version of the TicketComment file to see what the old table name was
git log --all --oneline -- src/main/java/org/example/alfs/entities/TicketComment.java
git show HEAD~1:src/main/java/org/example/alfs/entities/TicketComment.java 2>/dev/null | grep -A5 -B5 "@Table" | head -20

Repository: ithsjava25/project-backend-alfs

Length of output: 378


🏁 Script executed:

# Check the table name in each commit
git show 0791b1b:src/main/java/org/example/alfs/entities/TicketComment.java 2>/dev/null | grep -A2 -B2 "@Table"
git show 673f5cb:src/main/java/org/example/alfs/entities/TicketComment.java 2>/dev/null | grep -A2 -B2 "@Table"
git show 02a9056:src/main/java/org/example/alfs/entities/TicketComment.java 2>/dev/null | grep -A2 -B2 "@Table"

Repository: ithsjava25/project-backend-alfs

Length of output: 278


🏁 Script executed:

# Check if there are any database initialization files or schema definitions anywhere
find . -type f \( -name "*.sql" -o -name "schema*" -o -name "data.sql" \) 2>/dev/null

Repository: ithsjava25/project-backend-alfs

Length of output: 57


🏁 Script executed:

# Check application properties for JPA/Hibernate settings
cat src/main/resources/application.properties

Repository: ithsjava25/project-backend-alfs

Length of output: 132


🏁 Script executed:

# Search for any references to old table name "ticket_comment" (singular)
rg "ticket_comment\b" -C3 2>/dev/null

Repository: ithsjava25/project-backend-alfs

Length of output: 57


Add explicit migration for table rename from ticket_comment to ticket_comments.

This change renames the table from ticket_comment (used in commits through 0791b1b) to ticket_comments. Without a migration, existing databases will fail at runtime when the application tries to access the non-existent ticket_comments table. Include either a Flyway/Liquibase migration or document the migration steps required for existing deployments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/example/alfs/entities/TicketComment.java` at line 14, The
schema change renames the table backing the entity TicketComment (see
`@Table`(name = "ticket_comments")), but no migration was added; create and add an
explicit migration that renames the existing table ticket_comment to
ticket_comments (or creates ticket_comments and migrates data) using your chosen
tool (Flyway or Liquibase), include DDL to rename the table and any
index/constraint renames, and ensure the migration file is versioned and applied
before the application starts so TicketComment can map to the new table name
without runtime failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant