fix(unified): in-proc SQLite data migration (#114537)
* feat: unified storage migrations integration tests * chore: add comment and adjust db path name * chore: refactor test cases into interface * fix: unified SQLite migration with SQLStore migrator * revert changes to newResourceDBProvider
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type transactionContextKey struct{}
|
||||
|
||||
// ContextWithTransaction returns a new context with the transaction stored directly.
|
||||
// This is used for SQLite migrations where the transaction needs to be shared
|
||||
// between the migration code and unified storage operations within the same process.
|
||||
func ContextWithTransaction(ctx context.Context, tx *sql.Tx) context.Context {
|
||||
return context.WithValue(ctx, transactionContextKey{}, tx)
|
||||
}
|
||||
|
||||
// TransactionFromContext retrieves the transaction from context
|
||||
func TransactionFromContext(ctx context.Context) *sql.Tx {
|
||||
if v := ctx.Value(transactionContextKey{}); v != nil {
|
||||
if tx, ok := v.(*sql.Tx); ok {
|
||||
return tx
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user