pkgs/db/src/schemas/relations.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
import { defineRelations } from "drizzle-orm";
import { guilds } from "./guilds";
import { users, sessions } from "./users";
import { actors } from "./actors";
import {
tickets,
ticketParticipants,
ticketMessages,
ticketAttachments,
ticketComments,
} from "./tickets";
export default defineRelations(
{
guilds,
users,
sessions,
actors,
tickets,
ticketParticipants,
ticketMessages,
ticketAttachments,
ticketComments,
},
(r) => ({
guilds: {
actors: r.many.actors({ from: r.guilds.id, to: r.actors.guildId }),
tickets: r.many.tickets({ from: r.guilds.id, to: r.tickets.guildId }),
},
users: {
sessions: r.many.sessions({ from: r.users.id, to: r.sessions.userId }),
actors: r.many.actors({ from: r.users.id, to: r.actors.userId }),
},
sessions: {
user: r.one.users({ from: r.sessions.userId, to: r.users.id }),
},
actors: {
guild: r.one.guilds({ from: r.actors.guildId, to: r.guilds.id }),
user: r.one.users({ from: r.actors.userId, to: r.users.id }),
openedTickets: r.many.tickets({
from: r.actors.id,
to: r.tickets.openedBy,
alias: "ticket_opened_by",
}),
subjectTickets: r.many.tickets({
from: r.actors.id,
to: r.tickets.subject,
alias: "ticket_subject",
}),
claimedTickets: r.many.tickets({
from: r.actors.id,
to: r.tickets.claimedBy,
alias: "ticket_claimed_by",
}),
ticketParticipants: r.many.ticketParticipants({
from: r.actors.id,
to: r.ticketParticipants.actorId,
}),
ticketMessages: r.many.ticketMessages({
from: r.actors.id,
to: r.ticketMessages.actorId,
}),
ticketAttachments: r.many.ticketAttachments({
from: r.actors.id,
to: r.ticketAttachments.actorId,
}),
},
tickets: {
guild: r.one.guilds({ from: r.tickets.guildId, to: r.guilds.id }),
opener: r.one.actors({
from: r.tickets.openedBy,
to: r.actors.id,
alias: "ticket_opened_by",
}),
subjectActor: r.one.actors({
from: r.tickets.subject,
to: r.actors.id,
alias: "ticket_subject",
}),
claimedByActor: r.one.actors({
from: r.tickets.claimedBy,
to: r.actors.id,
alias: "ticket_claimed_by",
}),
closedByActor: r.one.actors({
from: r.tickets.closedBy,
to: r.actors.id,
alias: "ticket_closed_by",
}),
participants: r.many.ticketParticipants({
from: r.tickets.id,
to: r.ticketParticipants.ticketId,
}),
messages: r.many.ticketMessages({ from: r.tickets.id, to: r.ticketMessages.ticketId }),
attachments: r.many.ticketAttachments({
from: r.tickets.id,
to: r.ticketAttachments.ticketId,
}),
comments: r.many.ticketComments({ from: r.tickets.id, to: r.ticketComments.ticketId }),
},
ticketComments: {
ticket: r.one.tickets({ from: r.ticketComments.ticketId, to: r.tickets.id }),
actor: r.one.actors({ from: r.ticketComments.actorId, to: r.actors.id }),
},
ticketParticipants: {
tickets: r.one.tickets({ from: r.ticketParticipants.ticketId, to: r.tickets.id }),
actor: r.one.actors({ from: r.ticketParticipants.actorId, to: r.actors.id }),
},
ticketMessages: {
tickets: r.one.tickets({ from: r.ticketMessages.ticketId, to: r.tickets.id }),
actor: r.one.actors({ from: r.ticketMessages.actorId, to: r.actors.id }),
attachments: r.many.ticketAttachments({
from: r.ticketMessages.id,
to: r.ticketAttachments.messageId,
}),
},
ticketAttachments: {
tickets: r.one.tickets({ from: r.ticketAttachments.ticketId, to: r.tickets.id }),
actor: r.one.actors({ from: r.ticketAttachments.actorId, to: r.actors.id }),
message: r.one.ticketMessages({
from: r.ticketAttachments.messageId,
to: r.ticketMessages.id,
}),
},
}),
);
|