export const user = mysqlTable('user', {
id: serial('id').primaryKey(),
discordId: varchar('discord_id', { length: 32 }).notNull(),
//
created: timestamp('created').default(sql`now()`).notNull(),
updated: timestamp('updated').default(sql`now()`).notNull()
}, (user) => ({
discordIdIndex: uniqueIndex('user_discord_id_idx').on(user.discordId),
seedIndex: index('user_seed_idx').on(user.seed),
cherryIndex: index('user_cherry_idx').on(user.cherry),
rubyIndex: index('user_ruby_idx').on(user.ruby),
createdIndex: index('user_created_idx').on(user.created),
updatedIndex: index('user_updated_idx').on(user.updated)
}))
export const userRelations = relations(user, ({ one, many }) => ({
level: one(userLevel),
//
inviteLog: many(userInviteLog, { relationName: 'inviteLogs' }),
}))
export const userInviteLog = mysqlTable('user_invite_log', {
id: serial('id').primaryKey(),
inviterId: varchar('inviter_id', { length: 32 }).references(() => user.discordId, { onDelete: 'cascade' }).notNull(),
inviteeId: varchar('invitee_id', { length: 32 }).references(() => user.discordId, { onDelete: 'cascade' }).notNull(),
joinedAt: timestamp('joined_at').default(sql`now()`).notNull(),
leftAt: timestamp('left_at'),
kickedAt: timestamp('kicked_at'),
bannedAt: timestamp('banned_at')
}, (userInviteLog) => ({
inviterIdIndex: index('user_invite_log_inviter_id_idx').on(userInviteLog.inviterId),
inviteeIdIndex: index('user_invite_log_invitee_id_idx').on(userInviteLog.inviteeId),
//
}))