-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes 4293: add support for upload only repos #728
Conversation
Snapshot *bool `json:"snapshot"` // Enable snapshotting and hosting of this repository | ||
} | ||
|
||
type RepositoryUpdateRequest struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not saying I'm opposed, just curious, why separate the update request struct? I guess one benefit might be making the API more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While making the origin parameter available for create, i didn't want it available for update. There's no way in openapi to indicate that a parameter is only for creation, and i saw some discussion mentioning that using different structs was the correct way to handle it. We also did it this way for template.
That said, it complicates and duplicates the code quite a bit. I tried using inheritance and that reduced the duplication a bit, but increased complexity and i didn't think was an improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found these two issues. Everything else seems to be working well.
} else if newRepo.URL != "" { | ||
cleanedUrl := models.CleanupURL(newRepo.URL) | ||
// Repo configs with the same URL share a repository object | ||
if err := r.db.WithContext(ctx).Where("url = ?", cleanedUrl).FirstOrCreate(&newRepo).Error; err != nil { | ||
return api.RepositoryResponse{}, DBErrorToApi(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a repository exists (not a repository config) and I create an upload repo with the URL of the existing repository, I get no error, because it fetches the existing repository (which would have a non-upload origin). If the repository does not exist, I get a 400 error because "an upload repo cannot contain a URL". I think I'd expect to get the same 400 in the first scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated and add a test for create and update for this situation
BEGIN; | ||
alter table repositories alter column URL set not null; | ||
COMMIT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this error running the down migration
{"level":"error","error":"2 errors occurred:\n\t* migration failed: column \"url\" of relation \"repositories\" contains null values in line 0: BEGIN;\nalter table repositories alter column URL set not null;\nCOMMIT;\n (details: pq: column \"url\" of relation \"repositories\" contains null values)\n\t* pq: current transaction is aborted, commands ignored until end of transaction block in line 0: SELECT pg_advisory_unlock($1)\n\n","time":"2024-07-09T13:29:07-04:00","message":"Failed to migrate:"}
{"level":"fatal","error":"database locked","time":"2024-07-09T13:29:07-04:00","message":"Failed to migrate"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had an upload repository created when I ran it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i'm not sure exactly what to do about this. I guess this may be considered a migration that can't be reverted. We can't flip that column back to 'not null' whith a null value. We could delete all repositories (and repo configs, and associated rpms, etc....) in the migration, but thats not a great solution. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. I can't think of a better way to do it. I guess we can consider it an un-revertable migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
/retest |
Hi I can create an upload repo:
To list upload repos at present it is required to use
|
Summary
Testing steps
Create an upload repo:
with batch:
try to:
go run cmd/external-repos/main.go nightly-jobs
and verify no errors, that things work as expectedChecklist