Remove domain relation from deployments table

This commit is contained in:
IshaVenikar 2025-02-04 11:59:21 +05:30
parent f6b0f95761
commit 3ea43eab42
10 changed files with 29 additions and 125 deletions

View File

@ -158,10 +158,9 @@ export class Database {
.leftJoinAndSelect(
'project.deployments',
'deployments',
'deployments.isCurrent = true AND deployments.isDNS = true'
'deployments.isCurrent = true AND deployments.isCanonical = true'
)
.leftJoinAndSelect('deployments.createdBy', 'user')
.leftJoinAndSelect('deployments.domain', 'domain')
.leftJoinAndSelect('deployments.deployer', 'deployer')
.leftJoinAndSelect('project.owner', 'owner')
.leftJoinAndSelect('project.deployers', 'deployers')
@ -203,9 +202,8 @@ export class Database {
.leftJoinAndSelect(
'project.deployments',
'deployments',
'deployments.isCurrent = true AND deployments.isDNS = true'
'deployments.isCurrent = true AND deployments.isCanonical = true'
)
.leftJoinAndSelect('deployments.domain', 'domain')
.leftJoin('project.projectMembers', 'projectMembers')
.leftJoin('project.organization', 'organization')
.where(
@ -236,7 +234,6 @@ export class Database {
return this.getDeployments({
relations: {
project: true,
domain: true,
createdBy: true,
deployer: true,
},
@ -251,11 +248,10 @@ export class Database {
});
}
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
async getNonCanonicalDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
return this.getDeployments({
relations: {
project: true,
domain: true,
createdBy: true,
deployer: true,
},
@ -263,7 +259,7 @@ export class Database {
project: {
id: projectId
},
isDNS: false
isCanonical: false
},
order: {
createdAt: 'DESC'

View File

@ -78,13 +78,6 @@ export class Deployment {
@JoinColumn({ name: 'projectId' })
project!: Project;
@Column({ nullable: true })
domainId!: string | null;
@OneToOne(() => Domain)
@JoinColumn({ name: 'domainId' })
domain!: Domain | null;
@Column('varchar')
branch!: string;
@ -142,9 +135,8 @@ export class Deployment {
@Column('boolean', { default: false })
isCurrent!: boolean;
// TODO: Rename field
@Column('boolean', { default: false })
isDNS!: boolean;
isCanonical!: boolean;
@Column({
enum: DeploymentStatus

View File

@ -38,7 +38,7 @@ export const createResolvers = async (service: Service): Promise<any> => {
},
deployments: async (_: any, { projectId }: { projectId: string }) => {
return service.getCommitDeploymentsByProjectId(projectId);
return service.getNonCanonicalDeploymentsByProjectId(projectId);
},
environmentVariables: async (

View File

@ -100,7 +100,6 @@ type ProjectMember {
type Deployment {
id: String!
domain: Domain
branch: String!
commitHash: String!
commitMessage: String!

View File

@ -228,12 +228,12 @@ export class Service {
deployment.isCurrent = deployment.environment === Environment.Production;
deployment.dnsRecordData = dnsRecordData;
if (deployment.isDNS) {
if (deployment.isCanonical) {
const oldDNSDeployment = await this.db.getDeployment({
where: {
projectId: deployment.project.id,
deployer: deployment.deployer,
isDNS: true,
isCanonical: true,
isCurrent: true,
},
relations: {
@ -255,14 +255,6 @@ export class Service {
await this.db.deleteDeploymentById(oldDNSDeployment.id);
}
// Update domain after the previous DNS deployment is deleted due to unique key constraint for domain
// Set the domain for the new current DNS deployment to the custom domain that was added for that project
const customDomain = await this.db.getOldestDomainByProjectId(deployment.project.id);
if (customDomain) {
deployment.domain = customDomain;
}
}
await this.db.updateDeploymentById(deployment.id, deployment);
@ -301,7 +293,7 @@ export class Service {
projectDeployment.deployer.deployerLrn ===
deployment.deployer.deployerLrn &&
projectDeployment.id !== deployment.id &&
projectDeployment.isDNS == deployment.isDNS,
projectDeployment.isCanonical == deployment.isCanonical,
);
for (const oldDeployment of oldDeployments) {
await this.db.updateDeployment(
@ -493,14 +485,14 @@ export class Service {
return dbProjects;
}
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
const commitDeployments = await this.db.getCommitDeploymentsByProjectId(projectId);
return commitDeployments;
async getNonCanonicalDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
const nonCanonicalDeployments = await this.db.getNonCanonicalDeploymentsByProjectId(projectId);
return nonCanonicalDeployments;
}
async getLatestDNSRecordByProjectId(projectId: string): Promise<DNSRecordAttributes | null> {
const dnsDeployments = await this.db.getLatestDNSRecordByProjectId(projectId);
return dnsDeployments;
const dnsRecord = await this.db.getLatestDNSRecordByProjectId(projectId);
return dnsRecord;
}
async getEnvironmentVariablesByProjectId(
@ -649,18 +641,12 @@ export class Service {
throw new Error('Deployment does not exist');
}
const prodBranchDomains = await this.db.getDomainsByProjectId(
oldDeployment.project.id,
{ branch: oldDeployment.project.prodBranch },
);
const octokit = await this.getOctokit(user.id);
const newDeployment = await this.createDeployment(user.id, octokit, {
project: oldDeployment.project,
branch: oldDeployment.branch,
environment: Environment.Production,
domain: prodBranchDomains[0],
commitHash: oldDeployment.commitHash,
commitMessage: oldDeployment.commitMessage,
deployer: oldDeployment.deployer
@ -689,19 +675,6 @@ export class Service {
commitHash: data.commitHash!,
});
// Update previous deployment with prod branch domain
// TODO: Fix unique constraint error for domain
if (data.domain) {
await this.db.updateDeployment(
{
domainId: data.domain.id,
},
{
domain: null,
},
);
}
let deployer;
if (deployerLrn) {
deployer = await this.db.getDeployerByLRN(deployerLrn);
@ -709,20 +682,19 @@ export class Service {
deployer = data.deployer;
}
console.log("DATA>DOMAIN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",data.domain)
const deployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, false);
const dnsDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true);
const address = await this.getAddress();
const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash);
const environmentVariablesObj = await this.getEnvVariables(data.project!.id!);
// If a custom domain is present then use that as the DNS in the deployment request
const customDomain = await this.db.getOldestDomainByProjectId(data.project!.id!);
// To set project DNS
if (data.environment === Environment.Production) {
const dnsDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true);
// If a custom domain is present then use that as the DNS in the deployment request
const customDomain = await this.db.getOldestDomainByProjectId(data.project!.id!);
// On deleting deployment later, project DNS deployment is also deleted
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
const { applicationDeploymentRequestData, applicationDeploymentRequestId } =
@ -867,7 +839,7 @@ export class Service {
deployerLrn: string,
applicationRecordId: string,
applicationRecordData: ApplicationRecord,
isDNS: boolean,
isCanonical: boolean,
): Promise<Deployment> {
const newDeployment = await this.db.addDeployment({
project: data.project,
@ -878,14 +850,13 @@ export class Service {
status: DeploymentStatus.Building,
applicationRecordId,
applicationRecordData,
domain: data.domain,
createdBy: Object.assign(new User(), {
id: userId,
}),
deployer: Object.assign(new Deployer(), {
deployerLrn,
}),
isDNS
isCanonical
});
log(`Created deployment ${newDeployment.id}`);
@ -1118,9 +1089,6 @@ export class Service {
for await (const project of projects) {
const octokit = await this.getOctokit(project.ownerId);
const [domain] = await this.db.getDomainsByProjectId(project.id, {
branch,
});
const deployers = project.deployers;
if (!deployers) {
@ -1138,7 +1106,6 @@ export class Service {
project.prodBranch === branch
? Environment.Production
: Environment.Preview,
domain,
commitHash: headCommit.id,
commitMessage: headCommit.message,
deployer: deployer
@ -1180,7 +1147,6 @@ export class Service {
const oldDeployment = await this.db.getDeployment({
relations: {
project: true,
domain: true,
deployer: true,
createdBy: true,
},
@ -1206,7 +1172,6 @@ export class Service {
// TODO: Put isCurrent field in project
branch: oldDeployment.branch,
environment: Environment.Production,
domain: oldDeployment.domain,
commitHash: oldDeployment.commitHash,
commitMessage: oldDeployment.commitMessage,
deployer: oldDeployment.deployer
@ -1224,7 +1189,6 @@ export class Service {
// TODO: Implement transactions
const oldCurrentDeployment = await this.db.getDeployment({
relations: {
domain: true,
project: true,
deployer: true,
},
@ -1233,7 +1197,7 @@ export class Service {
id: projectId,
},
isCurrent: true,
isDNS: false,
isCanonical: false,
},
});
@ -1243,12 +1207,12 @@ export class Service {
const oldCurrentDeploymentUpdate = await this.db.updateDeploymentById(
oldCurrentDeployment.id,
{ isCurrent: false, domain: null },
{ isCurrent: false },
);
const newCurrentDeploymentUpdate = await this.db.updateDeploymentById(
deploymentId,
{ isCurrent: true, domain: null },
{ isCurrent: true },
);
const newCurrentDeployment = await this.db.getDeployment({ where: { id: deploymentId }, relations: { project: true, deployer: true } });
@ -1261,19 +1225,7 @@ export class Service {
const customDomain = await this.db.getOldestDomainByProjectId(projectId);
if (customDomain) {
await this.db.updateDeployment(
{
domainId: customDomain.id,
},
{
domain: null,
},
);
}
if(customDomain && applicationDeploymentRequestData) {
newCurrentDeployment.domain = customDomain
if (customDomain && applicationDeploymentRequestData) {
applicationDeploymentRequestData.dns = customDomain.name
}
@ -1326,7 +1278,7 @@ export class Service {
where: {
projectId: deployment.project.id,
deployer: deployment.deployer,
isDNS: true
isCanonical: true
},
relations: {
project: true,

View File

@ -243,7 +243,7 @@ export const DeploymentMenu = ({
setRedeployToProduction((preVal) => !preVal);
}}
deployment={deployment}
domains={deployment.domain ? [deployment.domain] : []}
domains={[]}
isConfirmButtonLoading={isConfirmButtonLoading}
/>
{Boolean(currentDeployment) && (
@ -258,7 +258,7 @@ export const DeploymentMenu = ({
}}
deployment={currentDeployment}
newDeployment={deployment}
domains={currentDeployment.domain ? [currentDeployment.domain] : []}
domains={[]}
/>
)}
<AssignDomainDialog

View File

@ -21,15 +21,6 @@ import { ChangeStateToProductionDialog } from 'components/projects/Dialog/Change
const deployment: Deployment = {
id: '1',
domain: {
id: 'domain1',
branch: 'main',
name: 'example.com',
status: DomainStatus.Live,
redirectTo: null,
createdAt: '1677609600', // 2023-02-25T12:00:00Z
updatedAt: '1677613200', // 2023-02-25T13:00:00Z
},
branch: 'main',
commitHash: 'a1b2c3d',
commitMessage:
@ -254,7 +245,7 @@ const ModalsPage: React.FC = () => {
setRedeployToProduction((preVal) => !preVal)
}
deployment={deployment}
domains={deployment.domain ? [deployment.domain] : []}
domains={[]}
/>
{/* Rollback to this deployment */}
<Button onClick={() => setRollbackDeployment(true)}>
@ -270,7 +261,7 @@ const ModalsPage: React.FC = () => {
}
deployment={deployment}
newDeployment={deployment}
domains={deployment.domain ? [deployment.domain] : []}
domains={[]}
/>
</div>
</div>

View File

@ -100,7 +100,6 @@ export const deployment0: Deployment = {
environment: Environment.Development,
isCurrent: true,
commitHash: 'Commit Hash',
domain: domain0,
commitMessage: 'Commit Message',
createdBy: user,
deployer: {

View File

@ -63,14 +63,6 @@ query ($projectId: String!) {
deployer {
baseDomain
}
domain {
status
branch
createdAt
updatedAt
id
name
}
createdBy {
id
name
@ -118,14 +110,6 @@ query ($organizationSlug: String!) {
applicationDeploymentRecordData {
url
}
domain {
status
branch
createdAt
updatedAt
id
name
}
}
}
}
@ -147,14 +131,6 @@ export const getDeployments = gql`
query ($projectId: String!) {
deployments(projectId: $projectId) {
id
domain{
branch
createdAt
id
name
status
updatedAt
}
branch
commitHash
commitMessage

View File

@ -99,7 +99,6 @@ export type User = {
export type Deployment = {
id: string;
domain: Domain;
branch: string;
commitHash: string;
commitMessage: string;