Fix the issue in table creation order#405
Conversation
There was a problem hiding this comment.
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 ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
|



Purpose
Fixes: ballerina-platform/ballerina-library#7921
Examples
Checklist