Skip to content

fix show create table with fk in other database (#1.2-dev) - #16349

Merged
mergify[bot] merged 2 commits into
matrixorigin:1.2-devfrom
YANGGMM:fix-re-fk-1.2-dev
May 23, 2024
Merged

mergify[bot] merged 2 commits into
matrixorigin:1.2-devfrom
YANGGMM:fix-re-fk-1.2-dev

Conversation

@YANGGMM

@YANGGMM YANGGMM commented May 23, 2024

Copy link
Copy Markdown
Contributor

fix show create table with fk in other database

Approved by: @ouyuanning, @heni02

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #16311

What this PR does / why we need it:

fix show create table with fk in other database

fix show create table with fk in other database

Approved by: @ouyuanning, @heni02
@YANGGMM
YANGGMM requested a review from a user May 23, 2024 06:12
@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label May 23, 2024
@mergify
mergify Bot requested a review from sukki37 May 23, 2024 06:13
@mergify mergify Bot added the kind/bug Something isn't working label May 23, 2024
@matrix-meow

Copy link
Copy Markdown
Contributor

@YANGGMM Thanks for your contributions!

Pull Request Review:

Title:

The title of the pull request is clear and concise, indicating that it fixes an issue related to showing the create table with foreign keys in another database.

Body:

The body of the pull request provides additional context by mentioning the approval of specific individuals, the type of PR (BUG), the issue it fixes (#16311), and the purpose of the PR, which is to fix showing create table with foreign keys in another database.

Changes:

  1. In the build_show.go file:

    • The change involves modifying the ConstructCreateTableSQL function call to include tableObjRef as an argument in addition to tableDef.
    • This change aims to address the issue of showing create table with foreign keys in another database.
  2. In the build_show_util.go file:

    • The ConstructCreateTableSQL function signature is updated to include tableObjRef as a parameter.
    • The logic within the function is adjusted to handle foreign keys referencing tables in different schemas correctly.
  3. In the build_show_util_test.go file:

    • A test case is updated to reflect the changes made in the ConstructCreateTableSQL function.
  4. In the create_table.test file:

    • Various SQL statements are added to create tables, insert data, create views, and show create table commands for testing purposes.

Suggestions for Improvement:

  1. Security Concern - SQL Injection Risk:

    • The code appears to construct SQL statements dynamically using string formatting. This can introduce SQL injection vulnerabilities.
    • Suggestion: Utilize parameterized queries or prepared statements to prevent SQL injection attacks. This involves using placeholders for dynamic values in SQL queries.
  2. Code Optimization - Repeated Code:

    • There is some repetition in the code related to constructing foreign key constraints for tables in the same schema versus different schemas.
    • Suggestion: Consider refactoring the code to reduce duplication and improve maintainability. You could create a helper function to handle the common logic for foreign key constraint creation.
  3. Code Readability - Formatting:

    • In the build_show_util.go file, the formatting of the code could be improved for better readability. Ensure consistent indentation and spacing throughout the file.
    • Suggestion: Maintain a consistent coding style to enhance code readability and maintainability.
  4. Testing - Comprehensive Coverage:

    • While the test case in build_show_util_test.go is updated, it's essential to ensure comprehensive test coverage for all scenarios, including edge cases and error handling.
    • Suggestion: Expand test coverage to validate the behavior of the code under various conditions to enhance reliability.
  5. Documentation - Comments:

    • The code changes involve complex logic related to foreign key constraints and schema handling. Adding comments to explain the rationale behind the changes and the logic within the functions can aid in understanding and maintenance.
    • Suggestion: Include descriptive comments to clarify the purpose of functions, parameters, and key logic blocks.

By addressing the security concern,

@mergify
mergify Bot merged commit 8ce356a into matrixorigin:1.2-dev May 23, 2024
@YANGGMM
YANGGMM deleted the fix-re-fk-1.2-dev branch June 3, 2024 07:46
@aylei aylei mentioned this pull request Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants