Set nano id to deployment id

This commit is contained in:
neeraj 2024-02-02 15:01:37 +05:30
parent b71b334c78
commit 51f3426d77
9 changed files with 44 additions and 31 deletions

View File

@ -16,6 +16,7 @@
"fs-extra": "^11.2.0",
"graphql": "^16.8.1",
"nanoid": "3",
"nanoid-dictionary": "^5.0.0-beta.1",
"reflect-metadata": "^0.2.1",
"toml": "^3.0.0",
"ts-node": "^10.9.2",

View File

@ -3,6 +3,7 @@ import path from 'path';
import debug from 'debug';
import assert from 'assert';
import { customAlphabet } from 'nanoid';
import { lowercase, numbers } from 'nanoid-dictionary';
import { DatabaseConfig } from './config';
import { User } from './entity/User';
@ -316,7 +317,7 @@ export class Database {
async updateDeploymentById (deploymentId: string, updates: DeepPartial<Deployment>): Promise<boolean> {
const deploymentRepository = this.dataSource.getRepository(Deployment);
const updateResult = await deploymentRepository.update({ id: Number(deploymentId) }, updates);
const updateResult = await deploymentRepository.update({ id: deploymentId }, updates);
if (updateResult.affected) {
return updateResult.affected > 0;
@ -366,14 +367,14 @@ export class Database {
createdBy: true
},
where: {
id: Number(deploymentId)
id: deploymentId
}
});
if (deployment === null) {
throw new Error('Deployment not found');
}
const { id, createdAt, updatedAt, ...updatedDeployment } = deployment;
const { createdAt, updatedAt, ...updatedDeployment } = deployment;
if (updatedDeployment.environment === Environment.Production) {
// TODO: Put isCurrent field in project
@ -383,13 +384,12 @@ export class Database {
});
}
await deploymentRepository.update({ id: Number(deploymentId) }, { domain: null, isCurrent: false });
await deploymentRepository.update({ id: deploymentId }, { domain: null, isCurrent: false });
// TODO: set deployment id in Deployment entity
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const nanoid = customAlphabet(alphabet, 8);
const nanoid = customAlphabet(lowercase + numbers, 8);
updatedDeployment.url = `${updatedDeployment.project.name}-${nanoid()}.${updatedDeployment.project.subDomain}`;
updatedDeployment.id = nanoid();
return deploymentRepository.save(updatedDeployment);
}
@ -450,7 +450,7 @@ export class Database {
const oldCurrentDeploymentUpdate = await deploymentRepository.update({ project: { id: projectId }, isCurrent: true }, { isCurrent: false, domain: null });
const newCurrentDeploymentUpdate = await deploymentRepository.update({ id: Number(deploymentId) }, { isCurrent: true, domain: oldCurrentDeployment?.domain });
const newCurrentDeploymentUpdate = await deploymentRepository.update({ id: deploymentId }, { isCurrent: true, domain: oldCurrentDeployment?.domain });
if (oldCurrentDeploymentUpdate.affected && newCurrentDeploymentUpdate.affected) {
return oldCurrentDeploymentUpdate.affected > 0 && newCurrentDeploymentUpdate.affected > 0;

View File

@ -1,6 +1,6 @@
import {
Entity,
PrimaryGeneratedColumn,
PrimaryColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
@ -28,8 +28,8 @@ enum Status {
@Entity()
export class Deployment {
// TODO: set custom generated id
@PrimaryGeneratedColumn()
id!: number;
@PrimaryColumn('varchar')
id!: string;
@ManyToOne(() => Project, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'projectId' })

View File

@ -3,120 +3,130 @@
"projectIndex": 0,
"domainIndex":0,
"createdByIndex": 0,
"id":"ffhae3zq",
"title": "nextjs-boilerplate-1",
"status": "Building",
"environment": "Production",
"isCurrent": true,
"branch": "main",
"commitHash": "testXyz",
"url": "testProject-fFhaE3Zq.testProject.snowball.xyz"
"url": "testProject-ffhae3zq.testProject.snowball.xyz"
},
{
"projectIndex": 0,
"domainIndex":1,
"createdByIndex": 0,
"id":"vehagei8",
"title": "nextjs-boilerplate-2",
"status": "Ready",
"environment": "Preview",
"isCurrent": false,
"branch": "test",
"commitHash": "testXyz",
"url": "testProject-VEHAgEI8.testProject.snowball.xyz"
"url": "testProject-vehagei8.testProject.snowball.xyz"
},
{
"projectIndex": 0,
"domainIndex":2,
"createdByIndex": 0,
"id":"qmgekyte",
"title": "nextjs-boilerplate-3",
"status": "Error",
"environment": "Development",
"isCurrent": false,
"branch": "test",
"commitHash": "testXyz",
"url": "testProject-QmGEkytE.testProject.snowball.xyz"
"url": "testProject-qmgekyte.testProject.snowball.xyz"
},
{
"projectIndex": 0,
"domainIndex": null,
"createdByIndex": 0,
"id":"f8wsyim6",
"title": "nextjs-boilerplate-4",
"status": "Ready",
"environment": "Production",
"isCurrent": false,
"branch": "prod",
"commitHash": "testXyz",
"url": "testProject-F8WSYiM6.testProject.snowball.xyz"
"url": "testProject-f8wsyim6.testProject.snowball.xyz"
},
{
"projectIndex": 1,
"domainIndex":3,
"createdByIndex": 1,
"id":"eO8cckxk",
"title": "nextjs-boilerplate-1",
"status": "Building",
"environment": "Production",
"isCurrent": true,
"branch": "main",
"commitHash": "testXyz",
"url": "testProject-2-eO8CcKxK.testProject-2.snowball.xyz"
"url": "testProject-2-eO8cckxk.testProject-2.snowball.xyz"
},
{
"projectIndex": 1,
"domainIndex":4,
"createdByIndex": 1,
"id":"yaq0t5yw",
"title": "nextjs-boilerplate-2",
"status": "Ready",
"environment": "Preview",
"isCurrent": false,
"branch": "test",
"commitHash": "testXyz",
"url": "testProject-2-yaQ0t5YW.testProject-2.snowball.xyz"
"url": "testProject-2-yaq0t5yw.testProject-2.snowball.xyz"
},
{
"projectIndex": 1,
"domainIndex":5,
"createdByIndex": 1,
"id":"hwwr6sbx",
"title": "nextjs-boilerplate-3",
"status": "Error",
"environment": "Development",
"isCurrent": false,
"branch": "test",
"commitHash": "testXyz",
"url": "testProject-2-HWwR6SBx.testProject-2.snowball.xyz"
"url": "testProject-2-hwwr6sbx.testProject-2.snowball.xyz"
},
{
"projectIndex": 2,
"domainIndex":6,
"createdByIndex": 2,
"id":"ndxje48a",
"title": "nextjs-boilerplate-1",
"status": "Building",
"environment": "Production",
"isCurrent": true,
"branch": "main",
"commitHash": "testXyz",
"url": "iglootools-ndXJE48a.iglootools.snowball.xyz"
"url": "iglootools-ndxje48a.iglootools.snowball.xyz"
},
{
"projectIndex": 2,
"domainIndex":7,
"createdByIndex": 2,
"id":"gtgpgvei",
"title": "nextjs-boilerplate-2",
"status": "Ready",
"environment": "Preview",
"isCurrent": false,
"branch": "test",
"commitHash": "testXyz",
"url": "iglootools-gtGPgVEi.iglootools.snowball.xyz"
"url": "iglootools-gtgpgvei.iglootools.snowball.xyz"
},
{
"projectIndex": 2,
"domainIndex":8,
"createdByIndex": 2,
"id":"b4bpthjr",
"title": "nextjs-boilerplate-3",
"status": "Error",
"environment": "Development",
"isCurrent": false,
"branch": "test",
"commitHash": "testXyz",
"url": "iglootools-B4BPtHjR.iglootools.snowball.xyz"
"url": "iglootools-b4bpthjr.iglootools.snowball.xyz"
}
]

View File

@ -25,7 +25,8 @@ const ProjectCard: React.FC<ProjectCardProps> = ({ project }) => {
<Link to={`projects/${project.id}`}>
<Typography>{project.name}</Typography>
<Typography color="gray" variant="small">
{project.subDomain ?? 'No sub domain'}
{project.deployments[0]?.domain?.name ??
'No Production Deployment'}
</Typography>
</Link>
</div>

View File

@ -1,4 +1,5 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Project } from 'gql-client';
import { Button, Typography } from '@material-tailwind/react';
@ -10,7 +11,6 @@ import FilterForm, {
import { DeploymentDetails } from '../../../types/project';
import { useGQLClient } from '../../../context/GQLClientContext';
import { COMMIT_DETAILS } from '../../../constants';
import { Project } from 'gql-client';
const DEFAULT_FILTER_VALUE: FilterValue = {
searchedBranch: '',

View File

@ -23,7 +23,7 @@ const OverviewTabPanel = ({ project }: OverviewProps) => {
<div className="grow">
<Typography>{project.name}</Typography>
<Typography variant="small" color="gray">
{project.subDomain ?? 'No sub domain'}
{project.subDomain}
</Typography>
</div>
</div>

View File

@ -1,4 +1,7 @@
import React from 'react';
import { CopyBlock, atomOneLight } from 'react-code-blocks';
import { Link } from 'react-router-dom';
import {
Button,
Dialog,
@ -6,8 +9,6 @@ import {
DialogBody,
DialogFooter,
} from '@material-tailwind/react';
import { CopyBlock, atomOneLight } from 'react-code-blocks';
import { Link } from 'react-router-dom';
interface AssignDomainProps {
open: boolean;

View File

@ -10559,16 +10559,16 @@ mz@^2.4.0, mz@^2.7.0:
object-assign "^4.0.1"
thenify-all "^1.0.0"
nanoid-dictionary@^5.0.0-beta.1:
version "5.0.0-beta.1"
resolved "https://registry.yarnpkg.com/nanoid-dictionary/-/nanoid-dictionary-5.0.0-beta.1.tgz#f2a2aa05b04f7ac6a9327c62a96146e8aa1b025d"
integrity sha512-xBkL9zzkNjzJ/UnmWyiOUDVX/COoi05eS0oU28RYKFFQhdnzO5dTOPbVZ/fCFgIOGr1zNinDHJ68mm/KQfcgcw==
nanoid@3, nanoid@^3.3.6, nanoid@^3.3.7:
version "3.3.7"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz"
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
nanoid@^5.0.5:
version "5.0.5"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.5.tgz#5112efb5c0caf4fc80680d66d303c65233a79fdd"
integrity sha512-/Veqm+QKsyMY3kqi4faWplnY1u+VuKO3dD2binyPIybP31DRO29bPF+1mszgLnrR2KqSLceFLBNw0zmvDzN1QQ==
napi-build-utils@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"