Skip to content

Conversation

Samar1110
Copy link
Contributor

Pull Request: OracleDB Migration Support Integration

Description:

  • Adds OracleDB migration support in pkg/gofr/migration/oracle.go and associated tests in oracle_test.go.
  • Provides robust unit tests with mocks covering success and failure scenarios for migration table creation, fetching last migration, commit, and transaction begin.
  • Uses Oracle driver interface methods (Exec, Select) for migration SQL execution.
  • Addresses #2015.

Details of the Change

  • Added oracleDS and oracleMigrator structs implementing migration interface for Oracle.
  • Migration table DDL and queries specific for Oracle PL/SQL with exception handling.
  • Migration lifecycle functions: checkAndCreateMigrationTable, getLastMigration, beginTransaction, commitMigration, and rollback.
  • Unit tests simulating Oracle behavior via mocks, validating all migration lifecycle operations with error and success cases.

Motivation & Benefits:

  • Enables native OracleDB support in GoFr migration framework.
  • Ensures consistent migration behavior for Oracle alongside other supported databases.
  • Improves reliability of schema migrations when using OracleDB.

Checklist:

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

@Samar1110 Samar1110 changed the title feat: Oracle db migration feat: Oracle db migration (#2015) Aug 23, 2025
Copy link
Member

@Umang01-hash Umang01-hash left a comment

Choose a reason for hiding this comment

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

@Samar1110 Here are a few changes for your PR:

  • Remove all the newly added files inside datasource/file directory (hello.txt, temp.csv, temp.json, temp.txt) as they are not related to scope of this PR and feels like uploaded by mistake.
  • The changes in file go.work.sum should also be reverted.

Select(ctx context.Context, dest any, query string, args ...any) error
Exec(ctx context.Context, query string, args ...any) error

HealthCheck(ctx context.Context) (any, error)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this method needed for migrations?

Copy link
Contributor Author

@Samar1110 Samar1110 Aug 29, 2025

Choose a reason for hiding this comment

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

Added the HealthCheck(ctx context.Context) (any, error) method to the Oracle interface in the migration package to align it with the OracleDB interface defined in the container package. Without this method, the *MockOracle generated for testing cannot be used as a container.OracleDB value, causing the compiler error:

"cannot use mockOracle (variable of type *MockOracle) as container.OracleDB value in assignment: *MockOracle does not implement container.OracleDB (missing method HealthCheck)".

As I am using

mockContainer.Oracle = mockOracle

in some functions, it takes the reference from pkg/gofr/container/datasource.go, which requires the HealthCheck method for compatibility. To resolve this, I have added the HealthCheck method in pkg/gofr/migration/interface.go.

By adding the HealthCheck method, the mock satisfies the interface requirements, ensuring type compatibility and eliminating this assignment error.

Copy link
Member

Choose a reason for hiding this comment

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

@Samar1110 I agree but if you notice many of the interfaces like SQL, Redis, Mongo, ArrangoDB etc all have HealthCheck() method not implemented yet they align with their interface definition in container.

You can see how their test have been written or implemented.

Run(migrationMap, mockContainer)
}

func TestOracleMigration_FailCreateMigrationTable(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

The tests for Oracle Migration should be placed inside oracle_test.go not here.

Copy link
Contributor Author

@Samar1110 Samar1110 Aug 29, 2025

Choose a reason for hiding this comment

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

Do I need to shift only this test -> TestOracleMigration_FailCreateMigrationTable or all test related to Oracle migration in this file to oracle_test.go ?

Copy link
Member

Choose a reason for hiding this comment

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

You should place all test related to Oracle migration in this file to oracle_test.go

}

const (
CheckAndCreateOracleMigrationTable = `
Copy link
Member

Choose a reason for hiding this comment

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

Why is this constant exported? Can we please unexport it if not needed outside of the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I would do that

@@ -207,3 +208,130 @@ func initializeClickHouseRunMocks(t *testing.T) (*MockClickhouse, *container.Con

Copy link
Member

Choose a reason for hiding this comment

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

In the method initializeClickHouseRunMocks we need to mark Oracle as nil else it's tests will fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure , I will mark it as nil

@Umang01-hash
Copy link
Member

@Samar1110 Please resolve the merge conflicts in your PR. You are near to completing this PR. Let's close it soon and if you need any help please let us know.

@Samar1110
Copy link
Contributor Author

@Samar1110 Please resolve the merge conflicts in your PR. You are near to completing this PR. Let's close it soon and if you need any help please let us know.

Sure @Umang01-hash , by today I would complete the work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants