Integrate orgs and projects#325
Conversation
This is the insertion half of a pattern for preventing inconsistency when one operation inserts a resource into a collection while another deletes the collection.
This allows implementing multiple variants on one collection type. For example, DatastoreCollection<User> on Organization and DatastoreCollection<Project> on Organization.
|
Hmm, I did something slightly wrong at least, since it grabbed the authn stuff. I think what happened was I merged main into the CTE branch but forgot to push, and then pushed this branch. I'll see if I can disentangle |
|
Okay, looks good now |
| .await | ||
| .map_err(|e| { | ||
| let organization_id = project.organization_id; | ||
| Organization::insert_resource( |
There was a problem hiding this comment.
There's a lot of refactoring noise in this PR so it's easy to miss, but this is really slick. I love that this block is clear for readers, handles the concurrency issues, and produces a useful error for the various cases! Thanks again for doing this.
| path = "/organizations/{organization_name}/projects/{project_name}", | ||
| }] | ||
| async fn projects_put_project( | ||
| async fn organization_projects_put_project( |
There was a problem hiding this comment.
Does it make sense to prepend the "organization_" prefix to these endpoints? Kinda seems like we should keep the old naming scheme for these functions - technically everything is nested under "organization", so it gets kinda noisy.
There was a problem hiding this comment.
I'd be fine dropping it. I was following the scheme that seemed to already be present on things like instances and disks
There was a problem hiding this comment.
Yeah, the current scheme is documented in the file. I think it'd be worthwhile that we stick with some consistent, predictable naming scheme, especially since the names show up in the generated clients and changing the names requires clients to make code changes. That scheme doesn't have to match what we do today.
There was a problem hiding this comment.
Right, this was documented as {collection_path}_{verb}_{object}.
It's not clear if "collection_path" is meant to be the whole path, or only the "outermost collection".
- If it's the full path, we would need to add the
organization_prefix to all endpoints. As an example, we'd wantproject_disks_postto becomeorganizations_projects_disk_post, but that seems... wordy. - If it's the "outermost collection: I think
organization_put_projectmakes more sense thanorganization_projects_put_project- the inner "project" is implied.
There was a problem hiding this comment.
Is there a strong opinion on this? I'd be inclined to leave it to a later refactor (since I think it also has implications for other endpoint names)
There was a problem hiding this comment.
Yeah I'd make it a separate PR.
There was a problem hiding this comment.
(Could do it together with organizations -> orgs)
|
I think I forgot to ping this last week, this should be ready for review |
| // child-resource generation number | ||
| let org_after_p1_creation = | ||
| datastore.organization_fetch(&make_name(org_name)).await.unwrap(); | ||
| assert!(org_after_p1_creation.rcgen > org_after_creation.rcgen); |
There was a problem hiding this comment.
You could you do without create_datastore by using nexus here
let nexus = &cptestctx.server.apictx.nexus;
let org_after_creation =
nexus.organization_fetch(&make_name(org_name)).await.unwrap();On one hand I can see why you'd want to talk to directly to the DB and avoid any indirection the Nexus wrapper might introduce. On the other hand I have a slight bias against doing asserts about internal implementation details from an integration test if possible, and if those were moved elsewhere it makes the question of talking to the DB moot.
There was a problem hiding this comment.
Hmm, I'll move this to a test within the datastore.rs I think
| type CollectionTimeDeletedColumn = organization::dsl::time_deleted; | ||
| type CollectionIdColumn = project::dsl::organization_id; | ||
| } | ||
|
|
There was a problem hiding this comment.
this is so clean 👌 👌 👌 👌
david-crespo
left a comment
There was a problem hiding this comment.
Looks great, thanks for doing all this. I don't have a strong opinion about the datastore in integration test comment, just curious about your thoughts.
Introduce the notion of projects belonging to organizations. This has broad impacts on our API routes, as mentioned in #308.
Resolves #308