pollo/app/services/schema.server.ts

96 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2023-04-20 04:20:00 -06:00
import {
2024-01-06 00:37:58 -07:00
pgTable,
2023-04-20 04:20:00 -06:00
text,
unique,
index,
2024-01-06 00:37:58 -07:00
boolean
} from "drizzle-orm/pg-core";
2023-04-20 04:20:00 -06:00
import { relations } from "drizzle-orm";
2024-01-06 00:37:58 -07:00
export const rooms = pgTable("Room", {
id: text("id").notNull().primaryKey(),
2023-04-20 04:20:00 -06:00
created_at: text("created_at"),
2024-01-06 00:37:58 -07:00
userId: text("userId").notNull(),
roomName: text("roomName"),
2024-04-09 11:09:51 -06:00
topicName: text("topicName"),
2024-01-06 00:37:58 -07:00
visible: boolean("visible").default(false).notNull(),
scale: text("scale").default("0.5,1,2,3,5").notNull(),
2023-04-20 04:20:00 -06:00
});
export const roomsRelations = relations(rooms, ({ many }) => ({
votes: many(votes),
logs: many(logs),
}));
2024-01-06 00:37:58 -07:00
export const votes = pgTable(
2023-04-20 04:20:00 -06:00
"Vote",
{
2024-01-06 00:37:58 -07:00
id: text("id").notNull().primaryKey(),
2023-04-20 04:20:00 -06:00
created_at: text("created_at"),
2024-01-06 00:37:58 -07:00
userId: text("userId").notNull(),
roomId: text("roomId")
2023-04-20 04:20:00 -06:00
.notNull()
.references(() => rooms.id, { onDelete: "cascade" }),
2024-01-06 00:37:58 -07:00
value: text("value").notNull(),
2023-04-20 04:20:00 -06:00
},
(table) => {
return {
unq: unique().on(table.userId, table.roomId),
userVoteIdx: index("user_vote_idx").on(table.userId),
};
}
);
export const votesRelations = relations(votes, ({ one }) => ({
room: one(rooms, {
fields: [votes.roomId],
references: [rooms.id],
}),
}));
2024-01-06 00:37:58 -07:00
export const logs = pgTable(
2023-04-20 04:20:00 -06:00
"Log",
{
2024-01-06 00:37:58 -07:00
id: text("id").notNull().primaryKey(),
2023-04-20 04:20:00 -06:00
created_at: text("created_at"),
2024-01-06 00:37:58 -07:00
userId: text("userId").notNull(),
roomId: text("roomId").notNull(),
scale: text("scale"),
2023-04-20 04:20:00 -06:00
votes: text("votes"),
2024-01-06 00:37:58 -07:00
roomName: text("roomName"),
2024-04-09 11:09:51 -06:00
topicName: text("topicName"),
2023-04-20 04:20:00 -06:00
},
(table) => {
return {
userLogIdx: index("user_log_idx").on(table.userId),
};
}
);
export const logsRelations = relations(logs, ({ one }) => ({
room: one(rooms, {
fields: [logs.roomId],
references: [rooms.id],
}),
}));
2024-01-06 00:37:58 -07:00
export const presence = pgTable(
2023-04-20 04:20:00 -06:00
"Presence",
{
2024-01-06 00:37:58 -07:00
id: text("id").notNull().primaryKey(),
userId: text("userId").notNull(),
userFullName: text("userFullName").notNull(),
userImageUrl: text("userImageUrl").notNull(),
isVIP: boolean("isVIP").default(false).notNull(),
isAdmin: boolean("isAdmin").default(false).notNull(),
roomId: text("roomId")
2023-04-20 04:20:00 -06:00
.notNull()
.references(() => rooms.id, { onDelete: "cascade" }),
},
(table) => {
return {
unq: unique().on(table.userId, table.roomId),
};
}
);