mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat(database): ✨ Add reactions table to database schema
This commit is contained in:
parent
4fdb96930f
commit
e00182cf54
24
drizzle/migrations/0037_condemned_talisman.sql
Normal file
24
drizzle/migrations/0037_condemned_talisman.sql
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
CREATE TABLE IF NOT EXISTS "Reaction" (
|
||||
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
|
||||
"emojiId" uuid NOT NULL,
|
||||
"noteId" uuid NOT NULL,
|
||||
"authorId" uuid NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "Reaction" ADD CONSTRAINT "Reaction_emojiId_Emojis_id_fk" FOREIGN KEY ("emojiId") REFERENCES "public"."Emojis"("id") ON DELETE cascade ON UPDATE cascade;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "Reaction" ADD CONSTRAINT "Reaction_noteId_Notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "public"."Notes"("id") ON DELETE cascade ON UPDATE cascade;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "Reaction" ADD CONSTRAINT "Reaction_authorId_Users_id_fk" FOREIGN KEY ("authorId") REFERENCES "public"."Users"("id") ON DELETE cascade ON UPDATE cascade;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
2303
drizzle/migrations/meta/0037_snapshot.json
Normal file
2303
drizzle/migrations/meta/0037_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -260,6 +260,13 @@
|
|||
"when": 1732563077877,
|
||||
"tag": "0036_cuddly_ironclad",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 37,
|
||||
"version": "7",
|
||||
"when": 1734546300555,
|
||||
"tag": "0037_condemned_talisman",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,43 @@ export const Emojis = pgTable("Emojis", {
|
|||
category: text("category"),
|
||||
});
|
||||
|
||||
export const Reaction = pgTable("Reaction", {
|
||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||
emojiId: uuid("emojiId")
|
||||
.notNull()
|
||||
.references(() => Emojis.id, {
|
||||
onDelete: "cascade",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
noteId: uuid("noteId")
|
||||
.notNull()
|
||||
.references(() => Notes.id, {
|
||||
onDelete: "cascade",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
authorId: uuid("authorId")
|
||||
.notNull()
|
||||
.references(() => Users.id, {
|
||||
onDelete: "cascade",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
});
|
||||
|
||||
export const ReactionRelations = relations(Reaction, ({ one }) => ({
|
||||
emoji: one(Emojis, {
|
||||
fields: [Reaction.emojiId],
|
||||
references: [Emojis.id],
|
||||
}),
|
||||
note: one(Notes, {
|
||||
fields: [Reaction.noteId],
|
||||
references: [Notes.id],
|
||||
}),
|
||||
author: one(Users, {
|
||||
fields: [Reaction.authorId],
|
||||
references: [Users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const Filters = pgTable("Filters", {
|
||||
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
||||
userId: uuid("userId")
|
||||
|
|
|
|||
Loading…
Reference in a new issue