From a8a63a88dc4636986cd4935f102f1d753b3452ba Mon Sep 17 00:00:00 2001 From: armandobelardo Date: Thu, 12 Sep 2024 18:26:51 -0400 Subject: [PATCH] improvement(fdr): add display name to generators table --- fern/apis/fdr/definition/generators/__package__.yml | 1 + .../api/resources/generators/client/Client.ts | 1 + .../api/resources/generators/types/Generator.ts | 1 + .../migration.sql | 10 ++++++++++ servers/fdr/prisma/schema.prisma | 1 + servers/fdr/src/__test__/local/db/generatorDao.test.ts | 7 +++++++ .../src/__test__/local/db/generatorVersionsDao.test.ts | 6 ++++++ .../api/resources/generators/types/Generator.d.ts | 1 + servers/fdr/src/db/generators/GeneratorDao.ts | 2 ++ 9 files changed, 30 insertions(+) create mode 100644 servers/fdr/prisma/migrations/20240912222048_add_generator_display_name/migration.sql diff --git a/fern/apis/fdr/definition/generators/__package__.yml b/fern/apis/fdr/definition/generators/__package__.yml index 62f44b0ee3..1d16e08e12 100644 --- a/fern/apis/fdr/definition/generators/__package__.yml +++ b/fern/apis/fdr/definition/generators/__package__.yml @@ -48,6 +48,7 @@ types: Generator: properties: id: GeneratorId + displayName: string generatorType: GeneratorType generatorLanguage: optional dockerImage: diff --git a/packages/fdr-sdk/src/client/generated/api/resources/generators/client/Client.ts b/packages/fdr-sdk/src/client/generated/api/resources/generators/client/Client.ts index 537277b796..21377d25ef 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/generators/client/Client.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/generators/client/Client.ts @@ -37,6 +37,7 @@ export class Generators { * @example * await fernRegistry.generators.upsertGenerator({ * id: "string", + * displayName: "string", * generatorType: { * type: "sdk" * }, diff --git a/packages/fdr-sdk/src/client/generated/api/resources/generators/types/Generator.ts b/packages/fdr-sdk/src/client/generated/api/resources/generators/types/Generator.ts index 19fc034b0f..efc1811038 100644 --- a/packages/fdr-sdk/src/client/generated/api/resources/generators/types/Generator.ts +++ b/packages/fdr-sdk/src/client/generated/api/resources/generators/types/Generator.ts @@ -6,6 +6,7 @@ import * as FernRegistry from "../../../index"; export interface Generator { id: FernRegistry.generators.GeneratorId; + displayName: string; generatorType: FernRegistry.generators.GeneratorType; generatorLanguage?: FernRegistry.generators.GeneratorLanguage; /** The name of the docker image to pull to run this generator. */ diff --git a/servers/fdr/prisma/migrations/20240912222048_add_generator_display_name/migration.sql b/servers/fdr/prisma/migrations/20240912222048_add_generator_display_name/migration.sql new file mode 100644 index 0000000000..2a1fc1c58d --- /dev/null +++ b/servers/fdr/prisma/migrations/20240912222048_add_generator_display_name/migration.sql @@ -0,0 +1,10 @@ +/* + - adds displayName as nullable column to Generator + - sets displayName to id for all existing rows + - makes displayName not nullable + +*/ +-- AlterTable +ALTER TABLE "Generator" ADD COLUMN "displayName" TEXT; +UPDATE "Generator" SET "displayName" = "id"; +ALTER TABLE "Generator" ALTER COLUMN "displayName" TEXT NOT NULL; diff --git a/servers/fdr/prisma/schema.prisma b/servers/fdr/prisma/schema.prisma index 856c3b9aa3..54d60546e9 100644 --- a/servers/fdr/prisma/schema.prisma +++ b/servers/fdr/prisma/schema.prisma @@ -165,6 +165,7 @@ enum SnippetTemplateSemanticVersion { model Generator { id String @id + displayName String generatorType Bytes dockerImage String @unique generatorLanguage Language? diff --git a/servers/fdr/src/__test__/local/db/generatorDao.test.ts b/servers/fdr/src/__test__/local/db/generatorDao.test.ts index 64fbc6c238..388301edcf 100644 --- a/servers/fdr/src/__test__/local/db/generatorDao.test.ts +++ b/servers/fdr/src/__test__/local/db/generatorDao.test.ts @@ -30,6 +30,7 @@ it("generator dao", async () => { // create snippets const generatorStarter: FdrAPI.generators.Generator = { id: "my-cool/example", + displayName: "My Cool Example", generatorType: { type: "sdk" }, dockerImage: "my-cool/example", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -45,6 +46,7 @@ it("generator dao", async () => { generator: { id: "my-cool/example", generatorType: { type: "sdk" }, + displayName: "My Cool Example", dockerImage: "changing things up", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Typescript, }, @@ -64,6 +66,7 @@ it("generator dao non-unique", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "python-sdk", + displayName: "Python SDK", generatorType: { type: "sdk" }, dockerImage: "my-cool/example", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -73,6 +76,7 @@ it("generator dao non-unique", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "python-sdk-2", + displayName: "Python SDK", generatorType: { type: "sdk" }, dockerImage: "my-cool/example-1", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -82,6 +86,7 @@ it("generator dao non-unique", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "python-sdk-3", + displayName: "Python SDK", generatorType: { type: "sdk" }, dockerImage: "my-cool/example-2", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -95,6 +100,7 @@ it("generator dao non-unique", async () => { it("generator dao image non-unique", async () => { const generator: Generator = { id: "python-sdk-3", + displayName: "Python SDK", generatorType: { type: "sdk" }, dockerImage: "my-cool/example", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -105,6 +111,7 @@ it("generator dao image non-unique", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "python-sdk-15", + displayName: "Python SDK", generatorType: { type: "sdk" }, dockerImage: "my-cool/example", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, diff --git a/servers/fdr/src/__test__/local/db/generatorVersionsDao.test.ts b/servers/fdr/src/__test__/local/db/generatorVersionsDao.test.ts index c3617cd3cc..e6424339ba 100644 --- a/servers/fdr/src/__test__/local/db/generatorVersionsDao.test.ts +++ b/servers/fdr/src/__test__/local/db/generatorVersionsDao.test.ts @@ -16,6 +16,7 @@ it("generator version dao not semver", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "this-fails-semver", + displayName: "An SDK", generatorType: { type: "sdk" }, dockerImage: "this-fails-semver", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -38,6 +39,7 @@ it("generator version get latest respects semver, not time", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "this-picks-latest", + displayName: "An SDK", generatorType: { type: "sdk" }, dockerImage: "this-picks-latest", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -94,6 +96,7 @@ it("generator changelog", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "this-gets-changelog", + displayName: "An SDK", generatorType: { type: "sdk" }, dockerImage: "this-gets-changelog", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -270,6 +273,7 @@ it("generator version happy path update", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "this-is-the-happy-path", + displayName: "An SDK", generatorType: { type: "sdk" }, dockerImage: "this-is-the-happy-path", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -331,6 +335,7 @@ it("get generator that works for cli version", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "this-is-cli-restricted", + displayName: "An SDK", generatorType: { type: "sdk" }, dockerImage: "this-is-cli-restricted", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, @@ -399,6 +404,7 @@ it("get generator retain major version", async () => { await fdrApplication.dao.generators().upsertGenerator({ generator: { id: "this-is-major-version-restricted", + displayName: "An SDK", generatorType: { type: "sdk" }, dockerImage: "this-is-major-version-restricted", generatorLanguage: FdrAPI.generators.GeneratorLanguage.Python, diff --git a/servers/fdr/src/api/generated/api/resources/generators/types/Generator.d.ts b/servers/fdr/src/api/generated/api/resources/generators/types/Generator.d.ts index 233df8757a..3b72e20a99 100644 --- a/servers/fdr/src/api/generated/api/resources/generators/types/Generator.d.ts +++ b/servers/fdr/src/api/generated/api/resources/generators/types/Generator.d.ts @@ -4,6 +4,7 @@ import * as FernRegistry from "../../../index"; export interface Generator { id: FernRegistry.generators.GeneratorId; + displayName: string; generatorType: FernRegistry.generators.GeneratorType; generatorLanguage?: FernRegistry.generators.GeneratorLanguage; /** The name of the docker image to pull to run this generator. */ diff --git a/servers/fdr/src/db/generators/GeneratorDao.ts b/servers/fdr/src/db/generators/GeneratorDao.ts index ebc19f8f09..6c63312c3a 100644 --- a/servers/fdr/src/db/generators/GeneratorDao.ts +++ b/servers/fdr/src/db/generators/GeneratorDao.ts @@ -81,6 +81,7 @@ export class GeneratorsDaoImpl implements GeneratorsDao { // We always just write over the previous entry here const data = { id: generator.id, + displayName: generator.displayName, generatorType: writeBuffer(generator.generatorType), generatorLanguage: convertGeneratorLanguage(generator.generatorLanguage), dockerImage: generator.dockerImage, @@ -155,6 +156,7 @@ function convertPrismaGenerator(generator: prisma.Generator | null): Generator | return generator != null ? { id: generator.id, + displayName: generator.displayName, generatorType: readBuffer(generator.generatorType) as GeneratorType, generatorLanguage: convertPrismaLanguage(generator.generatorLanguage), dockerImage: generator.dockerImage,