Fix serverless save when name empty (#6720)

- fix serverless function error on save when name empty
- remove useless unique constraint on serverless function names
This commit is contained in:
martmull
2024-08-23 17:34:31 +02:00
committed by GitHub
parent 5d8162dc09
commit 873a4c1bd1
8 changed files with 38 additions and 24 deletions

View File

@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class RemoveServerlessFunctionUniqueConstraint1724423248330
implements MigrationInterface
{
name = 'RemoveServerlessFunctionUniqueConstraint1724423248330';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "metadata"."serverlessFunction" DROP CONSTRAINT "IndexOnNameAndWorkspaceIdUnique"`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "metadata"."serverlessFunction" ADD CONSTRAINT "IndexOnNameAndWorkspaceIdUnique" UNIQUE ("name", "workspaceId")`,
);
}
}

View File

@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { join } from 'path';
import { tmpdir } from 'os';
import { promises as fs } from 'fs';
@ -137,7 +138,7 @@ export class LocalDriver
});
}
child.kill();
fs.unlink(tmpFilePath);
fs.unlink(tmpFilePath).catch(console.error);
});
child.stderr?.on('data', (data) => {
@ -169,19 +170,19 @@ export class LocalDriver
},
});
child.kill();
fs.unlink(tmpFilePath);
fs.unlink(tmpFilePath).catch(console.error);
});
child.on('error', (error) => {
reject(error);
child.kill();
fs.unlink(tmpFilePath);
fs.unlink(tmpFilePath).catch(console.error);
});
child.on('exit', (code) => {
if (code && code !== 0) {
reject(new Error(`Child process exited with code ${code}`));
fs.unlink(tmpFilePath);
fs.unlink(tmpFilePath).catch(console.error);
}
});

View File

@ -23,7 +23,6 @@ export class UpdateServerlessFunctionInput {
description?: string;
@IsString()
@IsNotEmpty()
@Field()
code: string;
}

View File

@ -17,7 +17,6 @@ export enum ServerlessFunctionRuntime {
}
@Entity('serverlessFunction')
@Unique('IndexOnNameAndWorkspaceIdUnique', ['name', 'workspaceId'])
export class ServerlessFunctionEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

View File

@ -240,18 +240,6 @@ export class ServerlessFunctionService extends TypeOrmQueryService<ServerlessFun
code: FileUpload | string,
workspaceId: string,
) {
const existingServerlessFunction =
await this.serverlessFunctionRepository.findOne({
where: { name: serverlessFunctionInput.name, workspaceId },
});
if (existingServerlessFunction) {
throw new ServerlessFunctionException(
`Function already exists`,
ServerlessFunctionExceptionCode.SERVERLESS_FUNCTION_ALREADY_EXIST,
);
}
let typescriptCode: string;
if (typeof code === 'string') {