Skip to content

Add order automation sample - #142

Open
pasindufernando1 wants to merge 1 commit into
wso2:mainfrom
pasindufernando1:orderAutomation
Open

Add order automation sample#142
pasindufernando1 wants to merge 1 commit into
wso2:mainfrom
pasindufernando1:orderAutomation

Conversation

@pasindufernando1

Copy link
Copy Markdown

Purpose

Add order automation sample

Copilot AI review requested due to automatic review settings June 23, 2026 08:13
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Overview

This pull request adds a complete order management automation sample to the integration-samples repository. The sample demonstrates a scheduled automation workflow that processes customer orders using Ballerina.

Changes

Added a new order-management-automation sample under integrator-default-profile/samples/ containing:

Project Configuration

  • Workspace and package configuration files (Ballerina.toml, Dependencies.toml, .choreo/context.yaml)
  • Build and dependency management setup with persistence and email integration

Automation Logic

  • Main automation function that polls a MySQL database for orders in PLACED status, updates them to PROCESSING, and sends customer notification emails via SMTP
  • Database and email connection setup with configurable credentials
  • Error handling and logging throughout the automation workflow

Data Models

  • SQL-backed persistence models for Order, Customer, and Product entities with proper relationships and field definitions
  • Type definitions for order processing workflows

Documentation & Configuration

  • Comprehensive README with prerequisites, database schema setup (SQL scripts), configuration instructions, and run/reset procedures
  • Configuration file template for database and SMTP server credentials
  • .gitignore for build artifacts and development files

Impact

This sample provides a complete, runnable example of an order processing automation that integrates database operations with email notifications, serving as a reference for building similar integration workflows.

Walkthrough

A new Ballerina sample, orderprocessingautomation, is added under integrator-default-profile/samples/order-management-automation. The sample defines a main() function that queries a MySQL orders_db for orders in PLACED status, updates each to PROCESSING, and sends a notification email per order via SMTP. The package includes SQL-backed persist models (Order, Customer, Product), composite query types, configurable connection variables, module-level client instantiation, a complete Dependencies.toml, workspace and Choreo context configuration, and a README with SQL setup scripts and run instructions.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete and does not follow the provided template. Only the 'Purpose' section contains minimal text; all other required sections are missing. Complete the pull request description by filling in all required template sections including Goals, Approach, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, Test environment, and Learning.
Title check ❓ Inconclusive The title 'Add order automation sample' is a generic description that partially relates to the changeset but lacks specificity about the primary change. Consider a more specific title that captures the main technical component, such as 'Add order-management-automation sample with scheduled polling' or 'Add order processing automation with database and email integration'.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Ballerina sample package under integrator-default-profile/samples/order-management-automation that demonstrates reading “PLACED” orders from MySQL (via Persist), emailing customers, and advancing orders to “PROCESSING”.

Changes:

  • Introduces a new Ballerina package (orderprocessingautomation) with Persist model + automation logic.
  • Adds documentation and workspace metadata for running the sample.
  • Adds Choreo context metadata for the sample workspace.

Reviewed changes

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

Show a summary per file
File Description
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/automation.bal Implements the order-processing loop (read placed orders, email, update status, log).
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/connections.bal Creates MySQL (Persist) and SMTP clients from configurable values.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/types.bal Defines record types used to represent orders and related entities.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/persist/ordersDB/model.bal Defines Persist entity model for orders/customers/products.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/config.bal Adds configurable DB + SMTP settings.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/README.md Documents setup (DB schema seed), configuration, and how to run the sample.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Ballerina.toml Defines the package and Persist tool configuration.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Dependencies.toml Locks dependency versions for the new package.
integrator-default-profile/samples/order-management-automation/Ballerina.toml Adds a workspace definition for the sample.
integrator-default-profile/samples/order-management-automation/.choreo/context.yaml Adds Choreo project context metadata.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/.gitignore Ignores build output and local config files for the sample.
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/main.bal Currently empty module file (added by template).
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/functions.bal Currently empty module file (added by template).
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/data_mappings.bal Currently empty module file (added by template).
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/agents.bal Currently empty module file (added by template).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


final ordersdb:Client ordersDB = check new (ordersDBHost, ordersDBPort, ordersDBUser, ordersDBPassword, ordersDBDatabase);

final email:SmtpClient emailSmtpclient = check new (string `${emailHost}`, string `${emailUserName}`, string `${emailPassword}`, port = emailPort, security = "START_TLS_NEVER");
PlacedOrdersProductType product;
|};

