Skip to content

Commit 0773d1e

Browse files
committed
[create-pull-request] automated change
1 parent eab040a commit 0773d1e

File tree

2 files changed

+271
-9
lines changed

2 files changed

+271
-9
lines changed

database/migrations/relations.ts

Lines changed: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ import {
88
neptunUserFile,
99
githubAppInstallation,
1010
githubAppInstallationRepository,
11-
neptunUserTemplate,
11+
neptunContextFile,
12+
neptunContextImport,
13+
neptunUserProject,
14+
projectChatConversation,
15+
projectGithubInstallation,
16+
projectTemplateCollection,
1217
neptunUserTemplateCollection,
18+
projectUserFile,
19+
neptunUserTemplate,
1320
chatConversationShare,
1421
chatConversationShareWhitelistEntry,
1522
} from "./schema.js";
@@ -23,6 +30,7 @@ export const chatConversationRelations = relations(
2330
}),
2431
chatConversationMessages: many(chatConversationMessage),
2532
chatConversationFiles: many(chatConversationFile),
33+
projectChatConversations: many(projectChatConversation),
2634
chatConversationShares: many(chatConversationShare),
2735
}),
2836
);
@@ -33,6 +41,9 @@ export const neptunUserRelations = relations(neptunUser, ({ many }) => ({
3341
chatConversationMessages: many(chatConversationMessage),
3442
chatConversationFiles: many(chatConversationFile),
3543
githubAppInstallations: many(githubAppInstallation),
44+
neptunContextFiles: many(neptunContextFile),
45+
neptunContextImports: many(neptunContextImport),
46+
neptunUserProjects: many(neptunUserProject),
3647
neptunUserTemplates: many(neptunUserTemplate),
3748
neptunUserFiles: many(neptunUserFile),
3849
neptunUserTemplateCollections: many(neptunUserTemplateCollection),
@@ -92,6 +103,7 @@ export const neptunUserFileRelations = relations(
92103
neptunUserFile,
93104
({ one, many }) => ({
94105
chatConversationFiles: many(chatConversationFile),
106+
projectUserFiles: many(projectUserFile),
95107
neptunUserTemplates: many(neptunUserTemplate),
96108
neptunUser: one(neptunUser, {
97109
fields: [neptunUserFile.neptunUserId],
@@ -108,6 +120,7 @@ export const githubAppInstallationRelations = relations(
108120
references: [neptunUser.id],
109121
}),
110122
githubAppInstallationRepositories: many(githubAppInstallationRepository),
123+
projectGithubInstallations: many(projectGithubInstallation),
111124
}),
112125
);
113126

@@ -121,27 +134,101 @@ export const githubAppInstallationRepositoryRelations = relations(
121134
}),
122135
);
123136

124-
export const neptunUserTemplateRelations = relations(
125-
neptunUserTemplate,
137+
export const neptunContextFileRelations = relations(
138+
neptunContextFile,
126139
({ one }) => ({
127140
neptunUser: one(neptunUser, {
128-
fields: [neptunUserTemplate.neptunUserId],
141+
fields: [neptunContextFile.neptunUserId],
129142
references: [neptunUser.id],
130143
}),
144+
neptunContextImport: one(neptunContextImport, {
145+
fields: [neptunContextFile.importId],
146+
references: [neptunContextImport.id],
147+
}),
148+
neptunUserProject: one(neptunUserProject, {
149+
fields: [neptunContextFile.projectId],
150+
references: [neptunUserProject.id],
151+
}),
152+
}),
153+
);
154+
155+
export const neptunContextImportRelations = relations(
156+
neptunContextImport,
157+
({ one, many }) => ({
158+
neptunContextFiles: many(neptunContextFile),
159+
neptunUser: one(neptunUser, {
160+
fields: [neptunContextImport.neptunUserId],
161+
references: [neptunUser.id],
162+
}),
163+
neptunUserProject: one(neptunUserProject, {
164+
fields: [neptunContextImport.projectId],
165+
references: [neptunUserProject.id],
166+
}),
167+
}),
168+
);
169+
170+
export const neptunUserProjectRelations = relations(
171+
neptunUserProject,
172+
({ one, many }) => ({
173+
neptunContextFiles: many(neptunContextFile),
174+
neptunContextImports: many(neptunContextImport),
175+
neptunUser: one(neptunUser, {
176+
fields: [neptunUserProject.neptunUserId],
177+
references: [neptunUser.id],
178+
}),
179+
projectChatConversations: many(projectChatConversation),
180+
projectGithubInstallations: many(projectGithubInstallation),
181+
projectTemplateCollections: many(projectTemplateCollection),
182+
projectUserFiles: many(projectUserFile),
183+
}),
184+
);
185+
186+
export const projectChatConversationRelations = relations(
187+
projectChatConversation,
188+
({ one }) => ({
189+
neptunUserProject: one(neptunUserProject, {
190+
fields: [projectChatConversation.projectId],
191+
references: [neptunUserProject.id],
192+
}),
193+
chatConversation: one(chatConversation, {
194+
fields: [projectChatConversation.chatConversationId],
195+
references: [chatConversation.id],
196+
}),
197+
}),
198+
);
199+
200+
export const projectGithubInstallationRelations = relations(
201+
projectGithubInstallation,
202+
({ one }) => ({
203+
neptunUserProject: one(neptunUserProject, {
204+
fields: [projectGithubInstallation.projectId],
205+
references: [neptunUserProject.id],
206+
}),
207+
githubAppInstallation: one(githubAppInstallation, {
208+
fields: [projectGithubInstallation.githubInstallationId],
209+
references: [githubAppInstallation.id],
210+
}),
211+
}),
212+
);
213+
214+
export const projectTemplateCollectionRelations = relations(
215+
projectTemplateCollection,
216+
({ one }) => ({
217+
neptunUserProject: one(neptunUserProject, {
218+
fields: [projectTemplateCollection.projectId],
219+
references: [neptunUserProject.id],
220+
}),
131221
neptunUserTemplateCollection: one(neptunUserTemplateCollection, {
132-
fields: [neptunUserTemplate.templateCollectionId],
222+
fields: [projectTemplateCollection.templateCollectionId],
133223
references: [neptunUserTemplateCollection.id],
134224
}),
135-
neptunUserFile: one(neptunUserFile, {
136-
fields: [neptunUserTemplate.userFileId],
137-
references: [neptunUserFile.id],
138-
}),
139225
}),
140226
);
141227

142228
export const neptunUserTemplateCollectionRelations = relations(
143229
neptunUserTemplateCollection,
144230
({ one, many }) => ({
231+
projectTemplateCollections: many(projectTemplateCollection),
145232
neptunUserTemplates: many(neptunUserTemplate),
146233
neptunUser: one(neptunUser, {
147234
fields: [neptunUserTemplateCollection.neptunUserId],
@@ -150,6 +237,38 @@ export const neptunUserTemplateCollectionRelations = relations(
150237
}),
151238
);
152239

240+
export const projectUserFileRelations = relations(
241+
projectUserFile,
242+
({ one }) => ({
243+
neptunUserProject: one(neptunUserProject, {
244+
fields: [projectUserFile.projectId],
245+
references: [neptunUserProject.id],
246+
}),
247+
neptunUserFile: one(neptunUserFile, {
248+
fields: [projectUserFile.userFileId],
249+
references: [neptunUserFile.id],
250+
}),
251+
}),
252+
);
253+
254+
export const neptunUserTemplateRelations = relations(
255+
neptunUserTemplate,
256+
({ one }) => ({
257+
neptunUser: one(neptunUser, {
258+
fields: [neptunUserTemplate.neptunUserId],
259+
references: [neptunUser.id],
260+
}),
261+
neptunUserTemplateCollection: one(neptunUserTemplateCollection, {
262+
fields: [neptunUserTemplate.templateCollectionId],
263+
references: [neptunUserTemplateCollection.id],
264+
}),
265+
neptunUserFile: one(neptunUserFile, {
266+
fields: [neptunUserTemplate.userFileId],
267+
references: [neptunUserFile.id],
268+
}),
269+
}),
270+
);
271+
153272
export const chatConversationShareRelations = relations(
154273
chatConversationShare,
155274
({ one, many }) => ({

database/migrations/schema.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
integer,
88
unique,
99
boolean,
10+
jsonb,
1011
uuid,
1112
} from "drizzle-orm/pg-core";
1213

@@ -27,10 +28,46 @@ export const chatConversationMessageActorEnum = pgEnum(
2728
"chat_conversation_message_actor_enum",
2829
["user", "assistant"],
2930
);
31+
export const contextFileCategory = pgEnum("context_file_category", [
32+
"bundler",
33+
"build_tool",
34+
"server",
35+
"package_manager",
36+
"runtime",
37+
"documentation",
38+
"test_tool",
39+
"unknown",
40+
]);
41+
export const contextFileType = pgEnum("context_file_type", [
42+
"markdown",
43+
"pdf",
44+
"text",
45+
]);
46+
export const importSourceType = pgEnum("import_source_type", [
47+
"local_folder",
48+
"github_repository_installation",
49+
"public_github_repository_url",
50+
]);
3051
export const oauthProviderEnum = pgEnum("oauth_provider_enum", [
3152
"github",
3253
"google",
3354
]);
55+
export const programmingLanguage = pgEnum("programming_language", [
56+
"typescript",
57+
"javascript",
58+
"php",
59+
"go",
60+
"python",
61+
"java",
62+
"kotlin",
63+
"ruby",
64+
"elixir",
65+
]);
66+
export const projectType = pgEnum("project_type", [
67+
"web-site",
68+
"web-service",
69+
"web-app",
70+
]);
3471

3572
export const chatConversation = pgTable("chat_conversation", {
3673
id: serial("id").primaryKey().notNull(),
@@ -147,6 +184,112 @@ export const githubAppInstallationRepository = pgTable(
147184
},
148185
);
149186

187+
export const neptunContextFile = pgTable("neptun_context_file", {
188+
id: serial("id").primaryKey().notNull(),
189+
title: text("title").notNull(),
190+
originalPath: text("original_path").notNull(),
191+
content: text("content").notNull(),
192+
fileType: contextFileType("file_type").notNull(),
193+
category: contextFileCategory("category"),
194+
fileSize: integer("file_size"),
195+
pdfUrl: text("pdf_url"),
196+
language: text("language").default("text").notNull(),
197+
metadata: jsonb("metadata"),
198+
parentPath: text("parent_path"),
199+
depth: integer("depth").default(0),
200+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
201+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
202+
neptunUserId: integer("neptun_user_id")
203+
.notNull()
204+
.references(() => neptunUser.id, { onDelete: "cascade" }),
205+
importId: integer("import_id")
206+
.notNull()
207+
.references(() => neptunContextImport.id, { onDelete: "cascade" }),
208+
projectId: integer("project_id").references(() => neptunUserProject.id, {
209+
onDelete: "cascade",
210+
}),
211+
});
212+
213+
export const neptunContextImport = pgTable("neptun_context_import", {
214+
id: serial("id").primaryKey().notNull(),
215+
sourceType: importSourceType("source_type").notNull(),
216+
sourcePath: text("source_path").notNull(),
217+
sourceRef: text("source_ref"),
218+
importStatus: text("import_status").default("pending").notNull(),
219+
errorMessage: text("error_message"),
220+
fileTree: jsonb("file_tree"),
221+
excludePatterns: text("exclude_patterns").array(),
222+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
223+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
224+
neptunUserId: integer("neptun_user_id")
225+
.notNull()
226+
.references(() => neptunUser.id, { onDelete: "cascade" }),
227+
projectId: integer("project_id").references(() => neptunUserProject.id, {
228+
onDelete: "cascade",
229+
}),
230+
});
231+
232+
export const neptunUserProject = pgTable("neptun_user_project", {
233+
id: serial("id").primaryKey().notNull(),
234+
name: text("name").notNull(),
235+
description: text("description"),
236+
type: projectType("type").notNull(),
237+
mainLanguage: programmingLanguage("main_language").notNull(),
238+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
239+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
240+
neptunUserId: integer("neptun_user_id")
241+
.notNull()
242+
.references(() => neptunUser.id, { onDelete: "cascade" }),
243+
});
244+
245+
export const projectChatConversation = pgTable("project_chat_conversation", {
246+
projectId: integer("project_id")
247+
.notNull()
248+
.references(() => neptunUserProject.id, { onDelete: "cascade" }),
249+
chatConversationId: integer("chat_conversation_id")
250+
.notNull()
251+
.references(() => chatConversation.id, { onDelete: "cascade" }),
252+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
253+
});
254+
255+
export const projectGithubInstallation = pgTable(
256+
"project_github_installation",
257+
{
258+
projectId: integer("project_id")
259+
.notNull()
260+
.references(() => neptunUserProject.id, { onDelete: "cascade" }),
261+
githubInstallationId: integer("github_installation_id")
262+
.notNull()
263+
.references(() => githubAppInstallation.id, { onDelete: "cascade" }),
264+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
265+
},
266+
);
267+
268+
export const projectTemplateCollection = pgTable(
269+
"project_template_collection",
270+
{
271+
projectId: integer("project_id")
272+
.notNull()
273+
.references(() => neptunUserProject.id, { onDelete: "cascade" }),
274+
templateCollectionId: integer("template_collection_id")
275+
.notNull()
276+
.references(() => neptunUserTemplateCollection.id, {
277+
onDelete: "cascade",
278+
}),
279+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
280+
},
281+
);
282+
283+
export const projectUserFile = pgTable("project_user_file", {
284+
projectId: integer("project_id")
285+
.notNull()
286+
.references(() => neptunUserProject.id, { onDelete: "cascade" }),
287+
userFileId: integer("user_file_id")
288+
.notNull()
289+
.references(() => neptunUserFile.id, { onDelete: "cascade" }),
290+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
291+
});
292+
150293
export const neptunUserTemplate = pgTable("neptun_user_template", {
151294
id: serial("id").primaryKey().notNull(),
152295
description: text("description"),

0 commit comments

Comments
 (0)