mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(database): ✨ Add Reaction database class
This commit is contained in:
parent
e00182cf54
commit
f67fed12e0
6 changed files with 2635 additions and 11 deletions
6
drizzle/migrations/0038_friendly_supernaut.sql
Normal file
6
drizzle/migrations/0038_friendly_supernaut.sql
Normal 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");
|
||||
2335
drizzle/migrations/meta/0038_snapshot.json
Normal file
2335
drizzle/migrations/meta/0038_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -267,6 +267,13 @@
|
|||
"when": 1734546300555,
|
||||
"tag": "0037_condemned_talisman",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 38,
|
||||
"version": "7",
|
||||
"when": 1734548407684,
|
||||
"tag": "0038_friendly_supernaut",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
}),
|
||||
}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue