1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +02:00

Add changeRequestEnabled to project and project_environments (#2357)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

- Add `change_request_enabled` column to `projects` and
`project_environments`
- Modified the store to include the new column
- Added new column to Project open api schema 

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
This commit is contained in:
andreas-unleash 2022-11-09 14:44:53 +02:00 committed by GitHub
parent ff11f30e1d
commit 47a617c78b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 5 deletions

View File

@ -21,12 +21,14 @@ const COLUMNS = [
'created_at',
'health',
'updated_at',
'change_request_enabled',
];
const TABLE = 'projects';
export interface IEnvironmentProjectLink {
environmentName: string;
projectId: string;
changeRequestsEnabled?: string;
}
export interface IProjectMembersCount {
@ -78,7 +80,7 @@ class ProjectStore implements IProjectStore {
let projects = this.db(TABLE)
.select(
this.db.raw(
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, count(features.name) AS number_of_features',
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, projects.change_request_enabled, count(features.name) AS number_of_features',
),
)
.leftJoin('features', 'features.project', 'projects.id')
@ -115,6 +117,7 @@ class ProjectStore implements IProjectStore {
featureCount: Number(row.number_of_features) || 0,
memberCount: Number(row.number_of_users) || 0,
updatedAt: row.updated_at,
changeRequestsEnabled: row.change_request_enabled || false,
};
}
@ -196,6 +199,7 @@ class ProjectStore implements IProjectStore {
const environments = projects.map((p) => ({
project_id: p.id,
environment_name: DEFAULT_ENV,
change_request_enabled: p.change_request_enabled,
}));
await this.db('project_environments')
.insert(environments)
@ -240,8 +244,13 @@ class ProjectStore implements IProjectStore {
id: string,
environment: string,
): Promise<void> {
const project = await this.get(id);
await this.db('project_environments')
.insert({ project_id: id, environment_name: environment })
.insert({
project_id: id,
environment_name: environment,
change_request_enabled: project.changeRequestsEnabled,
})
.onConflict(['project_id', 'environment_name'])
.ignore();
}
@ -250,10 +259,12 @@ class ProjectStore implements IProjectStore {
environment: string,
projects: string[],
): Promise<void> {
const rows = projects.map((project) => {
const rows = projects.map(async (projectId) => {
const project = await this.get(projectId);
return {
project_id: project,
project_id: projectId,
environment_name: environment,
change_request_enabled: project.changeRequestsEnabled || false,
};
});
@ -370,6 +381,7 @@ class ProjectStore implements IProjectStore {
return {
environmentName: row.environment_name,
projectId: row.project_id,
changeRequestsEnabled: row.change_request_enabled,
};
}
@ -386,6 +398,7 @@ class ProjectStore implements IProjectStore {
createdAt: row.created_at,
health: row.health || 100,
updatedAt: row.updated_at || new Date(),
changeRequestsEnabled: row.change_request_enabled || false,
};
}
}

View File

@ -9,6 +9,9 @@ export const projectEnvironmentSchema = {
environment: {
type: 'string',
},
changeRequestsEnabled: {
type: 'boolean',
},
},
components: {},
} as const;

View File

@ -10,6 +10,22 @@ test('projectSchema', () => {
featureCount: 10,
memberCount: 3,
updatedAt: '2022-06-28T17:33:53.963Z',
changeRequestsEnabled: false,
};
expect(
validateSchema('#/components/schemas/projectSchema', {}),
).not.toBeUndefined();
expect(
validateSchema('#/components/schemas/projectSchema', data),
).toBeUndefined();
});
test('projectSchema with only required', () => {
const data: ProjectSchema = {
name: 'Default',
id: 'default',
};
expect(

View File

@ -33,6 +33,9 @@ export const projectSchema = {
format: 'date-time',
nullable: true,
},
changeRequestsEnabled: {
type: 'boolean',
},
},
components: {},
} as const;

View File

@ -345,8 +345,8 @@ export interface IProject {
health?: number;
createdAt?: Date;
updatedAt?: Date;
changeRequestsEnabled?: boolean;
}
export interface ICustomRole {
id: number;
name: string;

View File

@ -10,6 +10,7 @@ export interface IProjectInsert {
name: string;
description: string;
updatedAt?: Date;
changeRequestsEnabled?: boolean;
}
export interface IProjectArchived {
@ -26,6 +27,11 @@ export interface IProjectQuery {
id?: string;
}
export interface IProjectEnvironmentWithChangeRequests {
environment: string;
changeRequestsEnabled: boolean;
}
export interface IProjectStore extends Store<IProject, string> {
hasProject(id: string): Promise<boolean>;
updateHealth(healthUpdate: IProjectHealthUpdate): Promise<void>;
@ -44,9 +50,11 @@ export interface IProjectStore extends Store<IProject, string> {
getProjectsWithCounts(query?: IProjectQuery): Promise<IProjectWithCount[]>;
count(): Promise<number>;
getAll(query?: IProjectQuery): Promise<IProject[]>;
getProjectLinksForEnvironments(
environments: string[],
): Promise<IEnvironmentProjectLink[]>;
addEnvironmentToProjects(
environment: string,
projects: string[],

View File

@ -0,0 +1,21 @@
'use strict';
exports.up = function (db, callback) {
db.runSql(
`
ALTER TABLE project_environments add column if not exists change_request_enabled bool default false;
ALTER TABLE projects add column if not exists change_request_enabled bool default false;
`,
callback,
);
};
exports.down = function (db, callback) {
db.runSql(
`
ALTER TABLE project_environments drop column if exists change_request_enabled;
ALTER TABLE projects drop column if exists change_request_enabled;
`,
callback,
);
};

View File

@ -2255,6 +2255,9 @@ exports[`should serve the OpenAPI spec 1`] = `
"projectEnvironmentSchema": {
"additionalProperties": false,
"properties": {
"changeRequestsEnabled": {
"type": "boolean",
},
"environment": {
"type": "string",
},
@ -2267,6 +2270,9 @@ exports[`should serve the OpenAPI spec 1`] = `
"projectSchema": {
"additionalProperties": false,
"properties": {
"changeRequestsEnabled": {
"type": "boolean",
},
"createdAt": {
"format": "date-time",
"type": "string",