feat(database): Add Reaction database class

This commit is contained in:
Jesse Wierzbinski 2024-12-18 20:01:26 +01:00
parent e00182cf54
commit f67fed12e0
No known key found for this signature in database
6 changed files with 2635 additions and 11 deletions

View file

@ -0,0 +1,6 @@
ALTER TABLE "Reaction" ALTER COLUMN "emojiId" DROP NOT NULL;--> statement-breakpoint
ALTER TABLE "Reaction" ADD COLUMN "uri" text;--> statement-breakpoint
ALTER TABLE "Reaction" ADD COLUMN "emoji_text" text;--> statement-breakpoint
ALTER TABLE "Reaction" ADD COLUMN "created_at" timestamp(3) DEFAULT now() NOT NULL;--> statement-breakpoint
ALTER TABLE "Reaction" ADD COLUMN "update_at" timestamp(3) DEFAULT now() NOT NULL;--> statement-breakpoint
ALTER TABLE "Reaction" ADD CONSTRAINT "Reaction_uri_unique" UNIQUE("uri");

File diff suppressed because it is too large Load diff

View file

@ -267,6 +267,13 @@
"when": 1734546300555,
"tag": "0037_condemned_talisman",
"breakpoints": true
},
{
"idx": 38,
"version": "7",
"when": 1734548407684,
"tag": "0038_friendly_supernaut",
"breakpoints": true
}
]
}

View file

@ -51,14 +51,15 @@ export const Emojis = pgTable("Emojis", {
category: text("category"),
});
export const Reaction = pgTable("Reaction", {
export const Reactions = pgTable("Reaction", {
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
emojiId: uuid("emojiId")
.notNull()
.references(() => Emojis.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
uri: text("uri").unique(),
// Emoji ID is nullable, in which case it is a text emoji, and the emojiText field is used
emojiId: uuid("emojiId").references(() => Emojis.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
emojiText: text("emoji_text"),
noteId: uuid("noteId")
.notNull()
.references(() => Notes.id, {
@ -71,19 +72,28 @@ export const Reaction = pgTable("Reaction", {
onDelete: "cascade",
onUpdate: "cascade",
}),
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
.defaultNow()
.notNull(),
updatedAt: timestamp("update_at", {
precision: 3,
mode: "string",
})
.defaultNow()
.notNull(),
});
export const ReactionRelations = relations(Reaction, ({ one }) => ({
export const ReactionRelations = relations(Reactions, ({ one }) => ({
emoji: one(Emojis, {
fields: [Reaction.emojiId],
fields: [Reactions.emojiId],
references: [Emojis.id],
}),
note: one(Notes, {
fields: [Reaction.noteId],
fields: [Reactions.noteId],
references: [Notes.id],
}),
author: one(Users, {
fields: [Reaction.authorId],
fields: [Reactions.authorId],
references: [Users.id],
}),
}));