Skip to content

Commit 4887af7

Browse files
committed
[create-pull-request] automated change
1 parent 4ab4133 commit 4887af7

File tree

2 files changed

+158
-54
lines changed

2 files changed

+158
-54
lines changed

database/migrations/relations.ts

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { relations } from "drizzle-orm/relations";
22
import {
33
neptunUser,
44
chatConversation,
5-
chatConversationFile,
6-
chatConversationMessage,
75
neptunUserOauthAccount,
6+
chatConversationMessage,
7+
chatConversationFile,
8+
neptunUserFile,
89
githubAppInstallation,
910
githubAppInstallationRepository,
11+
neptunUserTemplate,
12+
neptunUserTemplateCollection,
1013
chatConversationShare,
1114
chatConversationShareWhitelistEntry,
1215
} from "./schema.js";
@@ -18,45 +21,39 @@ export const chatConversationRelations = relations(
1821
fields: [chatConversation.neptunUserId],
1922
references: [neptunUser.id],
2023
}),
21-
chatConversationFiles: many(chatConversationFile),
2224
chatConversationMessages: many(chatConversationMessage),
25+
chatConversationFiles: many(chatConversationFile),
2326
chatConversationShares: many(chatConversationShare),
2427
}),
2528
);
2629

2730
export const neptunUserRelations = relations(neptunUser, ({ many }) => ({
2831
chatConversations: many(chatConversation),
29-
chatConversationFiles: many(chatConversationFile),
30-
chatConversationMessages: many(chatConversationMessage),
3132
neptunUserOauthAccounts: many(neptunUserOauthAccount),
33+
chatConversationMessages: many(chatConversationMessage),
34+
chatConversationFiles: many(chatConversationFile),
3235
githubAppInstallations: many(githubAppInstallation),
36+
neptunUserTemplates: many(neptunUserTemplate),
37+
neptunUserFiles: many(neptunUserFile),
38+
neptunUserTemplateCollections: many(neptunUserTemplateCollection),
3339
chatConversationShareWhitelistEntries: many(
3440
chatConversationShareWhitelistEntry,
3541
),
3642
}));
3743

