Add table selection support in persist pull command#421
Conversation
- 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
83a8853 to
47ca312
Compare
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
--tablescommand-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.
persist-cli/src/main/java/io/ballerina/persist/introspect/Introspector.java
Show resolved
Hide resolved
persist-cli/src/main/resources/cli-help/ballerina-persist-pull.help
Outdated
Show resolved
Hide resolved
5b23834 to
df6f9d1
Compare
|



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