Skip to content

Commit

Permalink
Fix for converting NULL to int is unsupported error.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Feb 1, 2024
1 parent 0cab021 commit a223f28
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions internal/postgres/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,10 @@ func SetUpper(column string) string {
return "UPDATE files " +
fmt.Sprintf("SET %s = UPPER(%s);", column, column)
}

// SetFilesize0 is an SQL statement to update filesize column NULLs with 0 values.
// This is a fix for the error: failed to bind pointers to obj: sql:
// Scan error on column index 2, name "size_total": converting NULL to int is unsupported
func SetFilesize0() string {
return "UPDATE files SET filesize = 0 WHERE filesize IS NULL;"
}
4 changes: 4 additions & 0 deletions model/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func releasers(ctx context.Context, w io.Writer, db *sql.DB) error {
if err != nil {
return err
}
_, err = queries.Raw(postgres.SetFilesize0()).Exec(db)
if err != nil {
return err
}

magics, err := models.Files(qm.Where("file_magic_type ILIKE ?", "ERROR: %")).All(ctx, db)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion model/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *Releasers) All(ctx context.Context, db *sql.DB, reorder bool, limit, pa
if db == nil {
return ErrDB
}
if len(*r) > 0 {
if r != nil && len(*r) > 0 {
return nil
}
query := string(postgres.DistReleaser())
Expand Down

0 comments on commit a223f28

Please sign in to comment.