Skip to content

Refactor ActivityLog model, Flyway migrations, update dependency configurations - #51

Merged
codebyNorthsteep merged 3 commits into
mainfrom
flywaymigration-init
Apr 7, 2026
Merged

Refactor ActivityLog model, Flyway migrations, update dependency configurations#51
codebyNorthsteep merged 3 commits into
mainfrom
flywaymigration-init

Conversation

@codebyNorthsteep

@codebyNorthsteep codebyNorthsteep commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces several important changes to the database schema, dependency management, and data initialization logic. The main highlights include the addition of an initial Flyway migration script to set up all core tables and relationships, updates to Flyway and Spring Boot dependencies, improvements to the ActivityLog model, and enhancements to the staff data initialization to include department information.

Database schema and migration:

  • Added a comprehensive Flyway migration script (V1__init.sql) that creates all core tables (activity_logs, attachment, comments, employment_form, report_form, staff, ticket_attachment, tickets) and defines foreign key constraints and unique indexes to establish relationships and enforce data integrity.
  • Changed spring.jpa.hibernate.ddl-auto from validate to none in application.properties to prevent Hibernate from managing schema changes, relying entirely on Flyway for schema management.

Dependency and configuration updates:

  • Updated pom.xml to use spring-boot-starter-flyway and flyway-database-postgresql for better Flyway integration with PostgreSQL, replacing the previous direct flyway-core dependency.

Model and service improvements:

  • Enhanced the ActivityLog entity by adding an all-arguments constructor and a convenience constructor for easier instantiation, improving code clarity and reducing boilerplate. [1] [2]
  • Updated ActivityLogService to use the new ActivityLog constructor for logging comments.

Data initialization enhancements:

  • Modified the data initializer to associate each staff member with a department and updated phone number formatting for consistency. The createStaff method now accepts a Department argument and sets it on the Staff entity. [1] [2]

These changes collectively improve the maintainability, scalability, and clarity of the application's data layer and initialization process.

Summary by CodeRabbit

  • New Features

    • Added an initial database migration creating core tables, indexes, constraints and relations for tickets, staff, forms, comments, attachments, and activity logs.
  • Refactor

    • Switched to Flyway-driven schema management and disabled Hibernate DDL validation at runtime.
    • Seed data now assigns departments to staff.
    • Activity log model includes an all-arguments constructor for easier instantiation.
  • Chores

    • Build updated to use the Spring Boot Flyway starter for migration management.

@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown

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: 2a80a273-ae80-4bde-b92b-011db0708045

📥 Commits

Reviewing files that changed from the base of the PR and between 585fa20 and 2b4bd21.

📒 Files selected for processing (1)
  • src/main/resources/db/migration/V1__init.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/resources/db/migration/V1__init.sql

📝 Walkthrough

Walkthrough

Replaced explicit Flyway artifacts with Spring Boot's Flyway starter, set Hibernate DDL to none, added an initial Flyway migration creating core tables and constraints, updated DataInitializer to assign Departments to seeded Staff, and added constructors to ActivityLog.

Changes

Cohort / File(s) Summary
Build & Dependency Management
pom.xml
Replaced org.flywaydb:flyway-core and org.flywaydb:flyway-database-postgresql with org.springframework.boot:spring-boot-starter-flyway.
Configuration
src/main/resources/application.properties
Changed spring.jpa.hibernate.ddl-auto from validate to none; spring.flyway.enabled and spring.jpa.show-sql unchanged.
Database Migration
src/main/resources/db/migration/V1__init.sql
Added initial migration creating tables (activity_logs, attachment, comments, employment_form, report_form, staff, ticket_attachment, tickets), indexes, unique constraints, and foreign keys.
Data Initialization
src/main/java/org/example/cyberwatch/config/DataInitializer.java
Seed data updated to pass and assign Department to Staff; createStaff now accepts a Department parameter.
Model
src/main/java/org/example/cyberwatch/features/activitylog/model/ActivityLog.java
Added Lombok @AllArgsConstructor and an explicit constructor ActivityLog(Ticket, Staff, ActivityType, String).
Service (comment)
src/main/java/org/example/cyberwatch/features/activitylog/service/ActivityLogService.java
Added inline comment suggesting use of TicketDTO instead of Ticket entity in logComment (no functional change).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • gitnes94
  • alicewersen-rgb
  • Ericthilen

Poem

🐇 I hopped through migrations bright,

