Update environment variable entity schema to update them individually (#53)
* Change environment field to enum instead of array * Update gql client for get environment variables query --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
8ead083ab3
commit
2f8d21baf5
@ -1,7 +1,6 @@
|
|||||||
import { DataSource, DeepPartial } from 'typeorm';
|
import { DataSource, DeepPartial } from 'typeorm';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { DatabaseConfig } from './config';
|
import { DatabaseConfig } from './config';
|
||||||
import { User } from './entity/User';
|
import { User } from './entity/User';
|
||||||
@ -156,9 +155,6 @@ export class Database {
|
|||||||
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
||||||
|
|
||||||
const environmentVariables = await environmentVariableRepository.find({
|
const environmentVariables = await environmentVariableRepository.find({
|
||||||
relations: {
|
|
||||||
project: true
|
|
||||||
},
|
|
||||||
where: {
|
where: {
|
||||||
project: {
|
project: {
|
||||||
id: projectId
|
id: projectId
|
||||||
@ -181,27 +177,27 @@ export class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addEnvironmentVariablesByProjectId (projectId: string, environmentVariables: any[]): Promise<boolean> {
|
async addEnvironmentVariablesByProjectId (projectId: string, environmentVariables: {
|
||||||
|
environments: string[];
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
}[]): Promise<boolean> {
|
||||||
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
||||||
const projectRepository = this.dataSource.getRepository(Project);
|
|
||||||
|
|
||||||
const project = await projectRepository.findOneBy({
|
const formattedEnvironmentVariables = environmentVariables.map((environmentVariable) => {
|
||||||
|
return environmentVariable.environments.map((environment) => {
|
||||||
|
return ({
|
||||||
|
key: environmentVariable.key,
|
||||||
|
value: environmentVariable.value,
|
||||||
|
environment: environment as Environment,
|
||||||
|
project: Object.assign(new Project(), {
|
||||||
id: projectId
|
id: projectId
|
||||||
|
})
|
||||||
});
|
});
|
||||||
assert(project);
|
|
||||||
|
|
||||||
const environmentVariablesPromises = environmentVariables.map(async environmentVariable => {
|
|
||||||
const envVar = new EnvironmentVariable();
|
|
||||||
|
|
||||||
envVar.key = environmentVariable.key;
|
|
||||||
envVar.value = environmentVariable.value;
|
|
||||||
envVar.environments = environmentVariable.environments;
|
|
||||||
envVar.project = project;
|
|
||||||
|
|
||||||
return environmentVariableRepository.save(envVar);
|
|
||||||
});
|
});
|
||||||
|
}).flat();
|
||||||
|
|
||||||
const savedEnvironmentVariables = await Promise.all(environmentVariablesPromises);
|
const savedEnvironmentVariables = await environmentVariableRepository.save(formattedEnvironmentVariables);
|
||||||
return savedEnvironmentVariables.length > 0;
|
return savedEnvironmentVariables.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ export class EnvironmentVariable {
|
|||||||
project!: Project;
|
project!: Project;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'simple-array'
|
enum: Environment
|
||||||
})
|
})
|
||||||
environments!: Environment[];
|
environment!: Environment;
|
||||||
|
|
||||||
@Column('varchar')
|
@Column('varchar')
|
||||||
key!: string;
|
key!: string;
|
||||||
|
@ -72,12 +72,7 @@ export const createResolvers = async (db: Database): Promise<any> => {
|
|||||||
|
|
||||||
environmentVariables: async (_: any, { projectId }: { projectId: string }) => {
|
environmentVariables: async (_: any, { projectId }: { projectId: string }) => {
|
||||||
const dbEnvironmentVariables = await db.getEnvironmentVariablesByProjectId(projectId);
|
const dbEnvironmentVariables = await db.getEnvironmentVariablesByProjectId(projectId);
|
||||||
|
return dbEnvironmentVariables;
|
||||||
const environmentVariables = dbEnvironmentVariables.map(dbEnvironmentVariable => {
|
|
||||||
return environmentVariableToGqlType(dbEnvironmentVariable);
|
|
||||||
});
|
|
||||||
|
|
||||||
return environmentVariables;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
projectMembers: async (_: any, { projectId }: { projectId: string }) => {
|
projectMembers: async (_: any, { projectId }: { projectId: string }) => {
|
||||||
|
@ -106,7 +106,7 @@ type Domain {
|
|||||||
|
|
||||||
type EnvironmentVariable {
|
type EnvironmentVariable {
|
||||||
id: String!
|
id: String!
|
||||||
environments: [Environment!]!
|
environment: Environment!
|
||||||
key: String!
|
key: String!
|
||||||
value: String!
|
value: String!
|
||||||
createdAt: String!
|
createdAt: String!
|
||||||
|
@ -74,7 +74,7 @@ export const projectMemberToGqlType = (dbProjectMember: ProjectMember): any => {
|
|||||||
export const environmentVariableToGqlType = (dbEnvironmentVariable: EnvironmentVariable): any => {
|
export const environmentVariableToGqlType = (dbEnvironmentVariable: EnvironmentVariable): any => {
|
||||||
return {
|
return {
|
||||||
id: dbEnvironmentVariable.id,
|
id: dbEnvironmentVariable.id,
|
||||||
environments: dbEnvironmentVariable.environments,
|
environments: dbEnvironmentVariable.environment,
|
||||||
key: dbEnvironmentVariable.key,
|
key: dbEnvironmentVariable.key,
|
||||||
value: dbEnvironmentVariable.value,
|
value: dbEnvironmentVariable.value,
|
||||||
createdAt: dbEnvironmentVariable.createdAt,
|
createdAt: dbEnvironmentVariable.createdAt,
|
||||||
|
@ -3,60 +3,90 @@
|
|||||||
"projectIndex": 0,
|
"projectIndex": 0,
|
||||||
"key": "ABC",
|
"key": "ABC",
|
||||||
"value": "ABC",
|
"value": "ABC",
|
||||||
"environments": ["Production", "Preview"]
|
"environment": "Production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"projectIndex": 0,
|
||||||
|
"key": "ABC",
|
||||||
|
"value": "ABC",
|
||||||
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 0,
|
"projectIndex": 0,
|
||||||
"key": "XYZ",
|
"key": "XYZ",
|
||||||
"value": "abc3",
|
"value": "abc3",
|
||||||
"environments": ["Preview"]
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 1,
|
"projectIndex": 1,
|
||||||
"key": "ABC",
|
"key": "ABC",
|
||||||
"value": "ABC",
|
"value": "ABC",
|
||||||
"environments": ["Production", "Preview"]
|
"environment": "Production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"projectIndex": 1,
|
||||||
|
"key": "ABC",
|
||||||
|
"value": "ABC",
|
||||||
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 1,
|
"projectIndex": 1,
|
||||||
"key": "XYZ",
|
"key": "XYZ",
|
||||||
"value": "abc3",
|
"value": "abc3",
|
||||||
"environments": ["Preview"]
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 2,
|
"projectIndex": 2,
|
||||||
"key": "ABC",
|
"key": "ABC",
|
||||||
"value": "ABC",
|
"value": "ABC",
|
||||||
"environments": ["Production", "Preview"]
|
"environment": "Production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"projectIndex": 2,
|
||||||
|
"key": "ABC",
|
||||||
|
"value": "ABC",
|
||||||
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 2,
|
"projectIndex": 2,
|
||||||
"key": "XYZ",
|
"key": "XYZ",
|
||||||
"value": "abc3",
|
"value": "abc3",
|
||||||
"environments": ["Preview"]
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 3,
|
"projectIndex": 3,
|
||||||
"key": "ABC",
|
"key": "ABC",
|
||||||
"value": "ABC",
|
"value": "ABC",
|
||||||
"environments": ["Production", "Preview"]
|
"environment": "Production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"projectIndex": 3,
|
||||||
|
"key": "ABC",
|
||||||
|
"value": "ABC",
|
||||||
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 3,
|
"projectIndex": 3,
|
||||||
"key": "XYZ",
|
"key": "XYZ",
|
||||||
"value": "abc3",
|
"value": "abc3",
|
||||||
"environments": ["Preview"]
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 4,
|
"projectIndex": 4,
|
||||||
"key": "ABC",
|
"key": "ABC",
|
||||||
"value": "ABC",
|
"value": "ABC",
|
||||||
"environments": ["Production", "Preview"]
|
"environment": "Production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"projectIndex": 4,
|
||||||
|
"key": "ABC",
|
||||||
|
"value": "ABC",
|
||||||
|
"environment": "Preview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"projectIndex": 4,
|
"projectIndex": 4,
|
||||||
"key": "XYZ",
|
"key": "XYZ",
|
||||||
"value": "abc3",
|
"value": "abc3",
|
||||||
"environments": ["Preview"]
|
"environment": "Preview"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -11,7 +11,7 @@ interface OverviewProps {
|
|||||||
project: Project;
|
project: Project;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check any live domain is set for production branch
|
// TODO: Check if any live domain is set for production branch
|
||||||
const IS_DOMAIN_SETUP = true;
|
const IS_DOMAIN_SETUP = true;
|
||||||
|
|
||||||
const OverviewTabPanel = ({ project }: OverviewProps) => {
|
const OverviewTabPanel = ({ project }: OverviewProps) => {
|
||||||
|
@ -72,8 +72,8 @@ export const EnvironmentVariablesTabPanel = () => {
|
|||||||
|
|
||||||
const getEnvironmentVariable = useCallback(
|
const getEnvironmentVariable = useCallback(
|
||||||
(environment: Environment) => {
|
(environment: Environment) => {
|
||||||
return environmentVariables.filter((item) =>
|
return environmentVariables.filter(
|
||||||
item.environments.includes(environment),
|
(item) => item.environment === environment,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[environmentVariables, id],
|
[environmentVariables, id],
|
||||||
|
@ -43,7 +43,7 @@ const MembersTabPanel = ({ project }: { project: Project }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchProjectMembers();
|
fetchProjectMembers();
|
||||||
}, [project.id]);
|
}, [project.id, fetchProjectMembers]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 mb-20">
|
<div className="p-2 mb-20">
|
||||||
|
@ -122,14 +122,6 @@ query {
|
|||||||
email
|
email
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
environmentVariables {
|
|
||||||
id
|
|
||||||
environments
|
|
||||||
key
|
|
||||||
value
|
|
||||||
createdAt
|
|
||||||
updatedAt
|
|
||||||
}
|
|
||||||
createdAt
|
createdAt
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
@ -171,7 +163,7 @@ export const getEnvironmentVariables = gql`
|
|||||||
query ($projectId: String!) {
|
query ($projectId: String!) {
|
||||||
environmentVariables(projectId: $projectId) {
|
environmentVariables(projectId: $projectId) {
|
||||||
createdAt
|
createdAt
|
||||||
environments
|
environment
|
||||||
id
|
id
|
||||||
key
|
key
|
||||||
updatedAt
|
updatedAt
|
||||||
|
@ -30,7 +30,7 @@ export enum DomainStatus {
|
|||||||
|
|
||||||
export type EnvironmentVariable = {
|
export type EnvironmentVariable = {
|
||||||
id: string
|
id: string
|
||||||
environments: Environment[]
|
environment: Environment
|
||||||
key: string
|
key: string
|
||||||
value: string
|
value: string
|
||||||
createdAt: string
|
createdAt: string
|
||||||
|
Loading…
Reference in New Issue
Block a user