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

Include unique constraints in the database backup #2695

Merged
merged 3 commits into from May 13, 2024

Conversation

stefannica
Copy link
Contributor

@stefannica stefannica commented May 10, 2024

Describe changes

The database backup feature did not include unique constraints in the database backup. This PR fixes this issue as well as includes a couple of other side changes:

  • improvements to how database backup and restore is tested in the CI to catch issues earlier
  • fixed an error during database initialization caused by unguarded analytics code that only happens if you connect the ZenML client directly to a database in 0.57.0 and later

Pre-requisites

Please ensure you have done the following:

  • I have read the CONTRIBUTING.md document.
  • If my change requires a change to docs, I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have based my new branch on develop and the open PR is targeting develop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.
  • If my changes require changes to the dashboard, these changes are communicated/requested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (add details above)

Summary by CodeRabbit

  • New Features

    • Enhanced database backup and restoration commands with additional parameters for improved control.
    • Updated analytics opt-in logic to handle different contexts more effectively.
    • Improved handling of secret store configurations in database settings.
    • Enhanced table creation in database migrations to include all unique constraints.
  • Bug Fixes

    • Fixed an issue where analytics settings were not correctly determined in server environments.

@github-actions github-actions bot added internal To filter out internal PRs and issues bug Something isn't working labels May 10, 2024
Copy link
Contributor

coderabbitai bot commented May 10, 2024

Walkthrough

Walkthrough

The recent updates enhance functionality across various scripts and modules in the ZenML framework. Modifications include improved handling of analytics settings, refined database backup and restore commands, and the inclusion of unique constraints in database migrations. These changes aim to streamline operations and ensure data integrity within the ZenML ecosystem.

Changes

File Path Change Summary
scripts/test-migrations.sh Added parameters to pipeline and database commands for enhanced testing capabilities.
.../analytics/context.py Updated handling of analytics opt-in settings to differentiate server context.
.../zen_stores/base_zen_store.py Refined logic for determining secrets store type in SqlZenStore.
.../zen_stores/migrations/utils.py Enhanced schema extraction process to include all unique constraints in table creation, improving data integrity.

🐰✨
A hop, a skip, in the code we dip,
Tweaks and twirls, through data swirls,
With each command, more robust it stands,
ZenML's charm, safe and sound, profound!
🌟📜


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@stefannica
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented May 10, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@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: 1

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2cbb695 and 01177c6.
Files selected for processing (4)
  • scripts/test-migrations.sh (2 hunks)
  • src/zenml/analytics/context.py (1 hunks)
  • src/zenml/zen_stores/base_zen_store.py (1 hunks)
  • src/zenml/zen_stores/migrations/utils.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/zenml/zen_stores/migrations/utils.py
Additional Context Used
ShellCheck (5)
scripts/test-migrations.sh (5)

[info] 197-197: Not following: .venv-upgrade/bin/activate was not specified as input (see shellcheck -x).


[error] 291-291: Argument mixes string and array. Use * or separate argument.


[error] 325-325: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).


[warning] 325-325: Remove quotes from right-hand side of =~ to match as a regex rather than literally.


[error] 351-351: Argument mixes string and array. Use * or separate argument.

Path-based Instructions (2)
src/zenml/analytics/context.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

src/zenml/zen_stores/base_zen_store.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

Additional comments not posted (2)
scripts/test-migrations.sh (1)

121-150: Enhancements to database backup and restore commands approved.

The addition of --size 5000 and --overwrite flags improves the testing process by allowing more extensive testing and safer operations in a controlled environment.

src/zenml/zen_stores/base_zen_store.py (1)

381-382: Proper handling of potential None value in secrets_store configuration.

The addition of a conditional check before accessing the type attribute of secrets_store prevents runtime errors and enhances the robustness of the code.

Comment on lines +79 to +89
try:
gc = GlobalConfiguration()
store_info = gc.zen_store.get_store_info()

if self.in_server:
self.analytics_opt_in = store_info.analytics_enabled
else:
self.analytics_opt_in = gc.analytics_opt_in
if self.in_server:
self.analytics_opt_in = store_info.analytics_enabled
else:
self.analytics_opt_in = gc.analytics_opt_in

if not self.analytics_opt_in:
return self
if not self.analytics_opt_in:
return self
Copy link
Contributor

Choose a reason for hiding this comment

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

Add logging for exceptions in the try block.

+            logger.error(f"Failed to initialize analytics context: {e}")

This will help in debugging by providing visibility into what specific errors are occurring during initialization.


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.

Suggested change
try:
gc = GlobalConfiguration()
store_info = gc.zen_store.get_store_info()
if self.in_server:
self.analytics_opt_in = store_info.analytics_enabled
else:
self.analytics_opt_in = gc.analytics_opt_in
if self.in_server:
self.analytics_opt_in = store_info.analytics_enabled
else:
self.analytics_opt_in = gc.analytics_opt_in
if not self.analytics_opt_in:
return self
if not self.analytics_opt_in:
return self
try:
gc = GlobalConfiguration()
store_info = gc.zen_store.get_store_info()
if self.in_server:
self.analytics_opt_in = store_info.analytics_enabled
else:
self.analytics_opt_in = gc.analytics_opt_in
if not self.analytics_opt_in:
return self
logger.error(f"Failed to initialize analytics context: {e}")

@strickvl strickvl requested a review from avishniakov May 13, 2024 09:14
@stefannica stefannica merged commit 51af865 into develop May 13, 2024
55 of 56 checks passed
@stefannica stefannica deleted the bug/ossk-461-backup-unique-constraints branch May 13, 2024 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working internal To filter out internal PRs and issues run-slow-ci
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants