Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add --without-tables option #78

Merged
merged 2 commits into from
Jun 13, 2024
Merged

✨ add --without-tables option #78

merged 2 commits into from
Jun 13, 2024

Conversation

techouse
Copy link
Owner

@techouse techouse commented Jun 10, 2024

Description

This PR adds the option --without-tables which enables a user to skip table creation and transfer only data.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

CLI and function tests.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@techouse techouse added the enhancement New feature or request label Jun 10, 2024
@techouse techouse self-assigned this Jun 10, 2024
Copy link

coderabbitai bot commented Jun 10, 2024

Walkthrough

The mysql2sqlite tool has been updated to version 2.1.12, introducing a new CLI option -Z, --without-tables to focus on data transfer without table structures. This update includes changes to the CLI, transporter logic, and tests to support the new functionality, ensuring robust error handling and accurate data migration.

Changes

Files Change Summary
README.md, docs/README.rst Added documentation for the new -Z, --without-tables option.
src/mysql_to_sqlite3/cli.py Introduced -Z/--without-tables option and updated CLI logic to handle the new parameter.
src/mysql_to_sqlite3/transporter.py Modified parameter handling and transfer logic to support without_tables and without_data.
src/mysql_to_sqlite3/types.py Added new without_tables parameter to MySQLtoSQLiteParams and _without_tables attribute.
tests/func/mysql_to_sqlite3_test.py Added test_without_tables_and_without_data to verify behaviour with the new option.
tests/func/test_cli.py Added test_without_data and test_without_tables to test CLI interactions with new options.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Transporter
    participant MySQL
    participant SQLite

    User->>CLI: Execute mysql2sqlite with -Z/--without-tables
    CLI->>Transporter: Pass parameters including without_tables=True
    Transporter->>MySQL: Fetch data without table structures
    MySQL-->>Transporter: Return data
    Transporter->>SQLite: Insert data into existing tables
    SQLite-->>Transporter: Confirm data insertion
    Transporter-->>CLI: Transfer complete
    CLI-->>User: Success message
Loading

Poem

In the realm of data's flow,
Where tables used to grow,
Now a new flag leads the way,
-Z to clear the fray.
Transfer data, pure and bright,
No tables in sight,
A rabbit's joy, in code's delight! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@techouse techouse marked this pull request as ready for review June 10, 2024 19:14
Copy link

codecov bot commented Jun 10, 2024

Codecov Report

Attention: Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.07%. Comparing base (9af779f) to head (6954d35).

Files Patch % Lines
src/mysql_to_sqlite3/cli.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #78      +/-   ##
==========================================
+ Coverage   87.04%   87.07%   +0.02%     
==========================================
  Files           8        8              
  Lines         579      588       +9     
==========================================
+ Hits          504      512       +8     
- Misses         75       76       +1     

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Outside diff range and nitpick comments (4)
README.md (1)

34-34: Update the copyright year to maintain accuracy.

Consider updating the copyright year to reflect the current year, ensuring that the documentation remains accurate and up-to-date.

src/mysql_to_sqlite3/transporter.py (3)

60-60: Ensure consistent use of default values and boolean conversions.

The code consistently uses a pattern of kwargs.get("key", default) or default for default values and boolean conversions. This is generally fine, but be aware that it can lead to unexpected behaviour if kwargs.get("key") returns a value that Python evaluates to False (like 0, '', [], etc.), even if it's a valid value. Consider using a more explicit check if this could be a concern.

Also applies to: 62-62, 68-68, 71-71, 82-82, 84-87, 89-90, 92-93, 95-95, 101-101, 103-103, 105-105, 120-120


Line range hint 305-308: Refactor to use contextlib.suppress for cleaner exception handling.

Instead of using a try-except-pass block, use contextlib.suppress to ignore exceptions. This makes the code cleaner and more Pythonic.

- try:
-     return column_type.decode()
- except (UnicodeDecodeError, AttributeError):
-     pass
+ from contextlib import suppress
+ with suppress(UnicodeDecodeError, AttributeError):
+     return column_type.decode()

Line range hint 359-368: Simplify nested if statements.

The nested if statements can be combined into a single if statement for clarity and reduced complexity.

- if index["primary"] in {1, "1"}:
-     if (index["auto_increment"] not in {1, "1"}) or any(
-         self._translate_type_from_mysql_to_sqlite(
-             column_type=_type,
-             sqlite_json1_extension_enabled=self._sqlite_json1_extension_enabled,
-         )
-         not in Integer_Types
-         for _type in types.split(",")
-     ):
-         primary += "\n\tPRIMARY KEY ({})".format(
-             ", ".join(f'"{column}"' for column in columns.split(","))
-         )
+ if index["primary"] in {1, "1"} and (index["auto_increment"] not in {1, "1"} or any(
+     self._translate_type_from_mysql_to_sqlite(
+         column_type=_type,
+         sqlite_json1_extension_enabled=self._sqlite_json1_extension_enabled,
+     )
+     not in Integer_Types
+     for _type in types.split(",")
+ )):
+     primary += "\n\tPRIMARY KEY ({})".format(
+         ", ".join(f'"{column}"' for column in columns.split(","))
+     )
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9af779f and 6954d35.

Files selected for processing (7)
  • README.md (3 hunks)
  • docs/README.rst (1 hunks)
  • src/mysql_to_sqlite3/cli.py (4 hunks)
  • src/mysql_to_sqlite3/transporter.py (5 hunks)
  • src/mysql_to_sqlite3/types.py (2 hunks)
  • tests/func/mysql_to_sqlite3_test.py (1 hunks)
  • tests/func/test_cli.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • docs/README.rst
Additional context used
LanguageTool
README.md

[locale-violation] ~5-~5: license must be spelled with a “c” when used as a noun in British English. Use “licence”. (LICENCE_LICENSE_NOUN_SINGULAR)
Context: ...10.2+|+10.3+|+10.4+|+10.5&color=C0765A) [![GitHub license](https://img.shields.io/github/license/...

Markdownlint
README.md

20-20: Expected: h2; Actual: h4 (MD001, heading-increment)
Heading levels should only increment by one level at a time


20-20: Punctuation: '.' (MD026, no-trailing-punctuation)
Trailing punctuation in heading


31-31: null (MD040, fenced-code-language)
Fenced code blocks should have a language specified

Ruff
src/mysql_to_sqlite3/transporter.py

305-308: Use contextlib.suppress(UnicodeDecodeError, AttributeError) instead of try-except-pass (SIM105)

Replace with contextlib.suppress(UnicodeDecodeError, AttributeError)


359-368: Use a single if statement instead of nested if statements (SIM102)

Additional comments not posted (4)
src/mysql_to_sqlite3/cli.py (1)

96-100: The new CLI option is well-integrated and documented.

The addition of the --without-tables option is clear and follows the existing pattern of CLI options. The help message is concise and informative.

README.md (1)

63-63: The new CLI options are well-documented in the README.

The addition of the -Z, --without-tables and -W, --without-data options are clearly documented, providing users with straightforward guidance on their usage.

tests/func/test_cli.py (2)

222-248: Ensure comprehensive testing of the --without-data option.

The test case for the --without-data option is well-constructed, ensuring that the functionality behaves as expected when this option is used.


249-295: Validate the functionality of the --without-tables option through testing.

The test case for the --without-tables option is thorough, covering scenarios where tables are not transferred. This ensures that the new functionality is robust and behaves as intended.

tests/func/mysql_to_sqlite3_test.py Show resolved Hide resolved
src/mysql_to_sqlite3/transporter.py Show resolved Hide resolved
src/mysql_to_sqlite3/types.py Show resolved Hide resolved
src/mysql_to_sqlite3/types.py Show resolved Hide resolved
src/mysql_to_sqlite3/cli.py Show resolved Hide resolved
@techouse techouse merged commit 435af97 into master Jun 13, 2024
73 checks passed
@techouse techouse deleted the feat/without-tables branch June 13, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant