submissions: postgres does not support unsigned integers, so let's pretend they are signed

This commit is contained in:
Quaternions 2024-12-19 16:49:22 -08:00
parent b3ffbe4b50
commit f04ab4f653
9 changed files with 35 additions and 35 deletions

View File

@ -8,22 +8,22 @@ package model
type ValidateRequest struct {
// submission_id is passed back in the response message
SubmissionID int64
ModelID uint64
ModelVersion uint64
ValidatedModelID uint64 // optional value
ModelID int64
ModelVersion int64
ValidatedModelID int64 // optional value
}
// Create a new map
type PublishNewRequest struct {
SubmissionID int64
ModelID uint64
ModelVersion uint64
ModelID int64
ModelVersion int64
ModelName string
}
type PublishFixRequest struct {
SubmissionID int64
ModelID uint64
ModelVersion uint64
TargetAssetID uint64
ModelID int64
ModelVersion int64
TargetAssetID int64
}

View File

@ -17,7 +17,7 @@ type ScriptPolicy struct {
// Hash of the source code that leads to this policy.
// If this is a replacement mapping, the original source may not be pointed to by any policy.
// The original source should still exist in the scripts table, which can be located by the same hash.
FromScriptHash uint64
FromScriptHash int64 // postgres does not support unsigned integers, so we have to pretend
// The ID of the replacement source (ScriptPolicyReplace)
// or verbatim source (ScriptPolicyAllowed)
// or 0 (other)

View File

@ -26,7 +26,7 @@ func HashParse(hash string) (uint64, error){
type Script struct {
ID int64 `gorm:"primaryKey"`
Name string
Hash uint64
Hash int64 // postgres does not support unsigned integers, so we have to pretend
Source string
SubmissionID int64 // which submission did this script first appear in
CreatedAt time.Time

View File

@ -29,10 +29,10 @@ type Submission struct {
GameID int32
CreatedAt time.Time
UpdatedAt time.Time
Submitter uint64 // UserID
AssetID uint64
AssetVersion uint64
Submitter int64 // UserID
AssetID int64
AssetVersion int64
Completed bool // Has this version of the map been completed at least once on maptest
TargetAssetID uint64 // where to upload map fix. if the TargetAssetID is 0, it's a new map.
TargetAssetID int64 // where to upload map fix. if the TargetAssetID is 0, it's a new map.
StatusID Status
}

View File

@ -59,7 +59,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
if err != nil {
return nil, err
}
filter.AddNotNil("from_script_hash", hash)
filter.AddNotNil("from_script_hash", int64(hash)) // No type safety!
}
if params.ToScriptID.IsSet(){
filter.AddNotNil("to_script_id", params.ToScriptID.Value)
@ -80,7 +80,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
for i := 0; i < len(items); i++ {
resp = append(resp, api.ScriptPolicy{
ID: items[i].ID,
FromScriptHash: model.HashFormat(items[i].FromScriptHash),
FromScriptHash: model.HashFormat(uint64(items[i].FromScriptHash)),
ToScriptID: items[i].ToScriptID,
Policy: int32(items[i].Policy),
})
@ -127,7 +127,7 @@ func (svc *Service) GetScriptPolicy(ctx context.Context, params api.GetScriptPol
return &api.ScriptPolicy{
ID: policy.ID,
FromScriptHash: model.HashFormat(policy.FromScriptHash),
FromScriptHash: model.HashFormat(uint64(policy.FromScriptHash)),
ToScriptID: policy.ToScriptID,
Policy: int32(policy.Policy),
}, nil

View File

@ -26,7 +26,7 @@ func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*a
script, err := svc.DB.Scripts().Create(ctx, model.Script{
ID: 0,
Name: req.Name,
Hash: model.HashSource(req.Source),
Hash: int64(model.HashSource(req.Source)),
Source: req.Source,
SubmissionID: req.SubmissionID.Or(0),
})
@ -52,7 +52,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
if err != nil {
return nil, err
}
filter.AddNotNil("hash", hash)
filter.AddNotNil("hash", int64(hash)) // No type safety!
}
if params.Name.IsSet(){
filter.AddNotNil("name", params.Name.Value)
@ -76,7 +76,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
for i := 0; i < len(items); i++ {
resp = append(resp, api.Script{
ID: items[i].ID,
Hash: model.HashFormat(items[i].Hash),
Hash: model.HashFormat(uint64(items[i].Hash)),
Source: items[i].Source,
SubmissionID: items[i].SubmissionID,
})
@ -124,7 +124,7 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (
return &api.Script{
ID: script.ID,
Name: script.Name,
Hash: model.HashFormat(script.Hash),
Hash: model.HashFormat(uint64(script.Hash)),
Source: script.Source,
SubmissionID: script.SubmissionID,
}, nil
@ -151,7 +151,7 @@ func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, par
}
if source, ok := req.Source.Get(); ok {
pmap.Add("source", source)
pmap.Add("hash", model.HashSource(source))
pmap.Add("hash", int64(model.HashSource(source))) // No type safety!
}
if SubmissionID, ok := req.SubmissionID.Get(); ok {
pmap.Add("submission_id", SubmissionID)

View File

@ -21,11 +21,11 @@ func (svc *Service) CreateSubmission(ctx context.Context, request *api.Submissio
DisplayName: request.DisplayName,
Creator: request.Creator,
GameID: request.GameID,
Submitter: userInfo.UserID,
AssetID: uint64(request.AssetID),
AssetVersion: uint64(request.AssetVersion),
Submitter: int64(userInfo.UserID),
AssetID: request.AssetID,
AssetVersion: request.AssetVersion,
Completed: false,
TargetAssetID: uint64(request.TargetAssetID.Value),
TargetAssetID: request.TargetAssetID.Value,
StatusID: model.StatusUnderConstruction,
})
if err != nil {
@ -149,7 +149,7 @@ func (svc *Service) UpdateSubmissionModel(ctx context.Context, params api.Update
}
// check if caller is the submitter
if !userInfo.IsSubmitter(submission.Submitter) {
if !userInfo.IsSubmitter(uint64(submission.Submitter)) {
return ErrPermissionDenied
}
@ -224,7 +224,7 @@ func (svc *Service) ActionSubmissionRevoke(ctx context.Context, params api.Actio
}
// check if caller is the submitter
if !userInfo.IsSubmitter(submission.Submitter) {
if !userInfo.IsSubmitter(uint64(submission.Submitter)) {
return ErrPermissionDenied
}
@ -252,7 +252,7 @@ func (svc *Service) ActionSubmissionSubmit(ctx context.Context, params api.Actio
}
// check if caller is the submitter
if !userInfo.IsSubmitter(submission.Submitter) {
if !userInfo.IsSubmitter(uint64(submission.Submitter)) {
return ErrPermissionDenied
}

View File

@ -49,7 +49,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
if err != nil {
return nil, err
}
filter.AddNotNil("from_script_hash", hash)
filter.AddNotNil("from_script_hash", int64(hash)) // No type safety!
}
if params.ToScriptID.IsSet(){
filter.AddNotNil("to_script_id", params.ToScriptID.Value)
@ -70,7 +70,7 @@ func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptP
for i := 0; i < len(items); i++ {
resp = append(resp, api.ScriptPolicy{
ID: items[i].ID,
FromScriptHash: model.HashFormat(items[i].FromScriptHash),
FromScriptHash: model.HashFormat(uint64(items[i].FromScriptHash)),
ToScriptID: items[i].ToScriptID,
Policy: int32(items[i].Policy),
})

View File

@ -17,7 +17,7 @@ func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*a
script, err := svc.DB.Scripts().Create(ctx, model.Script{
ID: 0,
Name: req.Name,
Hash: model.HashSource(req.Source),
Hash: int64(model.HashSource(req.Source)),
Source: req.Source,
SubmissionID: req.SubmissionID.Or(0),
})
@ -43,7 +43,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
if err != nil {
return nil, err
}
filter.AddNotNil("hash", hash)
filter.AddNotNil("hash", int64(hash)) // No type safety!
}
if params.Name.IsSet(){
filter.AddNotNil("name", params.Name.Value)
@ -67,7 +67,7 @@ func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParam
for i := 0; i < len(items); i++ {
resp = append(resp, api.Script{
ID: items[i].ID,
Hash: model.HashFormat(items[i].Hash),
Hash: model.HashFormat(uint64(items[i].Hash)),
Source: items[i].Source,
SubmissionID: items[i].SubmissionID,
})
@ -90,7 +90,7 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (
return &api.Script{
ID: script.ID,
Name: script.Name,
Hash: model.HashFormat(script.Hash),
Hash: model.HashFormat(uint64(script.Hash)),
Source: script.Source,
SubmissionID: script.SubmissionID,
}, nil