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

[AC 1427]Add New Organisation Properties Update DB Objects and create migration #2980

Conversation

cyprain-okeke
Copy link
Contributor

Type of change

- [ ] Bug fix
- [X] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

In preparation for the organization's secret manager billing feature, the UsePasswordManager, SmSeats,SmServiceAccounts,MaxAutoscaleSmSeats and MaxAutoscaleSmSeats columns need to be added to the Organization table, relevant db objects need to be updated, and migrations need to be created for the different database providers.

Code changes

  • I updated the Organization entity class with the UsePasswordManager, SmSeats,SmServiceAccounts,MaxAutoscaleSmSeats and MaxAutoscaleSmSeats properties, updated the organization table, stored procedures and functions SQL scripts, and created migrations for SQL server and EF core (SQLite, MySQL and Postgres).
  • I updated the Organization response models to include the new columns and updated ef core queries to return the new columns.

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

@cyprain-okeke cyprain-okeke requested a review from a team May 30, 2023 11:48
@cyprain-okeke cyprain-okeke changed the title Ac 1427/add new org properties update db objects and create migration [AC 1427]Add New Organisation Properties Update DB Objects and create migration May 30, 2023
@@ -81,6 +86,11 @@ public OrganizationResponseModel(Organization organization, string obj = "organi
public bool UseCustomPermissions { get; set; }
public bool SelfHost { get; set; }
public bool HasPublicAndPrivateKeys { get; set; }
public bool UsePasswordManager { get; set; } = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This default initialization value seems to be ignored since it's already initialized by the constructor. What's the reason for including it here? Perhaps just to document the intended default value?

Copy link
Member

@eliykat eliykat Jun 2, 2023

Choose a reason for hiding this comment

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

That's a good point, what do you think @cyprain-okeke?

Copy link
Member

@eliykat eliykat Jun 5, 2023

Choose a reason for hiding this comment

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

Cy's response (@cyprain-okeke looks like you accidentally edited my comment instead, so I'm just posting this separately for you)

I agree with you but The = true part of the declaration assigns a default value to the property. It means that if no value is explicitly assigned to UsePasswordManager, it will default to true.

So, in this case, the property UsePasswordManager will default to true if no value is explicitly assigned to it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes but it's a non-nullable bool, so it will always have a value assigned in the constructor, and this default assignment will never be used. (Please correct me if I'm wrong!)

public int? SmSeats { get; set; }
public int? SmServiceAccounts { get; set; }
public int? MaxAutoscaleSmSeats { get; set; } = null;
public int? MaxAutoscaleSmServiceAccounts { get; set; } = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Specifying null as the default value is redundant here given the datatype is already an int?

Copy link
Member

@eliykat eliykat Jun 2, 2023

Choose a reason for hiding this comment

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

The default value is 0, not null: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/default-values

I agree with your comment above though that these default assignments are probably not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This null has been removed. I agree with Conner

Copy link
Member

Choose a reason for hiding this comment

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

Oops sorry, the default value is indeed null for a nullable type. d'oh.

@cyprain-okeke This change is not showing, please double check that you've removed these assignments and pushed to remote.

Copy link
Contributor

@r-tome r-tome left a comment

Choose a reason for hiding this comment

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

The migration file is missing sp_refreshsqlmodule for the dependant stored procedures.
Other than that is looks good to me but left some questions/suggestions.

Copy link
Member

@eliykat eliykat left a comment

Choose a reason for hiding this comment

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

I haven't reviewed EF migrations on the assumption that @cturnbull-bitwarden and @r-tome already reviewed them (thank you both!). Just a few questions/comments.

This seems safe to merge into master because we're not using any of these values yet, but we do need to decide whether we're using a feature branch or feature flagging. I've raised that in #team-eng-adminconsole and we should make a decision there before merging. (This PR itself would not be feature flagged, but if we're going to use a feature branch then it should go there.)

src/Sql/dbo/Tables/Organization.sql Show resolved Hide resolved
src/Core/Entities/Organization.cs Outdated Show resolved Hide resolved
public int? SmSeats { get; set; }
public int? SmServiceAccounts { get; set; }
public int? MaxAutoscaleSmSeats { get; set; } = null;
public int? MaxAutoscaleSmServiceAccounts { get; set; } = null;
Copy link
Member

@eliykat eliykat Jun 2, 2023

Choose a reason for hiding this comment

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

The default value is 0, not null: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/default-values

I agree with your comment above though that these default assignments are probably not necessary.

@@ -81,6 +86,11 @@ public OrganizationResponseModel(Organization organization, string obj = "organi
public bool UseCustomPermissions { get; set; }
public bool SelfHost { get; set; }
public bool HasPublicAndPrivateKeys { get; set; }
public bool UsePasswordManager { get; set; } = true;
Copy link
Member

@eliykat eliykat Jun 2, 2023

Choose a reason for hiding this comment

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

That's a good point, what do you think @cyprain-okeke?

Copy link
Member

@eliykat eliykat 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, I believe the only outstanding changes are those requested by @cturnbull-bitwarden in OrganizationResponseModel.cs, you said you agreed but I can't see the updated code.

PS. As discussed in the team channel, it looks like we'll be feature flagging this initiative rather than using a feature branch. Because these are database updates that do not affect any existing functionality, it's fine to target master.

@cyprain-okeke The changes suggested by @cturnbull-bitwarden have been done. Thanks for reminding me of that.

cyprain-okeke and others added 4 commits June 5, 2023 08:19
…eate_migration' of https://github.com/bitwarden/server into ac-1427/add_new_org_properties_update_db_objects_and_create_migration
…eate_migration' of https://github.com/bitwarden/server into ac-1427/add_new_org_properties_update_db_objects_and_create_migration
Copy link
Contributor

@r-tome r-tome left a comment

Choose a reason for hiding this comment

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

Great work!

Copy link
Member

@eliykat eliykat left a comment

Choose a reason for hiding this comment

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

lgtm as well, thanks Cy!

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.

4 participants