refactor(storage): drop per-upload storage_driver, use storage_config as single source

Remove w_uploads.storage_driver and route all read/write/delete paths through
storage.Active() backed by storage_config.driver. Block direct driver switches
when uploads exist; require migration task instead. Simplify migration to
cursor-based file_path iteration without per-row driver updates.
This commit is contained in:
ryan
2026-06-18 13:56:31 +08:00
parent 1f391e9ec2
commit 410ff14795
25 changed files with 512 additions and 604 deletions
-20
View File
@@ -155,26 +155,6 @@ func Active(ctx context.Context) (Driver, Backend, error) {
return activeDriver, activeBackend, nil
}
// ForDriver returns the active or pending backend for an upload record, reusing the active singleton if matched.
func ForDriver(ctx context.Context, driver Driver) (Backend, error) {
if driver == DriverS3 && mockBackend != nil {
return mockBackend, nil
}
activeDrv, activeBnd, err := Active(ctx)
if err == nil && activeDrv == driver {
return activeBnd, nil
}
cfg, err := LoadConfig(ctx)
if err != nil {
return nil, err
}
backend, err := NewBackend(ctx, cfg, driver)
if err != nil {
return nil, fmt.Errorf("storage configuration for driver %q is unavailable: %w", driver, err)
}
return backend, nil
}
type functionBackend struct {
put func(context.Context, string, io.Reader, int64, string) error
get func(context.Context, string) (*Object, error)
+1 -10
View File
@@ -70,16 +70,7 @@ func TestStorageCache(t *testing.T) {
t.Errorf("Active returned driver %v, backend %v; expected %v, %v", drv, bnd, DriverLocal, mockBnd)
}
// 5. Test ForDriver returns cached backend
bnd2, err := ForDriver(ctx, DriverLocal)
if err != nil {
t.Fatalf("ForDriver failed: %v", err)
}
if bnd2 != mockBnd {
t.Errorf("ForDriver returned backend %v, expected %v", bnd2, mockBnd)
}
// 6. Test ResetCache again
// 5. Test ResetCache again
ResetCache()
if activeConfigJSON != "" || activeDriver != "" || activeBackend != nil || !lastChecked.IsZero() {
t.Fatal("ResetCache did not clear cache variables after setting them")