Skip to content

employee-dev-13-BE-add-ticket-table-back #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yennanliu
Copy link
Owner

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @yennanliu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request re-introduces and sets up the backend components for a ticketing system. It includes the necessary database table creation logic, updates the JPA entity and DTO for tickets with timestamp fields and appropriate column types, refactors the ticket update service method for correctness, adjusts database configuration for MySQL 8 and enhanced logging, and provides initial sample data and basic repository tests.

Highlights

  • Database Initialization: Introduced a DatabaseConfig class that uses a CommandLineRunner to ensure the tickets table is created on application startup if it doesn't already exist, including defining its schema with appropriate columns and indexes.
  • Ticket Entity & DTO: Updated the Ticket entity to use LONGTEXT for the description column definition and added createdAt and updatedAt fields with @CreationTimestamp and @UpdateTimestamp annotations for automatic timestamp management. The TicketDto was also updated to include these timestamp fields.
  • Improved Update Logic: Refactored the updateTicket method in TicketService to correctly fetch the existing ticket by ID and update its fields, rather than deleting and re-saving, which preserves the original creation timestamp and entity identity.
  • Database Configuration: Updated application.properties to use the MySQL8Dialect, enabled show-sql and format_sql for better debugging, and added trace logging for SQL parameter binding.
  • Sample Data: Added a data.sql file to initialize sample ticket statuses, tags (using INSERT IGNORE into option_schema), and sample tickets (using INSERT IGNORE into tickets) on application startup.
  • Basic JPA Test: Added a DatabaseConfigTest using @DataJpaTest to verify that the Ticket entity can be persisted and retrieved via the TicketRepository, implicitly testing the table structure and repository setup.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request re-introduces the tickets table and associated functionality. Key changes include adding a CommandLineRunner for initial table creation (though alternative schema management tools are generally preferred), updating the Ticket entity with timestamp fields and LONGTEXT for description, adding these fields to the TicketDto, improving the updateTicket service method to correctly update the existing entity, configuring Hibernate for MySQL 8 and enabling SQL logging, adding sample data initialization scripts, and including a @DataJpaTest to verify the persistence layer.

Comment on lines +29 to +30
"user_id INT," +
"assigned_to INT," +

Choose a reason for hiding this comment

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

high

The SQL schema defines user_id and assigned_to as INT columns. It would be beneficial to add foreign key constraints referencing the users table (assuming one exists) to enforce referential integrity at the database level. This helps prevent orphaned tickets if users are deleted.

Comment on lines +25 to +39
String createTicketsTable = "CREATE TABLE IF NOT EXISTS tickets (" +
"id INT AUTO_INCREMENT PRIMARY KEY," +
"subject VARCHAR(255) NOT NULL," +
"description LONGTEXT," +
"user_id INT," +
"assigned_to INT," +
"status VARCHAR(50) DEFAULT 'PENDING'," +
"tag VARCHAR(100)," +
"created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
"updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," +
"INDEX idx_user_id (user_id)," +
"INDEX idx_assigned_to (assigned_to)," +
"INDEX idx_status (status)," +
"INDEX idx_created_at (created_at)" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";

Choose a reason for hiding this comment

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

medium

Using a CommandLineRunner with raw SQL for database schema management can be less maintainable than using dedicated tools like Flyway or Liquibase, or relying solely on Hibernate's ddl-auto feature combined with entity definitions. While CREATE TABLE IF NOT EXISTS makes it idempotent, managing schema changes over time (e.g., adding columns, altering types) becomes more complex with this approach compared to migration scripts.

Comment on lines +34 to 35
* Fixed to work with both MySQL 5 and MySQL 8 for auto table creation.
*/

Choose a reason for hiding this comment

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

medium

The comment mentions fixing compatibility with MySQL 5 and 8. While LONGTEXT is generally supported, relying on columnDefinition can sometimes lead to portability issues across different database systems or versions. Ensure this definition works correctly with your target database environment(s).

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