employee-dev-13-BE-add-ticket-table-back#208
Conversation
There was a problem hiding this comment.
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
DatabaseConfigclass that uses aCommandLineRunnerto ensure theticketstable 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
Ticketentity to useLONGTEXTfor the description column definition and addedcreatedAtandupdatedAtfields with@CreationTimestampand@UpdateTimestampannotations for automatic timestamp management. TheTicketDtowas also updated to include these timestamp fields. - Improved Update Logic: Refactored the
updateTicketmethod inTicketServiceto 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.propertiesto use theMySQL8Dialect, enabledshow-sqlandformat_sqlfor better debugging, and added trace logging for SQL parameter binding. - Sample Data: Added a
data.sqlfile to initialize sample ticket statuses, tags (usingINSERT IGNOREintooption_schema), and sample tickets (usingINSERT IGNOREintotickets) on application startup. - Basic JPA Test: Added a
DatabaseConfigTestusing@DataJpaTestto verify that theTicketentity can be persisted and retrieved via theTicketRepository, 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
-
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. ↩
There was a problem hiding this comment.
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.
| "user_id INT," + | ||
| "assigned_to INT," + |
There was a problem hiding this comment.
| 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;"; |
There was a problem hiding this comment.
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.
| * Fixed to work with both MySQL 5 and MySQL 8 for auto table creation. | ||
| */ |
There was a problem hiding this comment.
No description provided.