generated from broadinstitute/golang-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fda04f7
commit 8c70227
Showing
19 changed files
with
367 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
alter table clusters | ||
alter column requires_suitability set not null; | ||
|
||
alter table environments | ||
drop constraint if exists fk_environments_required_role; | ||
|
||
alter table environments | ||
drop column if exists required_role_id; | ||
|
||
alter table environments | ||
add constraint lifecycle_valid_temp | ||
check ((lifecycle = 'template' and | ||
template_environment_id is null) or | ||
(lifecycle = 'dynamic' and | ||
template_environment_id is not null and | ||
base is not null and base != '' and | ||
default_cluster_id is not null and | ||
requires_suitability is not null) or | ||
(lifecycle = 'static' and | ||
base is not null and base != '' and | ||
default_cluster_id is not null and | ||
requires_suitability is not null)); | ||
|
||
alter table environments | ||
validate constraint lifecycle_valid_temp; | ||
|
||
alter table environments | ||
drop constraint lifecycle_valid; | ||
|
||
alter table environments | ||
rename constraint lifecycle_valid_temp to lifecycle_valid; | ||
|
||
alter table clusters | ||
drop constraint if exists fk_clusters_required_role; | ||
|
||
alter table clusters | ||
drop column if exists required_role_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
alter table clusters | ||
add column required_role_id bigint; | ||
|
||
alter table clusters | ||
add constraint fk_clusters_required_role | ||
foreign key (required_role_id) references roles; | ||
|
||
-- Now formally allow nulls in requires_suitability column to match with the semantics of required_role_id | ||
alter table clusters | ||
alter column requires_suitability drop not null; | ||
|
||
alter table environments | ||
add column required_role_id bigint; | ||
|
||
alter table environments | ||
add constraint fk_environments_required_role | ||
foreign key (required_role_id) references roles; | ||
|
||
-- The not null requirement on requires_suitability here is lifecycle-dependent, see 000062_environment_v3.up.sql, | ||
-- so we need to drop the not null constraint here to match the semantics of required_role_id. | ||
-- We do this by adding a new constraint as not valid, so that it commits instantly, and then validate it. | ||
-- This requires much, much less locking than a normal add constraint. | ||
-- https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-NOTES | ||
alter table environments | ||
add constraint lifecycle_valid_temp | ||
check ((lifecycle = 'template' and | ||
template_environment_id is null) or | ||
(lifecycle = 'dynamic' and | ||
template_environment_id is not null and | ||
base is not null and base != '' and | ||
default_cluster_id is not null) or | ||
(lifecycle = 'static' and | ||
base is not null and base != '' and | ||
default_cluster_id is not null)) not valid; | ||
|
||
alter table environments | ||
validate constraint lifecycle_valid_temp; | ||
|
||
alter table environments | ||
drop constraint lifecycle_valid; | ||
|
||
alter table environments | ||
rename constraint lifecycle_valid_temp to lifecycle_valid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,7 @@ func (s *handlerSuite) TestEnvironmentV3_toModel() { | |
DefaultCluster: utils.PointerTo(defaultCluster.Name), | ||
Owner: utils.PointerTo(owner.Email), | ||
RequiresSuitability: utils.PointerTo(true), | ||
RequiredRole: s.TestData.Role_TerraSuitableEngineer().Name, | ||
BaseDomain: utils.PointerTo("base-domain"), | ||
NamePrefixesDomain: utils.PointerTo(true), | ||
HelmfileRef: utils.PointerTo("HEAD"), | ||
|
@@ -193,6 +194,7 @@ func (s *handlerSuite) TestEnvironmentV3_toModel() { | |
DefaultClusterID: &defaultCluster.ID, | ||
OwnerID: &owner.ID, | ||
RequiresSuitability: utils.PointerTo(true), | ||
RequiredRoleID: utils.PointerTo(s.TestData.Role_TerraSuitableEngineer().ID), | ||
BaseDomain: utils.PointerTo("base-domain"), | ||
NamePrefixesDomain: utils.PointerTo(true), | ||
HelmfileRef: utils.PointerTo("HEAD"), | ||
|
@@ -345,6 +347,8 @@ func Test_environmentFromModel(t *testing.T) { | |
Owner: &models.User{Model: gorm.Model{ID: 5}, Email: "[email protected]"}, | ||
OwnerID: utils.PointerTo[uint](5), | ||
RequiresSuitability: utils.PointerTo(true), | ||
RequiredRole: &models.Role{Model: gorm.Model{ID: 999}, RoleFields: models.RoleFields{Name: utils.PointerTo("role-name")}}, | ||
RequiredRoleID: utils.PointerTo[uint](999), | ||
BaseDomain: utils.PointerTo("base-domain"), | ||
NamePrefixesDomain: utils.PointerTo(true), | ||
HelmfileRef: utils.PointerTo("HEAD"), | ||
|
@@ -376,6 +380,7 @@ func Test_environmentFromModel(t *testing.T) { | |
PagerdutyIntegrationInfo: &PagerdutyIntegrationV3{CommonFields: CommonFields{ID: 6}, PagerdutyID: "blah"}, | ||
OwnerInfo: &UserV3{CommonFields: CommonFields{ID: 5}, Email: "[email protected]", Suitable: utils.PointerTo(false), | ||
SuitabilityDescription: utils.PointerTo("no matching suitability record found or loaded; assuming unsuitable")}, | ||
RequiredRoleInfo: &RoleV3{CommonFields: CommonFields{ID: 999}, RoleV3Edit: RoleV3Edit{Name: utils.PointerTo("role-name")}}, | ||
EnvironmentV3Create: EnvironmentV3Create{ | ||
Base: "base", | ||
AutoPopulateChartReleases: utils.PointerTo(true), | ||
|
@@ -389,6 +394,7 @@ func Test_environmentFromModel(t *testing.T) { | |
DefaultCluster: utils.PointerTo("name-4"), | ||
Owner: utils.PointerTo("[email protected]"), | ||
RequiresSuitability: utils.PointerTo(true), | ||
RequiredRole: utils.PointerTo("role-name"), | ||
BaseDomain: utils.PointerTo("base-domain"), | ||
NamePrefixesDomain: utils.PointerTo(true), | ||
HelmfileRef: utils.PointerTo("HEAD"), | ||
|
@@ -420,6 +426,19 @@ func Test_environmentFromModel(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
name: "role ID case", | ||
args: args{model: models.Environment{ | ||
RequiredRoleID: utils.PointerTo[uint](999), | ||
}}, | ||
want: EnvironmentV3{ | ||
EnvironmentV3Create: EnvironmentV3Create{ | ||
EnvironmentV3Edit: EnvironmentV3Edit{ | ||
RequiredRole: utils.PointerTo("999"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.