1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Feat/add change request settings (#2390)

<!-- 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_settings table 
Remove change_request_enabled column

## 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-11 10:09:25 +02:00 committed by GitHub
parent 665638b9da
commit 74c5189159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 12 deletions

View File

@ -12,3 +12,4 @@ website/translated_docs
website
setupJest.js
frontend
dist

View File

@ -21,14 +21,12 @@ 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 {
@ -80,7 +78,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, projects.change_request_enabled, count(features.name) AS number_of_features',
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, count(features.name) AS number_of_features',
),
)
.leftJoin('features', 'features.project', 'projects.id')
@ -117,7 +115,6 @@ 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,
};
}
@ -199,7 +196,6 @@ 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)
@ -244,12 +240,10 @@ 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,
change_request_enabled: project.changeRequestsEnabled,
})
.onConflict(['project_id', 'environment_name'])
.ignore();
@ -261,12 +255,9 @@ class ProjectStore implements IProjectStore {
): Promise<void> {
const rows = await Promise.all(
projects.map(async (projectId) => {
const project = await this.get(projectId);
return {
project_id: projectId,
environment_name: environment,
change_request_enabled:
project.changeRequestsEnabled || false,
};
}),
);
@ -384,7 +375,6 @@ class ProjectStore implements IProjectStore {
return {
environmentName: row.environment_name,
projectId: row.project_id,
changeRequestsEnabled: row.change_request_enabled,
};
}
@ -401,7 +391,6 @@ 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

@ -0,0 +1,23 @@
'use strict';
exports.up = function (db, callback) {
db.runSql(
`
CREATE TABLE IF NOT EXISTS change_request_settings (
project varchar(255) REFERENCES projects(id) ON DELETE CASCADE,
environment varchar(100) REFERENCES environments(name) ON DELETE CASCADE,
PRIMARY KEY(project, environment)
);
`,
callback,
);
};
exports.down = function (db, callback) {
db.runSql(
`
DROP TABLE IF EXISTS change_request_settings;
`,
callback,
);
};

View File

@ -0,0 +1,21 @@
'use strict';
exports.up = 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,
);
};
exports.down = 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,
);
};