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 OpenSearch Support to Golang Migrate #1175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mtfelisb
Copy link

@mtfelisb mtfelisb commented Sep 24, 2024

This PR adds support for OpenSearch as a new database driver in the migrate tool.

Key aspects of the implementation include:

  • Driver Implementation: Created the OpenSearch struct that implements the database.Driver interface.
  • Migration Methods: Added support for Run, Version, Drop, and etc methods using the OpenSearch API. Plus WithInstance.
  • Versioning: Versioning is handled through an index.
  • Lock Mechanism: Implemented using a dedicated index in OpenSearch. The Lock method creates a unique entry in this index, ensuring only one migration runs at a time. It uses optimistic locking to prevent race conditions—if another process holds the lock, migration fails, maintaining data integrity.
  • Integration Tests: Integration tests ensure compatibility with OpenSearch 2x and 1x.
  • Documentation Updates: Added instructions for OpenSearch usage.

Note: It's highly recommended to thoroughly test this in a non-production environment first, as the user assumes full responsibility for its usage and outcome.

@mtfelisb mtfelisb changed the title Add OpenSearch database Add OpenSearch Support to Golang Migrate Sep 24, 2024
@digi0pz
Copy link

digi0pz commented Oct 12, 2024

Following this.
Would love to see this merged into the library.


const MigrationVersionDocId = "migration_version" // The id of a document used as a lock
const DefaultTimeout = 1 * time.Minute // Default operations timeout
const DefaultIndex = ".migrations" // Default index to handle migrations
Copy link

@digi0pz digi0pz Oct 12, 2024

Choose a reason for hiding this comment

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

Would it be a good idea to give the users the configuration to set the default index name?

Copy link
Author

Choose a reason for hiding this comment

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

Hi, @digi0pz! It's possible by the standard conn string. opensearch://user:password@host:port/index

@mtfelisb mtfelisb requested a review from digi0pz November 4, 2024 23:11
@mtfelisb
Copy link
Author

mtfelisb commented Nov 4, 2024

Hi, @dhui! Maybe can you help us with a review? :)

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