diff --git a/common/apperr/types.go b/common/apperr/types.go index 7d71eca6f..5a2ebea97 100644 --- a/common/apperr/types.go +++ b/common/apperr/types.go @@ -291,7 +291,7 @@ var ( ErrBackupNotFound = ErrorWithCode("BACKUP_NOT_FOUND_ERROR", "backup not found", ErrNotFound) ErrBackupNameNotUnique = ErrorWithCode("BACKUP_NAME_NOT_UNIQUE", "backup name not unique", ErrInvalidRequest) - ErrScriptVersionAdd = ErrorWithCode("SCRIPTVERSION_DEVICE_ADD_ERROR", "failed to add script version", ErrInternal) - ErrScriptVersionList = ErrorWithCode("SCRIPTVERSION_DEVICE_LIST_ERROR", "failed to list script version", ErrInternal) - ErrScriptVersionDelete = ErrorWithCode("SCRIPTVERSION_DEVICE_DELETE_ERROR", "failed to delete script version", ErrInternal) + ErrScriptVersionAdd = ErrorWithCode("SCRIPT_VERSION_ADD_ERROR", "failed to add script version", ErrInternal) + ErrScriptVersionList = ErrorWithCode("SCRIPT_VERSION_LIST_ERROR", "failed to list script version", ErrInternal) + ErrScriptVersionDelete = ErrorWithCode("SCRIPT_VERSION_DELETE_ERROR", "failed to delete script version", ErrInternal) ) diff --git a/db/script.go b/db/script.go index a3f95115d..db5d65211 100644 --- a/db/script.go +++ b/db/script.go @@ -194,7 +194,10 @@ func (n Scripts) Update(ctx context.Context, script *Script) (err error) { ScriptId: script.Id, Sum: []byte(hex.EncodeToString(hash[:])), } - _ = n.Db.WithContext(ctx).Create(version).Error + if err = n.Db.WithContext(ctx).Create(version).Error; err != nil { + err = errors.Wrap(apperr.ErrScriptVersionAdd, err.Error()) + return + } q := `delete from script_versions where id not in ( diff --git a/migrations/20231030_145308_add_script_version.sql b/migrations/20231030_145308_add_script_version.sql index 7d75ab96a..563095765 100644 --- a/migrations/20231030_145308_add_script_version.sql +++ b/migrations/20231030_145308_add_script_version.sql @@ -9,6 +9,7 @@ create table script_versions on update cascade on delete cascade, lang scripts_lang default 'javascript'::scripts_lang not null, source text, + sum bytea, created_at timestamp with time zone default CURRENT_TIMESTAMP );