diff --git a/packages/backend/package.json b/packages/backend/package.json index be7f3372..0d6d216c 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -41,6 +41,7 @@ "lint": "tsc --noEmit", "test:registry:init": "DEBUG=snowball:* ts-node ./test/initialize-registry.ts", "test:registry:publish-deploy-records": "DEBUG=snowball:* ts-node ./test/publish-deploy-records.ts", + "test:registry:publish-deployment-removal-records": "DEBUG=snowball:* ts-node ./test/publish-deployment-removal-records.ts", "test:db:load:fixtures": "DEBUG=snowball:* ts-node ./test/initialize-db.ts", "test:db:delete": "DEBUG=snowball:* ts-node ./test/delete-db.ts" }, diff --git a/packages/backend/src/entity/Deployment.ts b/packages/backend/src/entity/Deployment.ts index d61ad141..4535ea27 100644 --- a/packages/backend/src/entity/Deployment.ts +++ b/packages/backend/src/entity/Deployment.ts @@ -6,7 +6,8 @@ import { UpdateDateColumn, ManyToOne, OneToOne, - JoinColumn + JoinColumn, + DeleteDateColumn } from 'typeorm'; import { Project } from './Project'; @@ -146,4 +147,7 @@ export class Deployment { @UpdateDateColumn() updatedAt!: Date; + + @DeleteDateColumn() + deletedAt!: Date | null; } diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 5ba963c8..7aa47991 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -19,6 +19,7 @@ enum DeploymentStatus { Building Ready Error + Deleting } enum DomainStatus { diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index b939325e..cba99a48 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -52,6 +52,8 @@ export class Service { init (): void { // Start check for ApplicationDeploymentRecords asynchronously this.checkDeployRecordsAndUpdate(); + // Start check for ApplicationDeploymentRemovalRecords asynchronously + this.checkDeploymentRemovalRecordsAndUpdate(); } /** diff --git a/packages/backend/test/publish-deployment-removal-records.ts b/packages/backend/test/publish-deployment-removal-records.ts new file mode 100644 index 00000000..d8b026a3 --- /dev/null +++ b/packages/backend/test/publish-deployment-removal-records.ts @@ -0,0 +1,67 @@ +import debug from 'debug'; +import { DataSource } from 'typeorm'; +import path from 'path'; + +import { Registry } from '@cerc-io/laconic-sdk'; + +import { Config } from '../src/config'; +import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants'; +import { getConfig } from '../src/utils'; +import { Deployment, DeploymentStatus } from '../src/entity/Deployment'; + +const log = debug('snowball:publish-deployment-removal-records'); + +async function main () { + const { registryConfig, database, misc } = await getConfig(DEFAULT_CONFIG_FILE_PATH); + + const registry = new Registry( + registryConfig.gqlEndpoint, + registryConfig.restEndpoint, + registryConfig.chainId + ); + + const dataSource = new DataSource({ + type: 'better-sqlite3', + database: database.dbPath, + synchronize: true, + entities: [path.join(__dirname, '../src/entity/*')] + }); + + await dataSource.initialize(); + + const deploymentRepository = dataSource.getRepository(Deployment); + const deployments = await deploymentRepository.find({ + relations: { + project: true + }, + where: { + status: DeploymentStatus.Deleting + } + }); + + for await (const deployment of deployments) { + const applicationDeploymentRemovalRecord = { + type: "ApplicationDeploymentRemovalRecord", + version: "1.0.0", + deployment: deployment.applicationDeploymentRecordId, + request: deployment.applicationDeploymentRemovalRequestId, + } + + const result = await registry.setRecord( + { + privateKey: registryConfig.privateKey, + record: applicationDeploymentRemovalRecord, + bondId: registryConfig.bondId + }, + '', + registryConfig.fee + ); + + log('Application deployment removal record data:', applicationDeploymentRemovalRecord); + log(`Application deployment removal record published: ${result.data.id}`); + } +} + +main().catch((err) => { + log(err); +});