38-
export const chatConversationFileRelations = relations(
39-
chatConversationFile,
44+
export const neptunUserOauthAccountRelations = relations(
45+
neptunUserOauthAccount,
4046
({ one }) => ({
4147
neptunUser: one(neptunUser, {
42-
fields: [chatConversationFile.neptunUserId],
48+
fields: [neptunUserOauthAccount.neptunUserId],
4349
references: [neptunUser.id],
4450
}),
45-
chatConversation: one(chatConversation, {
46-
fields: [chatConversationFile.chatConversationId],
47-
references: [chatConversation.id],
48-
}),
49-
chatConversationMessage: one(chatConversationMessage, {
50-
fields: [chatConversationFile.chatConversationMessageId],
51-
references: [chatConversationMessage.id],
52-
}),
5351
}),
5452
);
5553

5654
export const chatConversationMessageRelations = relations(
5755
chatConversationMessage,
5856
({ one, many }) => ({
59-
chatConversationFiles: many(chatConversationFile),
6057
neptunUser: one(neptunUser, {
6158
fields: [chatConversationMessage.neptunUserId],
6259
references: [neptunUser.id],
@@ -65,14 +62,39 @@ export const chatConversationMessageRelations = relations(
6562
fields: [chatConversationMessage.chatConversationId],
6663
references: [chatConversation.id],
6764
}),
65+
chatConversationFiles: many(chatConversationFile),
6866
}),
6967
);
7068

71-
export const neptunUserOauthAccountRelations = relations(
72-
neptunUserOauthAccount,
69+
export const chatConversationFileRelations = relations(
70+
chatConversationFile,
7371
({ one }) => ({
7472
neptunUser: one(neptunUser, {
75-
fields: [neptunUserOauthAccount.neptunUserId],
73+
fields: [chatConversationFile.neptunUserId],
74+
references: [neptunUser.id],
75+
}),
76+
chatConversation: one(chatConversation, {
77+
fields: [chatConversationFile.chatConversationId],
78+
references: [chatConversation.id],
79+
}),
80+
chatConversationMessage: one(chatConversationMessage, {
81+
fields: [chatConversationFile.chatConversationMessageId],
82+
references: [chatConversationMessage.id],
83+
}),
84+
neptunUserFile: one(neptunUserFile, {
85+
fields: [chatConversationFile.neptunUserFileId],
86+
references: [neptunUserFile.id],
87+
}),
88+
}),
89+
);
90+
91+
export const neptunUserFileRelations = relations(
92+
neptunUserFile,
93+
({ one, many }) => ({
94+
chatConversationFiles: many(chatConversationFile),
95+
neptunUserTemplates: many(neptunUserTemplate),
96+
neptunUser: one(neptunUser, {
97+
fields: [neptunUserFile.neptunUserId],
7698
references: [neptunUser.id],
7799
}),
78100
}),
@@ -99,6 +121,35 @@ export const githubAppInstallationRepositoryRelations = relations(
99121
}),
100122
);
101123

124+
export const neptunUserTemplateRelations = relations(
125+
neptunUserTemplate,
126+
({ one }) => ({
127+
neptunUser: one(neptunUser, {
128+
fields: [neptunUserTemplate.neptunUserId],
129+
references: [neptunUser.id],
130+
}),
131+
neptunUserTemplateCollection: one(neptunUserTemplateCollection, {
132+
fields: [neptunUserTemplate.templateCollectionId],
133+
references: [neptunUserTemplateCollection.id],
134+
}),
135+
neptunUserFile: one(neptunUserFile, {
136+
fields: [neptunUserTemplate.userFileId],
137+
references: [neptunUserFile.id],
138+
}),
139+
}),
140+
);
141+
142+
export const neptunUserTemplateCollectionRelations = relations(
143+
neptunUserTemplateCollection,
144+
({ one, many }) => ({
145+
neptunUserTemplates: many(neptunUserTemplate),
146+
neptunUser: one(neptunUser, {
147+
fields: [neptunUserTemplateCollection.neptunUserId],
148+
references: [neptunUser.id],
149+
}),
150+
}),
151+
);
152+
102153
export const chatConversationShareRelations = relations(
103154
chatConversationShare,
104155
({ one, many }) => ({

database/migrations/schema.ts

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212

1313
export const aiModelEnum = pgEnum("ai_model_enum", [
1414
"OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
15-
"mistralai/Mistral-7B-Instruct-v0.1",
1615
"meta-llama/Meta-Llama-3-8B-Instruct",
16+
"mistralai/Mistral-7B-Instruct-v0.1",
1717
]);
1818
export const chatConversationMessageActorEnum = pgEnum(
1919
"chat_conversation_message_actor_enum",
@@ -35,39 +35,6 @@ export const chatConversation = pgTable("chat_conversation", {
3535
.references(() => neptunUser.id, { onDelete: "cascade" }),
3636
});
3737

38-
export const chatConversationFile = pgTable("chat_conversation_file", {
39-
id: serial("id").primaryKey().notNull(),
40-
title: text("title"),
41-
language: text("language").default("text").notNull(),
42-
fileExtension: text("file_extension").default("txt").notNull(),
43-
text: text("text").notNull(),
44-
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
45-
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
46-
neptunUserId: integer("neptun_user_id")
47-
.notNull()
48-
.references(() => neptunUser.id, { onDelete: "cascade" }),
49-
chatConversationId: integer("chat_conversation_id")
50-
.notNull()
51-
.references(() => chatConversation.id, { onDelete: "cascade" }),
52-
chatConversationMessageId: integer("chat_conversation_message_id")
53-
.notNull()
54-
.references(() => chatConversationMessage.id, { onDelete: "cascade" }),
55-
});
56-
57-
export const chatConversationMessage = pgTable("chat_conversation_message", {
58-
id: serial("id").primaryKey().notNull(),
59-
message: text("message").notNull(),
60-
actor: chatConversationMessageActorEnum("actor").default("user").notNull(),
61-
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
62-
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
63-
neptunUserId: integer("neptun_user_id")
64-
.notNull()
65-
.references(() => neptunUser.id, { onDelete: "cascade" }),
66-
chatConversationId: integer("chat_conversation_id")
67-
.notNull()
68-
.references(() => chatConversation.id, { onDelete: "cascade" }),
69-
});
70-
7138
export const neptunUser = pgTable(
7239
"neptun_user",
7340
{
@@ -98,6 +65,38 @@ export const neptunUserOauthAccount = pgTable("neptun_user_oauth_account", {
9865
.references(() => neptunUser.id, { onDelete: "cascade" }),
9966
});
10067

68+
export const chatConversationMessage = pgTable("chat_conversation_message", {
69+
id: serial("id").primaryKey().notNull(),
70+
message: text("message").notNull(),
71+
actor: chatConversationMessageActorEnum("actor").default("user").notNull(),
72+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
73+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
74+
neptunUserId: integer("neptun_user_id")
75+
.notNull()
76+
.references(() => neptunUser.id, { onDelete: "cascade" }),
77+
chatConversationId: integer("chat_conversation_id")
78+
.notNull()
79+
.references(() => chatConversation.id, { onDelete: "cascade" }),
80+
});
81+
82+
export const chatConversationFile = pgTable("chat_conversation_file", {
83+
id: serial("id").primaryKey().notNull(),
84+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
85+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
86+
neptunUserId: integer("neptun_user_id")
87+
.notNull()
88+
.references(() => neptunUser.id, { onDelete: "cascade" }),
89+
chatConversationId: integer("chat_conversation_id")
90+
.notNull()
91+
.references(() => chatConversation.id, { onDelete: "cascade" }),
92+
chatConversationMessageId: integer("chat_conversation_message_id")
93+
.notNull()
94+
.references(() => chatConversationMessage.id, { onDelete: "cascade" }),
95+
neptunUserFileId: integer("neptun_user_file_id")
96+
.notNull()
97+
.references(() => neptunUserFile.id, { onDelete: "cascade" }),
98+
});
99+
101100
export const githubAppInstallation = pgTable("github_app_installation", {
102101
id: serial("id").primaryKey().notNull(),
103102
githubAccountType: text("github_account_type").notNull(),
@@ -140,6 +139,24 @@ export const githubAppInstallationRepository = pgTable(
140139
},
141140
);
142141

142+
export const neptunUserTemplate = pgTable("neptun_user_template", {
143+
id: serial("id").primaryKey().notNull(),
144+
description: text("description"),
145+
fileName: text("file_name").notNull(),
146+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
147+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
148+
neptunUserId: integer("neptun_user_id")
149+
.notNull()
150+
.references(() => neptunUser.id, { onDelete: "cascade" }),
151+
templateCollectionId: integer("template_collection_id").references(
152+
() => neptunUserTemplateCollection.id,
153+
{ onDelete: "cascade" },
154+
),
155+
userFileId: integer("user_file_id").references(() => neptunUserFile.id, {
156+
onDelete: "cascade",
157+
}),
158+
});
159+
143160
export const chatConversationShare = pgTable(
144161
"chat_conversation_share",
145162
{
@@ -166,6 +183,42 @@ export const chatConversationShare = pgTable(
166183
},
167184
);
168185

186+
export const neptunUserFile = pgTable("neptun_user_file", {
187+
id: serial("id").primaryKey().notNull(),
188+
title: text("title"),
189+
text: text("text").notNull(),
190+
language: text("language").default("text").notNull(),
191+
fileExtension: text("file_extension").default("txt").notNull(),
192+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
193+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
194+
neptunUserId: integer("neptun_user_id")
195+
.notNull()
196+
.references(() => neptunUser.id, { onDelete: "cascade" }),
197+
});
198+
199+
export const neptunUserTemplateCollection = pgTable(
200+
"neptun_user_template_collection",
201+
{
202+
id: serial("id").primaryKey().notNull(),
203+
name: text("name").notNull(),
204+
description: text("description"),
205+
isShared: boolean("is_shared").default(false).notNull(),
206+
shareId: uuid("share_id").defaultRandom().notNull(),
207+
createdAt: timestamp("created_at", { mode: "string" }).defaultNow(),
208+
updatedAt: timestamp("updated_at", { mode: "string" }).defaultNow(),
209+
neptunUserId: integer("neptun_user_id")
210+
.notNull()
211+
.references(() => neptunUser.id, { onDelete: "cascade" }),
212+
},
213+
(table) => {
214+
return {
215+
neptunUserTemplateCollectionShareIdUnique: unique(
216+
"neptun_user_template_collection_share_id_unique",
217+
).on(table.shareId),
218+
};
219+
},
220+
);
221+
169222
export const chatConversationShareWhitelistEntry = pgTable(
170223
"chat_conversation_share_whitelist_entry",
171224
{

0 commit comments

Comments
 (0)