Skip to content

Feature/entity edit#2

Merged
simonforsberg merged 10 commits intomainfrom
feature/entity-edit
Mar 31, 2026
Merged

Feature/entity edit#2
simonforsberg merged 10 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 / Data validation

    • Required attachment filename and storage key fields
    • Comment messages now required and limited to 2000 characters
    • Enforced unique, constrained usernames and consistent password mapping

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e0fd64e8-229d-4f0f-8b7f-a35c29d080b3

📥 Commits

Reviewing files that changed from the base of the PR and between 4e6559d and 97b96c3.

📒 Files selected for processing (4)
  • 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
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/main/java/org/example/alfs/entities/AuditLog.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/entities/Ticket.java

📝 Walkthrough

Walkthrough

JPA entity mappings were tightened: several String fields converted to enums and persisted as strings, non-null and length constraints added to multiple columns, Ticket relationships and lifecycle hooks adjusted, new enums introduced and Role moved to an enums package, and CI workflow YAML simplified.

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, making those DB columns non-nullable.
AuditLog Enum Mapping
src/main/java/org/example/alfs/entities/AuditLog.java
Changed action from String to AuditAction with @Enumerated(EnumType.STRING) and added @Column(nullable = false, length = 50).
Ticket Restructure & Lifecycle
src/main/java/org/example/alfs/entities/Ticket.java
Replaced String status with TicketStatus (@Enumerated(EnumType.STRING), nullable=false), added updatedAt and @PreUpdate, defaulted status to OPEN in @PrePersist, tightened title column, made description a lazy @Lob, removed assignedHandler, and added nullable reporter and investigator @ManyToOne relations with explicit join columns.
TicketComment Mapping
src/main/java/org/example/alfs/entities/TicketComment.java
Normalized @Table whitespace; added @Column(nullable = false, length = 2000) to message (message now required and length-limited).
User Field & Mapping Adjustments
src/main/java/org/example/alfs/entities/User.java
Tightened username to @Column(nullable = false, unique = true, length = 100); removed explicit name = "password_hash" from passwordHash column annotation while keeping nullable=false, length=255; updated Role import to org.example.alfs.enums.Role.
CI Workflow
.github/workflows/CI.yml
Removed push trigger for main, simplified Maven command, renamed JDK step title, removed dependency-submission step, and applied minor YAML formatting changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Feature/entities #1: Earlier PR that introduced the same JPA entities now being modified (mappings, enums, and constraints).

Poem

🐇 I hopped through schemas, nudged nulls away,
Enums for order, columns set to stay,
Reporters and seekers find their new home,
Timestamps keep rhythm as queries roam,
A tiny carrot for every merged day.

🚥 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 uses non-descriptive terms that do not convey meaningful information about the specific changes made to the codebase. Use a more descriptive title that highlights the main changes, such as 'Add column constraints and refactor entities with enums' or 'Introduce enums and enforce database constraints across entities'.
✅ 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.

@simonforsberg simonforsberg merged commit 6e48e81 into main Mar 31, 2026
2 checks passed
This was referenced Mar 31, 2026
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