Schemas grew under moonlit night,
Staff found homes with departments new,
Constructors stitched the logging view,
A rabbit claps—code sprung to light! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes across all files: refactoring ActivityLog (adding constructors), updating Flyway migrations (schema definition), and revising dependency configurations (pom.xml and application.properties).

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch flywaymigration-init

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/main/resources/application.properties (1)

6-6: Keep Hibernate in validate instead of none.

Spring Boot still calls Flyway.migrate() on startup when Flyway is present, while spring.jpa.hibernate.ddl-auto only controls Hibernate’s schema action; Hibernate’s VALIDATE action is schema validation, whereas none does nothing. Switching this to none drops the startup guardrail and defers mapping drift to runtime. (docs.spring.io)

🔎 Minimal change
-spring.jpa.hibernate.ddl-auto=none
+spring.jpa.hibernate.ddl-auto=validate
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/application.properties` at line 6, Change the Hibernate
schema action from "none" back to "validate" by updating the
spring.jpa.hibernate.ddl-auto property value; locate the property
spring.jpa.hibernate.ddl-auto in application.properties and set it to validate
so Hibernate performs schema validation at startup
(spring.jpa.hibernate.ddl-auto=validate) to retain the startup guardrail against
mapping drift.
🤖 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/resources/db/migration/V1__init.sql`:
- Around line 1-10: Add a b-tree index to support the read path used by
ActivityLogService (methods in
org/example/cyberwatch/features/activitylog/service/ActivityLogService.java that
fetch by ticket_id ordered by timestamp) so queries on activity_logs by
ticket_id ORDER BY timestamp are not forced to scan; create an index on
(ticket_id, timestamp) — preferably with timestamp DESC to match the ordering —
with a clear name (e.g., idx_activity_logs_ticket_timestamp) and include it in
the migration (either by updating the current migration or adding a new one) so
PostgreSQL will use the index for those lookups.
- Around line 78-85: The migration creates column s3key which doesn't match
Hibernate's default mapping for the TicketAttachment.s3Key field (expecting
s3_key); update the CREATE TABLE for ticket_attachment to rename the column from
s3key to s3_key so the database column name matches the entity's implicit
mapping and primary key/constraints remain unchanged.

---

Nitpick comments:
In `@src/main/resources/application.properties`:
- Line 6: Change the Hibernate schema action from "none" back to "validate" by
updating the spring.jpa.hibernate.ddl-auto property value; locate the property
spring.jpa.hibernate.ddl-auto in application.properties and set it to validate
so Hibernate performs schema validation at startup
(spring.jpa.hibernate.ddl-auto=validate) to retain the startup guardrail against
mapping drift.
🪄 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: 2ebeadf9-79b5-4c23-95b6-f1a3c346b900

📥 Commits

Reviewing files that changed from the base of the PR and between 1ae492e and 135e869.

📒 Files selected for processing (6)
  • pom.xml
  • src/main/java/org/example/cyberwatch/config/DataInitializer.java
  • src/main/java/org/example/cyberwatch/features/activitylog/model/ActivityLog.java
  • src/main/java/org/example/cyberwatch/features/activitylog/service/ActivityLogService.java
  • src/main/resources/application.properties
  • src/main/resources/db/migration/V1__init.sql

Comment thread src/main/resources/db/migration/V1__init.sql
Comment thread src/main/resources/db/migration/V1__init.sql

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/resources/db/migration/V1__init.sql`:
- Around line 27-35: Add indexes on the ticket foreign-key columns to avoid
future sequential scans and expensive FK checks: create a non-unique index on
comments.ticket_id (referencing the comments table and ticket_id column) and a
non-unique index on ticket_attachment.ticket_id (referencing the
ticket_attachment table and ticket_id column); ensure these index creations are
applied in a migration before or alongside V1__init.sql so reads and
deletes/updates on tickets use the indexes (note activity_logs already has the
appropriate composite index so no change needed there).
🪄 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: 5c364b84-aca5-4996-a661-a2af6e93bde8

📥 Commits

Reviewing files that changed from the base of the PR and between 135e869 and 585fa20.

📒 Files selected for processing (1)
  • src/main/resources/db/migration/V1__init.sql

Comment thread src/main/resources/db/migration/V1__init.sql
@codebyNorthsteep
codebyNorthsteep merged commit 422d6d3 into main Apr 7, 2026
1 check passed
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.

2 participants