public type PlacedOrdersCustomerType record {|
string name;
string email;
string address;
|};
string address;
|};

public type PlacedOrdersProductType record {|
string productName;
string category;
decimal price;
|};
Comment on lines +13 to +18
ordersdb:Order updatedOrder = check ordersDB->/orders/[placedOrder.orderId].put({status: "PROCESSING"});
check emailSmtpclient->sendMessage({
to: placedOrder.customer.email,
subject: placedOrder.orderId + ": status update",
body: "Your order bearing id :" + placedOrder.orderId + " is now under process"
});
[[dependency]]
org = "ballerina"
name = "tool.persist"
version = "1.9.1"
Comment on lines +1 to +3
- org: pasindufernando
project: order-management-automation
local: true
configurable string emailHost = "127.0.0.1";
configurable string emailUserName = "orders@example.com";
configurable string emailPassword = ?;
configurable int emailPort = 2525; No newline at end of file
@@ -0,0 +1,106 @@
# Order Management Automation

A scheduled automation that processes newly placed orders. On each run it reads every order still in the `PLACED` state from a MySQL `orders_db`, emails the customer that their order is being handled, advances the order to `PROCESSING`, and logs a summary. When nothing is waiting, the run exits early.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (1)
integrator-default-profile/samples/order-management-automation/orderprocessingautomation/README.md (1)

79-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Clarify Config.toml example for local vs. external SMTP.

The Configuration example shows emailHost = "smtp.example.com" and emailPort = 465, which align with external SMTP services. However, the documented prerequisites describe a local setup (MySQL on localhost), and the actual default configuration in code uses 127.0.0.1:2525 (local test SMTP). Users following the README may be confused about whether to use the example values or the defaults. Either align the example with the documented local defaults or explicitly state when the example is for external SMTP and explain the difference.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/README.md`
around lines 79 - 89, The Configuration section in the README shows a
Config.toml example with external SMTP values (emailHost = "smtp.example.com"
and emailPort = 465), but this conflicts with the actual code defaults which use
local test SMTP (127.0.0.1:2525). Update the Config.toml example block to either
replace the external SMTP values with the local defaults (127.0.0.1 and port
2525) that match the code implementation, or alternatively add two separate
configuration examples clearly labeled "Local Development Setup" and "External
SMTP Setup" with explanations of when to use each, ensuring users understand
which values to use for their environment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/automation.bal`:
- Around line 13-18: The order status is being updated to "PROCESSING" before
the email notification is sent, which causes an inconsistent state if the email
sending fails. Reorder the operations by moving the
emailSmtpclient->sendMessage() call before the
ordersDB->/orders/[placedOrder.orderId].put() call. This ensures the email is
sent first, and only if successful does the order status transition to
"PROCESSING", preserving the ability to retry the entire operation without
leaving the system in an inconsistent state.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Ballerina.toml`:
- Around line 19-22: The version field for the tool.persist dependency in the
dependency block does not match the resolved version in Dependencies.toml.
Update the version property of the tool.persist dependency from "1.9.1" to
"1.9.2" to ensure consistency between Ballerina.toml and the actual resolved
dependency version, which improves reproducibility and prevents version
mismatches.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/connections.bal`:
- Line 7: The SMTP security mode is hardcoded as "START_TLS_NEVER" in the
emailSmtpclient initialization, while other connection parameters like
emailHost, emailPort, emailUserName, and emailPassword are configurable. Extract
the hardcoded security value into a configurable variable (e.g., emailSecurity)
defined in config.bal alongside the other email configuration parameters, then
replace "START_TLS_NEVER" in the emailSmtpclient initialization with this new
configurable variable to allow different security modes for different deployment
environments.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/persist/ordersDB/model.bal`:
- Line 8: The Ballerina model defines ID fields with `@sql`:Varchar {length: 36},
but the database schema specifies VARCHAR(20) for order_id, customer_id, and
product_id. Update all three ID field annotations to use length: 20 instead of
length: 36 to match the SQL schema definition and prevent data truncation. This
applies to the annotations on the order_id field, customer_id field, and
product_id field in the model.
- Line 33: The `@sql`:Varchar annotation on the customerId field specifies a
length of 36, but the actual database schema defines the customer_id column as
VARCHAR(20), creating a mismatch. Update the length parameter in the
`@sql`:Varchar annotation for the customerId field to match the database schema
definition of 20 characters instead of 36. This ensures the model definition is
consistent with the underlying database constraints.
- Line 47: The productId field in the model has an `@sql`:Varchar annotation with
length set to 36, but the corresponding database column product_id is defined as
VARCHAR(20). Update the length parameter in the `@sql`:Varchar annotation from 36
to 20 to ensure the model definition matches the actual database schema
definition.

---

Nitpick comments:
In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/README.md`:
- Around line 79-89: The Configuration section in the README shows a Config.toml
example with external SMTP values (emailHost = "smtp.example.com" and emailPort
= 465), but this conflicts with the actual code defaults which use local test
SMTP (127.0.0.1:2525). Update the Config.toml example block to either replace
the external SMTP values with the local defaults (127.0.0.1 and port 2525) that
match the code implementation, or alternatively add two separate configuration
examples clearly labeled "Local Development Setup" and "External SMTP Setup"
with explanations of when to use each, ensuring users understand which values to
use for their environment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e7b35d30-2a8c-4a43-a6b4-46be15515c77

