Skip to content

Comments

Add table selection support in persist pull command#421

Merged
TharmiganK merged 11 commits intomainfrom
add-table-selection
Nov 25, 2025
Merged

Add table selection support in persist pull command#421
TharmiganK merged 11 commits intomainfrom
add-table-selection

Conversation

@TharmiganK
Copy link
Contributor

@TharmiganK TharmiganK commented Nov 21, 2025

Purpose

Spec Issue: ballerina-platform/ballerina-spec#1400

Fixes: ballerina-platform/ballerina-library#8468

Examples

Example 1: Explicit Selection with Auto-Inclusion

$ bal persist pull --datastore mysql --host localhost --port 3306 \
    --user root --database mydb --tables=album_ratings

Database Password: ****
INFO: Automatically including table 'albums' due to foreign key relationship from 'album_ratings'
Introspection complete! The model.bal file created successfully.

Example 2: Interactive Mode

$ bal persist pull --datastore mysql --host localhost --port 3306 \
    --user root --database mydb --tables

Database Password: ****

Available tables in the database:
──────────────────────────────────
  1. users
  2. orders
  3. products
  4. categories
  5. reviews
──────────────────────────────────
Total: 5 tables

Select tables to introspect:
  • Enter table names separated by commas (e.g., users,orders,products)
  • Enter table numbers separated by commas (e.g., 1,3,5)
  • Enter 'all' to introspect all tables
  • Press Enter without input to introspect all tables
  • Enter 'q' or 'quit' to abort

Your selection: 2,3
INFO: Automatically including table 'users' due to foreign key relationship from 'orders'
Introspection complete! The model.bal file created successfully.

Checklist

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

TharmiganK and others added 7 commits November 21, 2025 03:13
- Introduced the `--tables` option to allow users to specify a comma-separated list of tables for introspection.
- Updated documentation and help files to reflect the new option.
- Added tests to verify the functionality of the `--tables` option.
- Implemented interactive mode for selecting tables during introspection.
- Updated documentation to reflect new table selection options.
- Enhanced help command with detailed usage instructions for the --tables flag.
…ables via foreign keys and update documentation accordingly
@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

❌ Patch coverage is 84.56376% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.22%. Comparing base (dd568c2) to head (95c5b39).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...i/src/main/java/io/ballerina/persist/cmd/Pull.java 73.84% 9 Missing and 8 partials ⚠️
.../io/ballerina/persist/introspect/Introspector.java 93.58% 2 Missing and 3 partials ⚠️
...na/persist/configuration/PersistConfiguration.java 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
+ Coverage   86.21%   86.22%   +0.01%     
==========================================
  Files          66       66              
  Lines        6393     6514     +121     
  Branches      844      868      +24     
==========================================
+ Hits         5512     5617     +105     
- Misses        641      647       +6     
- Partials      240      250      +10     

☔ 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.

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 PR adds table selection support to the bal persist pull command, allowing users to introspect specific database tables instead of all tables. The feature includes both explicit table specification via --tables=table1,table2 and an interactive mode triggered by --tables without a value. A key enhancement is automatic inclusion of tables referenced by foreign keys to ensure valid model generation.

Key Changes

  • Added --tables command-line option with support for comma-separated table names or interactive selection mode
  • Implemented foreign key dependency resolution that automatically includes referenced tables with informational logging
  • Created interactive table selection UI that displays up to 50 tables and supports selection by name, index, or 'all' keyword

Reviewed Changes

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

Show a summary per file
File Description
persist-tool/README.md Documents the new --tables option with usage examples for explicit and interactive modes
persist-cli/src/main/resources/cli-help/ballerina-persist-pull.help Adds comprehensive help documentation for table selection feature including interactive mode instructions
persist-cli/src/main/java/io/ballerina/persist/cmd/Pull.java Implements the --tables option, interactive table selection UI, and index-to-name parsing logic
persist-cli/src/main/java/io/ballerina/persist/configuration/PersistConfiguration.java Adds selectedTables field with getter/setter for storing user's table selection
persist-cli/src/main/java/io/ballerina/persist/introspect/Introspector.java Implements table filtering logic and foreign key dependency resolution to auto-include referenced tables
persist-cli/src/main/java/io/ballerina/persist/introspect/PostgreSqlIntrospector.java Adds class-level Javadoc documentation
persist-cli/src/main/java/io/ballerina/persist/introspect/MySqlIntrospector.java Adds class-level Javadoc documentation
persist-cli/src/main/java/io/ballerina/persist/introspect/MsSqlInstrospector.java Adds class-level Javadoc documentation
persist-cli-tests/src/test/java/io/ballerina/persist/tools/ToolingDbPullTest.java Adds comprehensive test cases for table selection, interactive mode, and foreign key auto-inclusion
persist-cli-tests/src/test/resources/test-src/input/tool_test_pull_tables_mysql/ Test input data for table selection feature
persist-cli-tests/src/test/resources/test-src/output/tool_test_pull_tables_mysql/ Expected output for table selection tests
persist-cli-tests/src/test/resources/test-src/input/tool_test_pull_fk_auto_include_mysql/ Test input data for foreign key auto-inclusion
persist-cli-tests/src/test/resources/test-src/output/tool_test_pull_fk_auto_include_mysql/ Expected output for foreign key auto-inclusion test
docs/spec/spec.md Updates specification with table selection behavior and interactive mode details
changelog.md Documents the new feature addition

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

@sonarqubecloud
Copy link

@TharmiganK TharmiganK marked this pull request as ready for review November 21, 2025 10:19
Copy link
Member

@daneshk daneshk left a comment

Choose a reason for hiding this comment

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

LGTM

@TharmiganK TharmiganK merged commit 6a97449 into main Nov 25, 2025
5 of 6 checks passed
@TharmiganK TharmiganK deleted the add-table-selection branch November 25, 2025 14:38
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.

Provide an option to configure the tables to be introspected when using ballerina persist tool

2 participants