Skip to content

Commit f8b2cf5

Browse files
committed
added feature flag schema migration, fixed silly issue with file_config being changed
1 parent c01e34b commit f8b2cf5

2 files changed

Lines changed: 88 additions & 34 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- CreateTable
2+
CREATE TABLE "FeatureFlag" (
3+
"id" TEXT NOT NULL,
4+
"enabled" BOOLEAN NOT NULL DEFAULT false,
5+
"description" TEXT,
6+
7+
CONSTRAINT "FeatureFlag_pkey" PRIMARY KEY ("id")
8+
);
Lines changed: 80 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,108 @@
11
import { Injectable } from '@nestjs/common';
2-
import { FeatureFlag } from '@prisma/client';
3-
import { FeatureFlagProto } from 'juno-proto';
2+
import { FileServiceConfig } from '@prisma/client';
43
import { PrismaService } from 'src/prisma.service';
4+
import { FileConfigProto } from 'juno-proto';
55

66
@Injectable()
7-
export class FeatureFlagService {
7+
export class FileServiceConfigService {
88
constructor(private prisma: PrismaService) {}
99

10-
async createFlag(
11-
request: FeatureFlagProto.CreateFlagRequest,
12-
): Promise<FeatureFlag> {
13-
return this.prisma.featureFlag.create({
10+
async createConfig(
11+
configData: FileConfigProto.CreateFileServiceConfigRequest,
12+
): Promise<FileServiceConfig> {
13+
return this.prisma.fileServiceConfig.create({
1414
data: {
15-
id: request.id,
16-
enabled: request.enabled,
17-
description: request.description,
15+
Project: {
16+
connect: {
17+
id: Number(configData.projectId),
18+
},
19+
},
20+
environment: configData.environment,
21+
},
22+
include: {
23+
Project: true,
24+
buckets: true,
25+
FileServiceFile: true,
1826
},
1927
});
2028
}
2129

22-
async getFlag(
23-
request: FeatureFlagProto.GetFlagRequest,
24-
): Promise<FeatureFlag> {
25-
return this.prisma.featureFlag.findUnique({
30+
async getConfig(
31+
req: FileConfigProto.GetFileServiceConfigRequest,
32+
): Promise<FileServiceConfig | null> {
33+
return this.prisma.fileServiceConfig.findUnique({
2634
where: {
27-
id: request.id,
35+
id_environment: {
36+
id: Number(req.id),
37+
environment: req.environment,
38+
},
39+
},
40+
include: {
41+
Project: true,
42+
buckets: true,
43+
FileServiceFile: true,
2844
},
2945
});
3046
}
3147

32-
// only updates enabled/description if provided in the request (leave unchanged if undefined)
33-
async setFlag(
34-
request: FeatureFlagProto.SetFlagRequest,
35-
): Promise<FeatureFlag> {
36-
return this.prisma.featureFlag.update({
48+
async updateConfig(
49+
req: FileConfigProto.UpdateFileServiceConfigRequest,
50+
): Promise<FileServiceConfig> {
51+
return this.prisma.fileServiceConfig.update({
3752
where: {
38-
id: request.id,
53+
id_environment: {
54+
id: Number(req.id),
55+
environment: req.environment,
56+
},
3957
},
4058
data: {
41-
...(request.enabled !== undefined && { enabled: request.enabled }),
42-
...(request.description !== undefined && {
43-
description: request.description,
44-
}),
59+
buckets: {
60+
deleteMany: {},
61+
// create: configData.buckets.map((bucket) => ({
62+
// bucketName: bucket.bucketName,
63+
// })),
64+
},
65+
Project: {
66+
connect: {
67+
id: Number(req.id),
68+
},
69+
},
70+
FileServiceFile: {
71+
deleteMany: {},
72+
// create:
73+
// configData.files?.map((file) => ({
74+
// fileId: {
75+
// path: file.fileId.path,
76+
// bucketName: file.fileId.bucketName,
77+
// configId: file.fileId.configId,
78+
// },
79+
// metadata: file.metadata,
80+
// })) || [],
81+
},
82+
},
83+
include: {
84+
Project: true,
85+
buckets: true,
86+
FileServiceFile: true,
4587
},
4688
});
4789
}
4890

49-
async deleteFlag(
50-
request: FeatureFlagProto.DeleteFlagRequest,
51-
): Promise<FeatureFlagProto.DeleteFlagResponse> {
52-
await this.prisma.featureFlag.delete({
91+
async deleteConfig(
92+
request: FileConfigProto.DeleteFileServiceConfigRequest,
93+
): Promise<FileServiceConfig> {
94+
return this.prisma.fileServiceConfig.delete({
5395
where: {
54-
id: request.id,
96+
id_environment: {
97+
id: Number(request.id),
98+
environment: request.environment,
99+
},
100+
},
101+
include: {
102+
Project: true,
103+
buckets: true,
104+
FileServiceFile: true,
55105
},
56106
});
57-
58-
return {
59-
success: true,
60-
};
61107
}
62108
}

0 commit comments

Comments
 (0)