Skip to content

Commit d541f26

Browse files
Remove TODOs and implement correct types in environmentDataSources.ts (#98)
* Remove TODOs and implement correct types in environmentDataSources.ts * Add delete cascade to datasource properties * Update app/lib/stores/environmentDataSources.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update app/lib/stores/environmentDataSources.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent d8549b7 commit d541f26

7 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎app/components/@settings/tabs/data/forms/AddDataSourceForm.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ interface AddDataSourceFormProps {
5151
onSuccess: () => void;
5252
}
5353

54-
// TODO: @skos update the form to use EnvironmentDataSource
5554
export default function AddDataSourceForm({ isSubmitting, setIsSubmitting, onSuccess }: AddDataSourceFormProps) {
5655
const [dbType, setDbType] = useState<DataSourceOption>(DEFAULT_DATA_SOURCES[0]);
5756
const [dbName, setDbName] = useState('');

‎app/components/@settings/tabs/data/forms/EditDataSourceForm.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ interface EnvironmentsResponse {
4141
error?: string;
4242
}
4343

44-
// TODO: @skos update the form to use EnvironmentDataSource
4544
interface EditDataSourceFormProps {
4645
selectedDataSource: EnvironmentDataSource | null;
4746
isSubmitting: boolean;

‎app/components/DataLoader.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ interface DataLoaderProps {
2828

2929
export function DataLoader({ children, rootData }: DataLoaderProps) {
3030
const { data: session } = useSession();
31-
// TODO: @skos this is the main idea, keep it this way but fetch envId, envName and connectionUrl
3231
const { setEnvironmentDataSources } = useEnvironmentDataSourcesStore();
3332
const { setPluginAccess } = usePluginStore();
3433
const { setDataSourceTypes } = useDataSourceTypesStore();

‎app/lib/services/dataSourceService.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ export function getDataSource(id: string) {
237237
return prisma.dataSource.findUnique({ where: { id } });
238238
}
239239

240-
// TODO: @skos update this and the routes and UI
241240
export async function updateDataSource(data: { id: string; name: string; connectionString: string; userId: string }) {
242241
validateDataSource(data.connectionString);
243242

@@ -247,7 +246,6 @@ export async function updateDataSource(data: { id: string; name: string; connect
247246
});
248247
}
249248

250-
// TODO: @skos update this with environmentId (routes and UI as well)
251249
export async function deleteDataSource(id: string, userId: string) {
252250
return prisma.dataSource.delete({ where: { id, createdById: userId } });
253251
}

‎app/lib/stores/environmentDataSources.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { useRouter } from 'next/navigation';
33
import { persist } from 'zustand/middleware';
44
import { DATA_SOURCE_CONNECTION_ROUTE } from '~/lib/constants/routes';
55

6-
// TODO: @skos we could reassign the prisma types in lib/ to a variable and import here as a type
76
export interface EnvironmentVariable {
87
id: string;
98
key: string;
109
value: string;
1110
description: string | null;
12-
// TODO: @skos the type should be EnvironmentVariableType (but can't import directly from prisma)
13-
type: any;
11+
// this must be synced with EnvironmentVariableType enum in prisma
12+
type: 'GLOBAL' | 'DATA_SOURCE';
1413
environmentId: string;
1514
dataSourceId: string | null;
1615
createdById: string;
@@ -36,11 +35,11 @@ export interface EnvironmentDataSource {
3635
};
3736
dataSourceProperties: [
3837
{
39-
type: any;
38+
// this must be synced with DataSourcePropertyType enum in prisma
39+
type: 'CONNECTION_URL' | 'ACCESS_TOKEN' | 'REFRESH_TOKEN' | 'CLIENT_ID' | 'CLIENT_SECRET' | 'API_KEY';
4040
environmentVariables: EnvironmentVariable[];
4141
},
4242
];
43-
// TODO: @skos this should be DataSourcePropertyType (but can't import from prisma directly)
4443
}
4544

4645
interface EnvironmentDataSourcesStore {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- DropForeignKey
2+
ALTER TABLE "public"."data_source_property" DROP CONSTRAINT "data_source_property_environment_id_data_source_id_fkey";
3+
4+
-- AddForeignKey
5+
ALTER TABLE "public"."data_source_property" ADD CONSTRAINT "data_source_property_environment_id_data_source_id_fkey" FOREIGN KEY ("environment_id", "data_source_id") REFERENCES "public"."environment_data_source"("environment_id", "data_source_id") ON DELETE CASCADE ON UPDATE CASCADE;

‎prisma/schema.prisma‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ model DataSourceProperty {
4949
5050
environmentId String @map("environment_id")
5151
dataSourceId String @map("data_source_id")
52-
environmentDataSource EnvironmentDataSource @relation(fields: [environmentId, dataSourceId], references: [environmentId, dataSourceId])
52+
environmentDataSource EnvironmentDataSource @relation(fields: [environmentId, dataSourceId], references: [environmentId, dataSourceId], onDelete: Cascade)
5353
5454
@@map("data_source_property")
5555
}

0 commit comments

Comments
 (0)