2023-08-12 18:17:36 -06:00
|
|
|
import {
|
2023-10-02 19:29:35 -06:00
|
|
|
sqliteTable,
|
|
|
|
integer,
|
|
|
|
text,
|
2023-08-20 16:52:27 -06:00
|
|
|
unique,
|
2023-10-02 19:29:35 -06:00
|
|
|
index,
|
|
|
|
} from "drizzle-orm/sqlite-core";
|
2023-08-12 18:17:36 -06:00
|
|
|
import { relations } from "drizzle-orm";
|
|
|
|
|
2023-10-02 19:29:35 -06:00
|
|
|
export const rooms = sqliteTable("Room", {
|
|
|
|
id: text("id", { length: 255 }).notNull().primaryKey(),
|
|
|
|
created_at: text("created_at"),
|
|
|
|
userId: text("userId", { length: 255 }).notNull(),
|
|
|
|
roomName: text("roomName", { length: 255 }),
|
|
|
|
storyName: text("storyName", { length: 255 }),
|
|
|
|
visible: integer("visible").default(0).notNull(),
|
|
|
|
scale: text("scale", { length: 255 }).default("0.5,1,2,3,5").notNull(),
|
2023-08-12 18:17:36 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
export const roomsRelations = relations(rooms, ({ many }) => ({
|
|
|
|
votes: many(votes),
|
|
|
|
logs: many(logs),
|
|
|
|
}));
|
|
|
|
|
2023-10-02 19:29:35 -06:00
|
|
|
export const votes = sqliteTable(
|
2023-08-18 23:49:35 -06:00
|
|
|
"Vote",
|
|
|
|
{
|
2023-10-02 19:29:35 -06:00
|
|
|
id: text("id", { length: 255 }).notNull().primaryKey(),
|
|
|
|
created_at: text("created_at"),
|
|
|
|
userId: text("userId", { length: 255 }).notNull(),
|
|
|
|
roomId: text("roomId", { length: 255 })
|
2023-08-18 23:49:35 -06:00
|
|
|
.notNull()
|
|
|
|
.references(() => rooms.id, { onDelete: "cascade" }),
|
2023-10-02 19:29:35 -06:00
|
|
|
value: text("value", { length: 255 }).notNull(),
|
2023-08-18 23:49:35 -06:00
|
|
|
},
|
|
|
|
(table) => {
|
|
|
|
return {
|
2023-08-20 16:52:27 -06:00
|
|
|
unq: unique().on(table.userId, table.roomId),
|
2023-10-20 21:10:58 -03:00
|
|
|
userVoteIdx: index("user_vote_idx").on(table.userId),
|
2023-08-18 23:49:35 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2023-08-12 18:17:36 -06:00
|
|
|
|
|
|
|
export const votesRelations = relations(votes, ({ one }) => ({
|
|
|
|
room: one(rooms, {
|
|
|
|
fields: [votes.roomId],
|
|
|
|
references: [rooms.id],
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
2023-10-02 19:29:35 -06:00
|
|
|
export const logs = sqliteTable(
|
2023-08-18 23:49:35 -06:00
|
|
|
"Log",
|
|
|
|
{
|
2023-10-02 19:29:35 -06:00
|
|
|
id: text("id", { length: 255 }).notNull().primaryKey(),
|
|
|
|
created_at: text("created_at"),
|
|
|
|
userId: text("userId", { length: 255 }).notNull(),
|
|
|
|
roomId: text("roomId", { length: 255 }).notNull(),
|
|
|
|
scale: text("scale", { length: 255 }),
|
|
|
|
votes: text("votes"),
|
|
|
|
roomName: text("roomName", { length: 255 }),
|
|
|
|
storyName: text("storyName", { length: 255 }),
|
2023-08-18 23:49:35 -06:00
|
|
|
},
|
|
|
|
(table) => {
|
|
|
|
return {
|
2023-10-20 21:10:58 -03:00
|
|
|
userLogIdx: index("user_log_idx").on(table.userId),
|
2023-08-18 23:49:35 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2023-08-12 18:17:36 -06:00
|
|
|
|
|
|
|
export const logsRelations = relations(logs, ({ one }) => ({
|
|
|
|
room: one(rooms, {
|
|
|
|
fields: [logs.roomId],
|
|
|
|
references: [rooms.id],
|
|
|
|
}),
|
|
|
|
}));
|
2023-11-22 12:27:30 -07:00
|
|
|
|
|
|
|
export const presence = sqliteTable(
|
|
|
|
"Presence",
|
|
|
|
{
|
|
|
|
id: text("id", { length: 255 }).notNull().primaryKey(),
|
|
|
|
userId: text("userId", { length: 255 }).notNull(),
|
|
|
|
userFullName: text("userFullName", { length: 255 }).notNull(),
|
|
|
|
userImageUrl: text("userImageUrl", { length: 255 }).notNull(),
|
|
|
|
isVIP: integer("isVIP").default(0).notNull(),
|
|
|
|
isAdmin: integer("isAdmin").default(0).notNull(),
|
|
|
|
roomId: text("roomId", { length: 255 })
|
|
|
|
.notNull()
|
|
|
|
.references(() => rooms.id, { onDelete: "cascade" }),
|
|
|
|
},
|
|
|
|
(table) => {
|
|
|
|
return {
|
|
|
|
unq: unique().on(table.userId, table.roomId),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|