Skip to content

Comments

Fix the issue in table creation order#405

Merged
daneshk merged 2 commits intoballerina-platform:mainfrom
daneshk:main
Jun 17, 2025
Merged

Fix the issue in table creation order#405
daneshk merged 2 commits intoballerina-platform:mainfrom
daneshk:main

Conversation

@daneshk
Copy link
Member

@daneshk daneshk commented Jun 14, 2025

Purpose

Fixes: ballerina-platform/ballerina-library#7921

Examples

Checklist

  • Linked to an issue
  • Updated the specification
  • Updated the changelog
  • Added tests

@daneshk daneshk requested a review from Copilot June 14, 2025 19:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes issues related to the table creation order in SQL scripts generated for multiple database systems. The changes reorder DROP and CREATE statements, swap table definitions for related entities, and update foreign key constraints to ensure correct dependency resolution.

  • Reordered DROP and CREATE statements in SQL scripts for H2, PostgreSQL, MSSQL, and others.
  • Swapped table definitions (e.g., "User" and "User2") to align with dependency requirements.
  • Removed outdated foreign key constraints to avoid dependency conflicts.

Reviewed Changes

Copilot reviewed 87 out of 87 changed files in this pull request and generated no comments.

Show a summary per file
File Description
persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_108_h2/modules/entities/script.sql Adjusted DROP and CREATE order for Building, Department, and OrderItem tables
persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_107_h2/modules/entities/script.sql Reordered table creation to resolve dependency issues
persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_106/modules/postgresql_entities/script.sql Swapped table definitions for User and User2 to correct primary key assignments
persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_106/modules/mssql_entities/script.sql Mirrored changes for User and User2 in MSSQL scripts
persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_101/modules/* Removed foreign key references (ownerId) in Car tables to ensure proper table creation order
persist-cli-tests/src/test/resources/test-src/input/tool_test_generate_114/persist/model.bal, main.bal, Ballerina.toml Added test inputs and configuration to support new ordering
Comments suppressed due to low confidence (3)

persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_106/modules/postgresql_entities/script.sql:11

  • The swapping between 'User' and 'User2' table definitions can be confusing; please verify that the intended primary key constraints and dependency mappings are correctly maintained for both tables.
CREATE TABLE "User" (

persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_101/modules/postgresql_entities/script.sql:10

  • Removal of the 'ownerId' foreign key from the Car table may affect relational integrity; please ensure that the intended association is correctly handled in the new schema or elsewhere in the application.
-	"ownerId" INT NOT NULL,

persist-cli-tests/src/test/resources/test-src/output/tool_test_generate_101/modules/mssql_entities/script.sql:9

  • The removal of the 'ownerId' column and corresponding foreign key constraint in the Car table should be double-checked to ensure that the necessary relationships for data integrity are managed through another mechanism.
-	[ownerId] INT NOT NULL,

@codecov
Copy link

codecov bot commented Jun 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.81%. Comparing base (b8f7771) to head (3bb9478).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #405      +/-   ##
==========================================
+ Coverage   85.64%   85.81%   +0.17%     
==========================================
  Files          66       66              
  Lines        6227     6241      +14     
  Branches      835      838       +3     
==========================================
+ Hits         5333     5356      +23     
+ Misses        654      647       -7     
+ Partials      240      238       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link

Copy link
Member

@ayeshLK ayeshLK left a comment

Choose a reason for hiding this comment

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

LGTM

@daneshk daneshk merged commit 7402e52 into ballerina-platform:main Jun 17, 2025
6 checks 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.

Persist client generates SQL schema with incorrect table creation order, causing foreign key dependency errors

2 participants