Skip to content
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

Schema changes for Organization membership #4904

Merged
merged 5 commits into from
Oct 26, 2017
Merged

Conversation

chenriksson
Copy link
Member

@chenriksson chenriksson commented Oct 25, 2017

Core schema changes required for membership in organizations. Tracked by #4868

The following were excluded, but can be added in a future migration once the design is finalized:

/cc @anangaur

/// - Pushing new package versions
/// - Unlisting packages
/// </summary>
public bool IsCollaborator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be careful with this, because I don't think it is usable in LINQ to SQL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I prefer methods here since it's a stronger signal to the caller that this is not a real SQL property and should only be used after a query is completed (i.e. in memory).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed Membership.IsCollaborator and User.IsOrganization properties. If callers need something like that, we can add back helpers in later PRs.

.WillCascadeOnDelete(false); // Disabled to prevent multiple cascade paths.

modelBuilder.Entity<Membership>()
.HasKey(m => new { m.OrganizationKey, m.MemberKey })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the composite key? EF will already be creating an index for OrganizationKey.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EF requires a PK on the Membership table, and throws an exception if I don't have it.

This is essentially a many-to-many table where the 2 foreign keys become the composite PK, same as with the PackageRegistrationOwners table. The only difference is that this includes additional state (IsAdmin), so I need to treat it as two one-to-many relations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see MemberKey is a Key on the Users table. I misunderstood. Perfect 👌

/// <summary>
/// Whether this is an <see cref="Organization"/> account.
/// </summary>
public bool IsOrganization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this is unusable in LINQ to SQL.

Copy link
Contributor

@scottbommarito scottbommarito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but this should probably be merged into a feature branch

/// <summary>
/// Whether the <see cref="Member"/> is an administrator for the <see cref="Organization"/>.
///
/// Administrators have the following capabilities:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should say explicitly that members that are not admins are collaborators.

It might not be best to list out all of the capabilities here. This comment is unlikely to change if we change the actual capabilities, so I'm concerned this list will become outdated and misleading.

If you do leave the list, you should specify what collaborators can do.

///
/// The Users table contains both User and Organization accounts. The Organizations table exists both
/// as a constraint for Membership as well as a place for possible Organization-only settings. If User
/// and Organization settings diverge, we can consider creating a separate UserSettings table as well.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there are already fields in the Users table that don't apply to Organizations.

Ideally we should already create UserSettings but the value of doing so is just too low to prioritize it.

}
set
{
throw new NotSupportedException();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these all have set? Is set ever used? Can we remove set and get rid of these NotSupportedExceptions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setters exist on the IEntitiesContext properties. The test context doesn't support it, so throw ensures it isn't used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize these were tests, woops

/// <summary>
/// Account (User) name.
/// </summary>
public string Name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this works in LINQ to SQL. Not sure tho.

@joelverhagen
Copy link
Member

In general I think we should avoid convenience properties on EF entities since it is unclear from the interface if they are usable in LINQ to SQL. Maybe we can add analogous methods as they are needed by our business logic.

Also, what SQL does this migration generate?

/// <summary>
/// Organization account (User).
/// </summary>
public User Account { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AccountKey = Account.Key , right? If so, why do we need AccountKey as a separate property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Contributor

@skofman1 skofman1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@chenriksson
Copy link
Member Author

@scottbommarito I don't think we need a feature branch for this feature. Most of these changes should be transparent to the user until we enable onboarding. Let me know if there are concerns with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants