diff --git a/src/Schema/collections/channel.ts b/src/Schema/collections/channel.ts index 58f19a88..ced4d8a4 100644 --- a/src/Schema/collections/channel.ts +++ b/src/Schema/collections/channel.ts @@ -1,7 +1,5 @@ import { pgTable, text, integer, boolean } from "drizzle-orm/pg-core"; -import { relations } from "drizzle-orm/relations"; import { guilds } from "./guild.js"; -import { voiceStates } from "./voice.js"; export const channels = pgTable("channels", { id: text("id").primaryKey(), @@ -23,40 +21,15 @@ export const channels = pgTable("channels", { messageCount: integer("message_count"), defaultAutoArchiveDuration: integer("default_auto_archive_duration"), permissions: text("permissions"), - flags: integer("flags") -}); + flags: integer("flags"), -export const guildsChannels = pgTable("guild_channels", { - id: text("id").primaryKey().references(() => channels.id, { onDelete: "cascade" }), - guildId: text("guild_id").references(() => guilds.id, { onDelete: "cascade" }) + guildId: text("guild_id").references(() => guilds.id, { onDelete: "cascade" }), }); export const channelsOverwrite = pgTable("channels_overwrite", { id: text("id").primaryKey().references(() => channels.id, { onDelete: "cascade" }), + type: integer("type"), allow: text("allow"), deny: text("deny") }); - -export const channelsRelation = relations(channels, ({ many }) => ({ - permission_overwrites: many(channelsOverwrite) -})); - -export const guildChannelsRelations = relations(guildsChannels, ({ many, one }) => ({ - states: many(voiceStates), - channel: one(channels, { - fields: [guildsChannels.id], - references: [channels.id] - }), - guild: one(guilds, { - fields: [guildsChannels.id], - references: [guilds.id] - }) -})); - -export const channelsOverwriteRelation = relations(channelsOverwrite, ({ one }) => ({ - channel: one(channels, { - fields: [channelsOverwrite.id], - references: [channels.id] - }) -})); diff --git a/src/Schema/collections/guild.ts b/src/Schema/collections/guild.ts index 7321c6aa..98f116af 100644 --- a/src/Schema/collections/guild.ts +++ b/src/Schema/collections/guild.ts @@ -1,7 +1,4 @@ -import { relations } from "drizzle-orm"; import { pgTable, text, boolean, integer } from "drizzle-orm/pg-core"; -import { guildsRoles } from "./roles.js"; -import { voiceStates } from "./voice.js"; export const guilds = pgTable("guilds", { id: text("id").primaryKey(), @@ -42,8 +39,3 @@ export const guilds = pgTable("guilds", { premiumProgressBarEnabled: boolean("premium_progress_bar_enabled"), safetyAlertChannelId: text("safety_alert_channel_id") }); - -export const guildsRelations = relations(guilds, ({ many }) => ({ - roles: many(guildsRoles), - voiceStates: many(voiceStates) -})); diff --git a/src/Schema/collections/member.ts b/src/Schema/collections/member.ts index 47b4884b..382c1552 100644 --- a/src/Schema/collections/member.ts +++ b/src/Schema/collections/member.ts @@ -1,10 +1,11 @@ -import { relations } from "drizzle-orm"; import { pgTable, integer, text, boolean } from "drizzle-orm/pg-core"; -import { memberRoles } from "./roles.js"; import { users } from "./user.js"; +import { guilds } from "./guild.js"; export const members = pgTable("members", { id: text("id").primaryKey().references(() => users.id, { onDelete: "cascade" }), + guildId: text("guild_id").references(() => guilds.id, { onDelete: "cascade" }), + nick: text("nick"), avatar: text("avatar"), flags: integer("flags"), @@ -16,11 +17,3 @@ export const members = pgTable("members", { permissions: integer("permissions"), communicationDisabledUntil: text("communication_disabled_until") }); - -export const membersRelations = relations(members, ({ many, one }) => ({ - roles: many(memberRoles), - user: one(users, { - fields: [members.id], - references: [users.id] - }) -})); diff --git a/src/Schema/collections/message.ts b/src/Schema/collections/message.ts index cd85f2a9..4984dddd 100644 --- a/src/Schema/collections/message.ts +++ b/src/Schema/collections/message.ts @@ -1,12 +1,13 @@ -import { relations } from "drizzle-orm"; import { pgTable, text, boolean, integer } from "drizzle-orm/pg-core"; import { channels } from "./channel.js"; import { users } from "./user.js"; export const messages = pgTable("messages", { id: text("id").primaryKey(), + channelId: text("channel_id").references(() => channels.id, { onDelete: "cascade" }), authorId: text("author_id").references(() => users.id, { onDelete: "set null" }), + content: text("content"), timestamp: text("timestamp"), editedTimestamp: text("edited_timestamp"), @@ -21,14 +22,4 @@ export const messages = pgTable("messages", { position: integer("position") }); -export const messagesRelation = relations(messages, ({ one }) => ({ - channel: one(channels, { - fields: [messages.channelId], - references: [channels.id] - }), - author: one(users, { - fields: [messages.authorId], - references: [users.id] - }) -})); diff --git a/src/Schema/collections/roles.ts b/src/Schema/collections/roles.ts index 8592169c..7152fb83 100644 --- a/src/Schema/collections/roles.ts +++ b/src/Schema/collections/roles.ts @@ -1,4 +1,3 @@ -import { relations } from "drizzle-orm"; import { boolean, integer, pgTable, text } from "drizzle-orm/pg-core"; import { guilds } from "./guild.js"; import { members } from "./member.js"; @@ -14,7 +13,6 @@ export const roles = pgTable("roles", { export const memberRoles = pgTable("member_roles", { id: text("id").primaryKey().references(() => members.id, { onDelete: "cascade" }), - roleId: text("role_id").references(() => roles.id, { onDelete: "cascade" }) }); @@ -22,26 +20,3 @@ export const guildsRoles = pgTable("guild_roles", { id: text("id").primaryKey().references(() => guilds.id, { onDelete: "cascade" }), roleId: text("role_id").references(() => roles.id, { onDelete: "cascade" }) }); - -export const memberRolesRelation = relations(memberRoles, ({ one }) => ({ - role: one(roles, { - fields: [memberRoles.roleId], - references: [roles.id] - }), - member: one(members, { - fields: [memberRoles.id], - references: [members.id] - }) -})); - -export const guildsRolesRelation = relations(guildsRoles, ({ one }) => ({ - role: one(roles, { - fields: [guildsRoles.roleId], - references: [roles.id] - }), - guild: one(guilds, { - fields: [guildsRoles.id], - references: [guilds.id] - }) -})); - diff --git a/src/Schema/collections/session.ts b/src/Schema/collections/session.ts index 73e79332..b552e508 100644 --- a/src/Schema/collections/session.ts +++ b/src/Schema/collections/session.ts @@ -2,9 +2,8 @@ import { integer, pgTable, text } from "drizzle-orm/pg-core"; export const sessions = pgTable("sessions", { id: integer("id").primaryKey(), - resumeURL: text("resume_url").notNull(), sequence: integer("sequence").notNull(), - sessionId: text("session_id").notNull(), + sessionId: text("session_id").notNull().unique(), shardCount: integer("shardCount").notNull() }); diff --git a/src/Schema/collections/voice.ts b/src/Schema/collections/voice.ts index 5350b1f9..bbeb1e53 100644 --- a/src/Schema/collections/voice.ts +++ b/src/Schema/collections/voice.ts @@ -1,14 +1,15 @@ -import { relations } from "drizzle-orm"; -import { pgTable, text, boolean } from "drizzle-orm/pg-core"; -import { guildsChannels } from "./channel.js"; +import { pgTable, text, boolean, integer } from "drizzle-orm/pg-core"; import { guilds } from "./guild.js"; import { members } from "./member.js"; +import { channels } from "./channel.js"; +import { sessions } from "./session.js"; export const voiceStates = pgTable("voice_states", { - channelId: text("channel_id").references(() => guildsChannels.id, { onDelete: "cascade" }), - guildId: text("guild_id").references(() => guilds.id, { onDelete: "cascade" }), memberId: text("member_id").primaryKey().references(() => members.id, { onDelete: "cascade" }), - sessionId: text("session_id"), + guildId: text("guild_id").references(() => guilds.id, { onDelete: "cascade" }), + channelId: text("channel_id").references(() => channels.id, { onDelete: "cascade" }), + sessionId: text("session_id").references(() => sessions.sessionId, { onDelete: "cascade" }), + deaf: boolean("deaf"), mute: boolean("mute"), selfDeaf: boolean("self_deaf"), @@ -18,19 +19,3 @@ export const voiceStates = pgTable("voice_states", { suppress: boolean("suppress"), requestToSpeakTimestamp: text("request_to_speak_timestamp") }); - -export const voiceStatesRelation = relations(voiceStates, ({ one }) => ({ - channel: one(guildsChannels, { - fields: [voiceStates.channelId], - references: [guildsChannels.id] - }), - guild: one(guilds, { - fields: [voiceStates.guildId], - references: [guilds.id] - }), - member: one(members, { - fields: [voiceStates.memberId], - references: [members.id] - }) -})); -