Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Tenancy: add tenant mode field to project. (#89)

spinningbota89b70cfa904
diff --git a/api/project.go b/api/project.go
index 1c9ad93f8c..cf171f5246 100644
--- a/api/project.go
+++ b/api/project.go
@@ -42,6 +42,16 @@ func (e ProjectVisibility) String() string {
return ""
}
+// ProjectTenantMode is the tenant mode setting for project.
+type ProjectTenantMode string
+
+const (
+ // TenantModeDisabled is the DISABLED value for ProjectTenantMode.
+ TenantModeDisabled ProjectTenantMode = "DISABLED"
+ // TenantModeTenant is the TENANT value for ProjectTenantMode.
+ TenantModeTenant ProjectTenantMode = "TENANT"
+)
+
type Project struct {
ID int `jsonapi:"primary,project"`
@@ -62,6 +72,7 @@ type Project struct {
Key string `jsonapi:"attr,key"`
WorkflowType ProjectWorkflowType `jsonapi:"attr,workflowType"`
Visibility ProjectVisibility `jsonapi:"attr,visibility"`
+ TenantMode ProjectTenantMode `jsonapi:"attr,tenantMode"`
}
type ProjectCreate struct {
@@ -105,6 +116,7 @@ type ProjectPatch struct {
Name *string `jsonapi:"attr,name"`
Key *string `jsonapi:"attr,key"`
WorkflowType *ProjectWorkflowType `jsonapi:"attr,workflowType"`
+ TenantMode *ProjectTenantMode `jsonapi:"attr,tenantMode"`
}
type ProjectService interface {
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index c8eee4b75b..2336772bac 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -211,7 +211,8 @@ CREATE TABLE project (
name TEXT NOT NULL,
`key` TEXT NOT NULL UNIQUE,
workflow_type TEXT NOT NULL CHECK (workflow_type IN ('UI', 'VCS')),
- visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PRIVATE'))
+ visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PRIVATE')),
+ tenant_mode TEXT NOT NULL DEFAULT 'DISABLED' CHECK (tenant_mode IN ('DISABLED', 'TENANT'))
);
INSERT INTO
diff --git a/store/project.go b/store/project.go
index 27bc10b080..d9673107a6 100644
--- a/store/project.go
+++ b/store/project.go
@@ -164,10 +164,11 @@ func createProject(ctx context.Context, tx *Tx, create *api.ProjectCreate) (*api
name,
key,
workflow_type,
- visibility
+ visibility,
+ tenant_mode
)
- VALUES (?, ?, ?, ?, 'UI', 'PUBLIC')
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type, visibility"+`
+ VALUES (?, ?, ?, ?, 'UI', 'PUBLIC', 'DISABLED')
+ RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type, visibility, tenant_mode"+`
`,
create.CreatorID,
create.CreatorID,
@@ -193,6 +194,7 @@ func createProject(ctx context.Context, tx *Tx, create *api.ProjectCreate) (*api
&project.Key,
&project.WorkflowType,
&project.Visibility,
+ &project.TenantMode,
); err != nil {
return nil, FormatError(err)
}
@@ -224,7 +226,8 @@ func findProjectList(ctx context.Context, tx *Tx, find *api.ProjectFind) (_ []*a
name,
key,
workflow_type,
- visibility
+ visibility,
+ tenant_mode
FROM project
WHERE `+strings.Join(where, " AND "),
args...,
@@ -249,6 +252,7 @@ func findProjectList(ctx context.Context, tx *Tx, find *api.ProjectFind) (_ []*a
&project.Key,
&project.WorkflowType,
&project.Visibility,
+ &project.TenantMode,
); err != nil {
return nil, FormatError(err)
}
@@ -278,6 +282,9 @@ func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*ap
if v := patch.WorkflowType; v != nil {
set, args = append(set, "`workflow_type` = ?"), append(args, *v)
}
+ if v := patch.TenantMode; v != nil {
+ set, args = append(set, "`tenant_mode` = ?"), append(args, *v)
+ }
args = append(args, patch.ID)
@@ -286,7 +293,7 @@ func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*ap
UPDATE project
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type, visibility"+`
+ RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type, visibility, tenant_mode"+`
`,
args...,
)
@@ -308,6 +315,7 @@ func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*ap
&project.Key,
&project.WorkflowType,
&project.Visibility,
+ &project.TenantMode,
); err != nil {
return nil, FormatError(err)
}
diff --git a/store/seed/test/10030__project.sql b/store/seed/test/10030__project.sql
index 33f2e64d72..f7feeb3da7 100644
--- a/store/seed/test/10030__project.sql
+++ b/store/seed/test/10030__project.sql
@@ -6,7 +6,8 @@ INSERT INTO
name,
`key`,
workflow_type,
- visibility
+ visibility,
+ tenant_mode
)
VALUES
(
@@ -16,7 +17,8 @@ VALUES
'Test (UI)',
'TEST',
'UI',
- 'PUBLIC'
+ 'PUBLIC',
+ 'DISABLED'
);
INSERT INTO
@@ -27,7 +29,8 @@ INSERT INTO
name,
`key`,
workflow_type,
- visibility
+ visibility,
+ tenant_mode
)
VALUES
(
@@ -37,7 +40,8 @@ VALUES
'Shop (Git)',
'SHP',
'VCS',
- 'PUBLIC'
+ 'PUBLIC',
+ 'DISABLED'
);
INSERT INTO
@@ -48,7 +52,8 @@ INSERT INTO
name,
`key`,
workflow_type,
- visibility
+ visibility,
+ tenant_mode
)
VALUES
(
@@ -58,7 +63,8 @@ VALUES
'Blog (Git)',
'BLG',
'VCS',
- 'PUBLIC'
+ 'PUBLIC',
+ 'DISABLED'
);
INSERT INTO
@@ -70,7 +76,8 @@ INSERT INTO
name,
`key`,
workflow_type,
- visibility
+ visibility,
+ tenant_mode
)
VALUES
(
@@ -81,5 +88,52 @@ VALUES
'Retired Project',
'RTR',
'UI',
- 'PUBLIC'
+ 'PUBLIC',
+ 'DISABLED'
+ );
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ `key`,
+ workflow_type,
+ visibility,
+ tenant_mode
+ )
+VALUES
+ (
+ 3005,
+ 101,
+ 101,
+ 'Tenant (Git)',
+ 'TNTG',
+ 'VCS',
+ 'PUBLIC',
+ 'TENANT'
+ );
+
+INSERT INTO
+ project (
+ id,
+ creator_id,
+ updater_id,
+ name,
+ `key`,
+ workflow_type,
+ visibility,
+ tenant_mode
+ )
+VALUES
+ (
+ 3006,
+ 101,
+ 101,
+ 'Tenant (UI)',
+ 'TNTU',
+ 'UI',
+ 'PUBLIC',
+ 'TENANT'
);
diff --git a/store/seed/test/10040__project_member.sql b/store/seed/test/10040__project_member.sql
index 782c23f520..567b67c2ea 100644
--- a/store/seed/test/10040__project_member.sql
+++ b/store/seed/test/10040__project_member.sql
@@ -173,3 +173,90 @@ VALUES
'DEVELOPER',
103
);
+
+-- Project 3005 membership
+INSERT INTO
+ project_member (
+ creator_id,
+ updater_id,
+ project_id,
+ `role`,
+ principal_id
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 3005,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ creator_id,
+ updater_id,
+ project_id,
+ `role`,
+ principal_id
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 3005,
+ 'DEVELOPER',
+ 102
+ );
+
+-- Project 3006 membership
+INSERT INTO
+ project_member (
+ creator_id,
+ updater_id,
+ project_id,
+ `role`,
+ principal_id
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 3006,
+ 'OWNER',
+ 101
+ );
+
+INSERT INTO
+ project_member (
+ creator_id,
+ updater_id,
+ project_id,
+ `role`,
+ principal_id
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 3006,
+ 'DEVELOPER',
+ 102
+ );
+
+INSERT INTO
+ project_member (
+ creator_id,
+ updater_id,
+ project_id,
+ `role`,
+ principal_id
+ )
+VALUES
+ (
+ 101,
+ 101,
+ 3006,
+ 'DEVELOPER',
+ 103
+ );