mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-18 21:11:39 +01:00
rewrite kd leaderboard generation, add explicit relations to schema
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import type { AccessToken } from "@twurple/auth";
|
||||
import type { inventory, items } from "items";
|
||||
|
||||
import { integer, jsonb, pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
|
||||
import type { anivBots } from "lib/handleAnivMessage";
|
||||
import { relations } from "drizzle-orm";
|
||||
|
||||
export const auth = pgTable('auth', {
|
||||
id: integer().primaryKey(),
|
||||
@@ -17,6 +17,16 @@ export const users = pgTable('users', {
|
||||
lastlootbox: timestamp().default(new Date(0)).notNull()
|
||||
});
|
||||
|
||||
export const usersRelations = relations(users, ({ many }) => ({
|
||||
timeouts_target: many(timeouts),
|
||||
timeouts_shooter: many(timeouts),
|
||||
usedItems: many(usedItems),
|
||||
cheerEvents: many(cheerEvents),
|
||||
cheers: many(cheers),
|
||||
anivTimeouts: many(anivTimeouts),
|
||||
getLoots: many(getLoots)
|
||||
}));
|
||||
|
||||
export const timeouts = pgTable('timeouts', {
|
||||
id: uuid().defaultRandom().primaryKey(),
|
||||
user: integer().notNull().references(() => users.id),
|
||||
@@ -25,6 +35,19 @@ export const timeouts = pgTable('timeouts', {
|
||||
created: timestamp().defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const timeoutsRelations = relations(timeouts, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [timeouts.user],
|
||||
references: [users.id],
|
||||
relationName: 'shooter'
|
||||
}),
|
||||
target: one(users, {
|
||||
fields: [timeouts.target],
|
||||
references: [users.id],
|
||||
relationName: 'target'
|
||||
})
|
||||
}))
|
||||
|
||||
export const usedItems = pgTable('usedItems', {
|
||||
id: uuid().defaultRandom().primaryKey(),
|
||||
user: integer().notNull().references(() => users.id),
|
||||
@@ -32,6 +55,13 @@ export const usedItems = pgTable('usedItems', {
|
||||
created: timestamp().defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const usedItemsRelations = relations(usedItems, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [usedItems.user],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const cheerEvents = pgTable('cheerEvents', {
|
||||
id: uuid().defaultRandom().primaryKey(),
|
||||
user: integer().notNull().references(() => users.id),
|
||||
@@ -39,6 +69,13 @@ export const cheerEvents = pgTable('cheerEvents', {
|
||||
created: timestamp().defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const cheerEventsRelations = relations(cheerEvents, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [cheerEvents.user],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const cheers = pgTable('cheers', {
|
||||
id: uuid().defaultRandom().primaryKey(),
|
||||
user: integer().notNull().references(() => users.id),
|
||||
@@ -46,6 +83,13 @@ export const cheers = pgTable('cheers', {
|
||||
created: timestamp().defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const cheersRelations = relations(cheers, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [cheers.user],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const anivTimeouts = pgTable('anivTimeouts', {
|
||||
id: uuid().defaultRandom().primaryKey(),
|
||||
user: integer().notNull().references(() => users.id),
|
||||
@@ -55,6 +99,13 @@ export const anivTimeouts = pgTable('anivTimeouts', {
|
||||
created: timestamp().defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const anivTimeoutsRelations = relations(anivTimeouts, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [anivTimeouts.user],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const getLoots = pgTable('getLoots', {
|
||||
id: uuid().defaultRandom().primaryKey(),
|
||||
user: integer().notNull().references(() => users.id),
|
||||
@@ -62,3 +113,10 @@ export const getLoots = pgTable('getLoots', {
|
||||
items: jsonb().$type<inventory>().notNull(),
|
||||
created: timestamp().defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const getLootsRelations = relations(getLoots, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [getLoots.user],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user