📥 Commits

Reviewing files that changed from the base of the PR and between 017f912 and 578df3a.

📒 Files selected for processing (15)
  • integrator-default-profile/samples/order-management-automation/.choreo/context.yaml
  • integrator-default-profile/samples/order-management-automation/Ballerina.toml
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/.gitignore
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Ballerina.toml
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Dependencies.toml
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/README.md
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/agents.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/automation.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/config.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/connections.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/data_mappings.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/functions.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/main.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/persist/ordersDB/model.bal
  • integrator-default-profile/samples/order-management-automation/orderprocessingautomation/types.bal

Comment on lines +13 to +18
ordersdb:Order updatedOrder = check ordersDB->/orders/[placedOrder.orderId].put({status: "PROCESSING"});
check emailSmtpclient->sendMessage({
to: placedOrder.customer.email,
subject: placedOrder.orderId + ": status update",
body: "Your order bearing id :" + placedOrder.orderId + " is now under process"
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reorder processing at Line 13-18: send notification before status transition.

The current flow updates the order to PROCESSING before sending the email. If sending fails, the order state is already advanced, which breaks the intended processing contract and retry behavior.

Proposed change
         foreach PlacedOrdersType placedOrder in placedOrders {
-            ordersdb:Order updatedOrder = check ordersDB->/orders/[placedOrder.orderId].put({status: "PROCESSING"});
             check emailSmtpclient->sendMessage({
                 to: placedOrder.customer.email,
                 subject: placedOrder.orderId + ": status update",
                 body: "Your order bearing id :" + placedOrder.orderId + " is now under process"
             });
+            ordersdb:Order updatedOrder = check ordersDB->/orders/[placedOrder.orderId].put({status: "PROCESSING"});
             log:printInfo(string `Order advanced to PROCESSING: ${updatedOrder.orderId}`);
         }

As per path instructions, this focuses on correctness and high-level safety behavior without speculative detail.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ordersdb:Order updatedOrder = check ordersDB->/orders/[placedOrder.orderId].put({status: "PROCESSING"});
check emailSmtpclient->sendMessage({
to: placedOrder.customer.email,
subject: placedOrder.orderId + ": status update",
body: "Your order bearing id :" + placedOrder.orderId + " is now under process"
});
check emailSmtpclient->sendMessage({
to: placedOrder.customer.email,
subject: placedOrder.orderId + ": status update",
body: "Your order bearing id :" + placedOrder.orderId + " is now under process"
});
ordersdb:Order updatedOrder = check ordersDB->/orders/[placedOrder.orderId].put({status: "PROCESSING"});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/automation.bal`
around lines 13 - 18, The order status is being updated to "PROCESSING" before
the email notification is sent, which causes an inconsistent state if the email
sending fails. Reorder the operations by moving the
emailSmtpclient->sendMessage() call before the
ordersDB->/orders/[placedOrder.orderId].put() call. This ensures the email is
sent first, and only if successful does the order status transition to
"PROCESSING", preserving the ability to retry the entire operation without
leaving the system in an inconsistent state.

Source: Path instructions

Comment on lines +19 to +22
[[dependency]]
org = "ballerina"
name = "tool.persist"
version = "1.9.1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify tool.persist version consistency between manifests

echo "=== Ballerina.toml declared version ==="
rg -A1 'name = "tool.persist"' integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Ballerina.toml

echo "=== Dependencies.toml resolved version ==="
rg -A1 'name = "tool.persist"' integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Dependencies.toml

Repository: wso2/integration-samples

Length of output: 325


Update tool.persist version in Ballerina.toml to match the resolved version.

The declared version is 1.9.1, but Dependencies.toml resolved to 1.9.2. Update Ballerina.toml line 22 to version = "1.9.2" for consistency and reproducibility.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/Ballerina.toml`
around lines 19 - 22, The version field for the tool.persist dependency in the
dependency block does not match the resolved version in Dependencies.toml.
Update the version property of the tool.persist dependency from "1.9.1" to
"1.9.2" to ensure consistency between Ballerina.toml and the actual resolved
dependency version, which improves reproducibility and prevents version
mismatches.


final ordersdb:Client ordersDB = check new (ordersDBHost, ordersDBPort, ordersDBUser, ordersDBPassword, ordersDBDatabase);

final email:SmtpClient emailSmtpclient = check new (string `${emailHost}`, string `${emailUserName}`, string `${emailPassword}`, port = emailPort, security = "START_TLS_NEVER");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -name "connections.bal" -o -name "*.bal" | grep -E "(connections|order)" | head -20

Repository: wso2/integration-samples

Length of output: 1890


🏁 Script executed:

cat integrator-default-profile/samples/order-management-automation/orderprocessingautomation/connections.bal

Repository: wso2/integration-samples

Length of output: 533


🏁 Script executed:

cat -n integrator-default-profile/samples/order-management-automation/orderprocessingautomation/connections.bal

Repository: wso2/integration-samples

Length of output: 582


🏁 Script executed:

find integrator-default-profile/samples/order-management-automation -type f \( -name "*.toml" -o -name "*.bal" \) | head -30

Repository: wso2/integration-samples

Length of output: 1383


🏁 Script executed:

cat integrator-default-profile/samples/order-management-automation/Config.toml 2>/dev/null || echo "No Config.toml found"

Repository: wso2/integration-samples

Length of output: 183


🏁 Script executed:

cat -n integrator-default-profile/samples/order-management-automation/orderprocessingautomation/config.bal

Repository: wso2/integration-samples

Length of output: 639


🌐 Web query:

Ballerina email SMTP client security parameter options START_TLS STARTTLS

💡 Result:

The Ballerina email module provides robust transport-level security for SMTP clients through the security enum field within the SmtpConfiguration record [1][2][3]. The available options for the security parameter are: * SSL: Uses the default TLS/SSL protocol [2][4][3]. * START_TLS_NEVER: Disables both TLS/SSL and STARTTLS, allowing only unencrypted communication [1][2][3]. * START_TLS_ALWAYS: Mandates the use of the secure STARTTLS protocol [1][2][3]. * START_TLS_AUTO: Enables STARTTLS but falls back to unencrypted communication if the server does not support STARTTLS [1][2][3]. By default, TLS/SSL is enabled [1][2][3]. For deep-level transport security configuration, such as custom certificates, you can also use the secureSocket field in your SmtpConfiguration [1][2][3]. When choosing a security mode, ensure the port number matches the protocol requirements. Common standards include: * SSL: Port 465 [1][2][3]. * STARTTLS: Port 587 [1][2][3]. * Unsecured: Ports 25 or 587 [1][2][3]. Example configuration using START_TLS_AUTO: email:SmtpConfiguration smtpConfig = { port: 587, secureSocket: { // Transport level configuration }, security: email:START_TLS_AUTO };

Citations:


Make SMTP security mode configurable at line 7.

The security = "START_TLS_NEVER" parameter is hard-coded while emailHost, emailPort, emailUserName, and emailPassword are all configurable. Since START_TLS_NEVER disables encryption, this parameter should also be configurable to enable safer transport modes for production deployments.

Proposed change
- final email:SmtpClient emailSmtpclient = check new (string `${emailHost}`, string `${emailUserName}`, string `${emailPassword}`, port = emailPort, security = "START_TLS_NEVER");
+ final email:SmtpClient emailSmtpclient = check new (
+     string `${emailHost}`,
+     string `${emailUserName}`,
+     string `${emailPassword}`,
+     port = emailPort,
+     security = emailSecurity
+ );

Add to config.bal:

+ configurable string emailSecurity = "START_TLS_NEVER";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
final email:SmtpClient emailSmtpclient = check new (string `${emailHost}`, string `${emailUserName}`, string `${emailPassword}`, port = emailPort, security = "START_TLS_NEVER");
final email:SmtpClient emailSmtpclient = check new (
string `${emailHost}`,
string `${emailUserName}`,
string `${emailPassword}`,
port = emailPort,
security = emailSecurity
);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/connections.bal`
at line 7, The SMTP security mode is hardcoded as "START_TLS_NEVER" in the
emailSmtpclient initialization, while other connection parameters like
emailHost, emailPort, emailUserName, and emailPassword are configurable. Extract
the hardcoded security value into a configurable variable (e.g., emailSecurity)
defined in config.bal alongside the other email configuration parameters, then
replace "START_TLS_NEVER" in the emailSmtpclient initialization with this new
configurable variable to allow different security modes for different deployment
environments.

Source: Path instructions

@sql:Name {value: "orders"}
public type Order record {|
@sql:Name {value: "order_id"}
@sql:Varchar {length: 36}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

Schema mismatch: VARCHAR lengths exceed database definition.

The model defines ID fields with length: 36, but the README's SQL schema specifies VARCHAR(20) for order_id, customer_id, and product_id. IDs longer than 20 characters will be truncated, causing data corruption and referential integrity violations.

🔧 Proposed fix to align with SQL schema
     `@sql`:Name {value: "order_id"}
-    `@sql`:Varchar {length: 36}
+    `@sql`:Varchar {length: 20}
     readonly string orderId;
     `@sql`:Name {value: "customer_id"}
-    `@sql`:Varchar {length: 36}
+    `@sql`:Varchar {length: 20}
     `@sql`:Index {name: "customer_id"}
     string customerId;
     `@sql`:Name {value: "product_id"}
-    `@sql`:Varchar {length: 36}
+    `@sql`:Varchar {length: 20}
     `@sql`:Index {name: "product_id"}
     string productId;

Also applies to: 11-11, 15-15

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/persist/ordersDB/model.bal`
at line 8, The Ballerina model defines ID fields with `@sql`:Varchar {length: 36},
but the database schema specifies VARCHAR(20) for order_id, customer_id, and
product_id. Update all three ID field annotations to use length: 20 instead of
length: 36 to match the SQL schema definition and prevent data truncation. This
applies to the annotations on the order_id field, customer_id field, and
product_id field in the model.

@sql:Name {value: "customers"}
public type Customer record {|
@sql:Name {value: "customer_id"}
@sql:Varchar {length: 36}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

Schema mismatch: customer_id VARCHAR length exceeds database definition.

The model defines customerId with length: 36, but the SQL schema specifies VARCHAR(20). Ensure consistency with the database schema.

🔧 Proposed fix
     `@sql`:Name {value: "customer_id"}
-    `@sql`:Varchar {length: 36}
+    `@sql`:Varchar {length: 20}
     readonly string customerId;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@sql:Varchar {length: 36}
`@sql`:Name {value: "customer_id"}
`@sql`:Varchar {length: 20}
readonly string customerId;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/persist/ordersDB/model.bal`
at line 33, The `@sql`:Varchar annotation on the customerId field specifies a
length of 36, but the actual database schema defines the customer_id column as
VARCHAR(20), creating a mismatch. Update the length parameter in the
`@sql`:Varchar annotation for the customerId field to match the database schema
definition of 20 characters instead of 36. This ensures the model definition is
consistent with the underlying database constraints.

@sql:Name {value: "products"}
public type Product record {|
@sql:Name {value: "product_id"}
@sql:Varchar {length: 36}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

Schema mismatch: product_id VARCHAR length exceeds database definition.

The model defines productId with length: 36, but the SQL schema specifies VARCHAR(20). Ensure consistency with the database schema.

🔧 Proposed fix
     `@sql`:Name {value: "product_id"}
-    `@sql`:Varchar {length: 36}
+    `@sql`:Varchar {length: 20}
     readonly string productId;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@sql:Varchar {length: 36}
`@sql`:Name {value: "product_id"}
`@sql`:Varchar {length: 20}
readonly string productId;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/samples/order-management-automation/orderprocessingautomation/persist/ordersDB/model.bal`
at line 47, The productId field in the model has an `@sql`:Varchar annotation with
length set to 36, but the corresponding database column product_id is defined as
VARCHAR(20). Update the length parameter in the `@sql`:Varchar annotation from 36
to 20 to ensure the model definition matches the actual database schema
definition.

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.

2 participants