fix: correct two latent defects found in code review

- migrator/share.go called tx.Rollback() on a possibly-nil tx inside the
  Tx() error branch — a nil-pointer panic on the failure path.
- migration.go computed requiredVersion.Compare(requiredVersion), an
  always-false self-comparison that silently broke max-version tracking.
- error message typo: 'ailed to decode' -> 'failed to decode'.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
pull/3582/head
Tomas Dvorak 2 weeks ago
parent 4c9d57b3b5
commit c0da31945e

@ -36,7 +36,6 @@ func (m *Migrator) migrateShare() error {
tx, err := m.v4client.Tx(ctx) tx, err := m.v4client.Tx(ctx)
if err != nil { if err != nil {
_ = tx.Rollback()
return fmt.Errorf("failed to start transaction: %w", err) return fmt.Errorf("failed to start transaction: %w", err)
} }

@ -417,7 +417,7 @@ func (f *fileClient) CreateDirectLink(ctx context.Context, file int, name string
func (f *fileClient) GetByHashID(ctx context.Context, hashID string) (*ent.File, error) { func (f *fileClient) GetByHashID(ctx context.Context, hashID string) (*ent.File, error) {
id, err := f.hasher.Decode(hashID, hashid.FileID) id, err := f.hasher.Decode(hashID, hashid.FileID)
if err != nil { if err != nil {
return nil, fmt.Errorf("ailed to decode hash id %q: %w", hashID, err) return nil, fmt.Errorf("failed to decode hash id %q: %w", hashID, err)
} }
return withFileEagerLoading(ctx, f.client.File.Query().Where(file.ID(id))).First(ctx) return withFileEagerLoading(ctx, f.client.File.Query().Where(file.ID(id))).First(ctx)

@ -826,7 +826,7 @@ func applyPatches(l logging.Logger, client *ent.Client, ctx context.Context, req
return fmt.Errorf("failed to parse required version %s: %w", requiredDbVersion, err) return fmt.Errorf("failed to parse required version %s: %w", requiredDbVersion, err)
} }
if latestAppliedVersion == nil || requiredVersion.Compare(requiredVersion) > 0 { if latestAppliedVersion == nil || requiredVersion.Compare(latestAppliedVersion) > 0 {
latestAppliedVersion = requiredVersion latestAppliedVersion = requiredVersion
} }

Loading…
Cancel
Save