138 lines
4.1 KiB
TypeScript
138 lines
4.1 KiB
TypeScript
import type { AdapterAccount } from "@auth/core/adapters";
|
|
import { relations } from "drizzle-orm";
|
|
import {
|
|
integer,
|
|
pgTable,
|
|
primaryKey,
|
|
serial,
|
|
smallint,
|
|
text,
|
|
timestamp,
|
|
varchar,
|
|
} from "drizzle-orm/pg-core";
|
|
|
|
export const users = pgTable("user", {
|
|
id: text("id").notNull().primaryKey(),
|
|
name: text("name"),
|
|
email: text("email").notNull(),
|
|
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
image: text("image"),
|
|
});
|
|
|
|
export const accounts = pgTable(
|
|
"account",
|
|
{
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
type: text("type").$type<AdapterAccount["type"]>().notNull(),
|
|
provider: text("provider").notNull(),
|
|
providerAccountId: text("providerAccountId").notNull(),
|
|
refresh_token: text("refresh_token"),
|
|
access_token: text("access_token"),
|
|
expires_at: integer("expires_at"),
|
|
token_type: text("token_type"),
|
|
scope: text("scope"),
|
|
id_token: text("id_token"),
|
|
session_state: text("session_state"),
|
|
},
|
|
(account) => ({
|
|
compoundKey: primaryKey({
|
|
columns: [account.provider, account.providerAccountId],
|
|
}),
|
|
}),
|
|
);
|
|
|
|
export const sessions = pgTable("session", {
|
|
sessionToken: text("sessionToken").notNull().primaryKey(),
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
});
|
|
|
|
export const verificationTokens = pgTable(
|
|
"verificationToken",
|
|
{
|
|
identifier: text("identifier").notNull(),
|
|
token: text("token").notNull(),
|
|
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
},
|
|
(vt) => ({
|
|
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
}),
|
|
);
|
|
|
|
export const matchPlannings = pgTable("match_planning", {
|
|
id: serial("id").primaryKey(),
|
|
channelId: varchar("channel_id", { length: 19 }).notNull(),
|
|
matchtype: varchar("matchtype", { length: 50 }).notNull(),
|
|
createrId: varchar("creater_id", { length: 19 }).notNull(),
|
|
roleId: varchar("role_id", { length: 19 }).notNull(),
|
|
opponentName: varchar("opponent_name", { length: 100 }).notNull(),
|
|
messageId: varchar("message_id", { length: 19 }).notNull(),
|
|
plannedFor: timestamp("planned_for", { precision: 3 }).notNull(),
|
|
guildId: varchar("guild_id", { length: 19 })
|
|
.notNull()
|
|
.references(() => guilds.id, { onDelete: "cascade" }),
|
|
});
|
|
|
|
export const matchPlanningsRelations = relations(matchPlannings, ({ one }) => ({
|
|
guild: one(guilds, {
|
|
fields: [matchPlannings.guildId],
|
|
references: [guilds.id],
|
|
}),
|
|
}));
|
|
|
|
export const guilds = pgTable("guild", {
|
|
id: varchar("id", { length: 19 }).primaryKey(),
|
|
});
|
|
|
|
export const guildsRelations = relations(guilds, ({ one, many }) => ({
|
|
matches: many(matchPlannings),
|
|
timePlanning: one(timePlannings, {
|
|
fields: [guilds.id],
|
|
references: [timePlannings.guildId],
|
|
}),
|
|
}));
|
|
|
|
export const timePlannings = pgTable("time_planning", {
|
|
id: serial("id").primaryKey(),
|
|
guildId: varchar("guild_id", { length: 19 })
|
|
.references(() => guilds.id, {
|
|
onDelete: "cascade",
|
|
})
|
|
.notNull()
|
|
.unique(),
|
|
channelId: varchar("channel_id", { length: 19 }).notNull(),
|
|
targetWeekday: smallint("target_weekday").notNull(),
|
|
targetHour: smallint("target_hour").notNull(),
|
|
targetMinute: smallint("target_minute").notNull(),
|
|
isAvailableRoleId: varchar("is_available_role_id", { length: 19 }),
|
|
wantsToBeNotifieRoledId: varchar("wants_to_be_notified_role_id", {
|
|
length: 19,
|
|
}),
|
|
});
|
|
|
|
export const timePlanningsRelations = relations(
|
|
timePlannings,
|
|
({ one, many }) => ({
|
|
guild: one(tpMessages),
|
|
messages: many(tpMessages),
|
|
}),
|
|
);
|
|
|
|
export const tpMessages = pgTable("tp_message", {
|
|
messageId: varchar("message_id", { length: 19 }).primaryKey(),
|
|
day: smallint("day").notNull(),
|
|
planId: varchar("plan_id", { length: 19 })
|
|
.notNull()
|
|
.references(() => timePlannings.guildId, { onDelete: "cascade" }),
|
|
});
|
|
|
|
export const tpMessagesRelations = relations(tpMessages, ({ one }) => ({
|
|
timePlanning: one(timePlannings, {
|
|
fields: [tpMessages.messageId],
|
|
references: [timePlannings.channelId],
|
|
}),
|
|
}));
|