mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(database): ♻️ Make user avatar and header into a Media instead of plaintext
This commit is contained in:
parent
bc961b70bb
commit
ba431e2b11
11 changed files with 2480 additions and 89 deletions
6
drizzle/migrations/0045_polite_mikhail_rasputin.sql
Normal file
6
drizzle/migrations/0045_polite_mikhail_rasputin.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
ALTER TABLE "Users" ADD COLUMN "avatarId" uuid;--> statement-breakpoint
|
||||
ALTER TABLE "Users" ADD COLUMN "headerId" uuid;--> statement-breakpoint
|
||||
ALTER TABLE "Users" ADD CONSTRAINT "Users_avatarId_Medias_id_fk" FOREIGN KEY ("avatarId") REFERENCES "public"."Medias"("id") ON DELETE set null ON UPDATE cascade;--> statement-breakpoint
|
||||
ALTER TABLE "Users" ADD CONSTRAINT "Users_headerId_Medias_id_fk" FOREIGN KEY ("headerId") REFERENCES "public"."Medias"("id") ON DELETE set null ON UPDATE cascade;--> statement-breakpoint
|
||||
ALTER TABLE "Users" DROP COLUMN "avatar";--> statement-breakpoint
|
||||
ALTER TABLE "Users" DROP COLUMN "header";
|
||||
2349
drizzle/migrations/meta/0045_snapshot.json
Normal file
2349
drizzle/migrations/meta/0045_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -316,6 +316,13 @@
|
|||
"when": 1738082427051,
|
||||
"tag": "0044_quiet_jasper_sitwell",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 45,
|
||||
"version": "7",
|
||||
"when": 1738087527661,
|
||||
"tag": "0045_polite_mikhail_rasputin",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -365,6 +365,12 @@ export const Medias = pgTable("Medias", {
|
|||
export const MediasRelations = relations(Medias, ({ many }) => ({
|
||||
notes: many(Notes),
|
||||
emojis: many(Emojis),
|
||||
avatars: many(Users, {
|
||||
relationName: "UserToAvatar",
|
||||
}),
|
||||
headers: many(Users, {
|
||||
relationName: "UserToHeader",
|
||||
}),
|
||||
}));
|
||||
|
||||
export const Notifications = pgTable("Notifications", {
|
||||
|
|
@ -557,8 +563,14 @@ export const Users = pgTable(
|
|||
};
|
||||
}
|
||||
>(),
|
||||
avatar: text("avatar").notNull(),
|
||||
header: text("header").notNull(),
|
||||
avatarId: uuid("avatarId").references(() => Medias.id, {
|
||||
onDelete: "set null",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
headerId: uuid("headerId").references(() => Medias.id, {
|
||||
onDelete: "set null",
|
||||
onUpdate: "cascade",
|
||||
}),
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
isBot: boolean("is_bot").default(false).notNull(),
|
||||
|
|
@ -588,6 +600,16 @@ export const UsersRelations = relations(Users, ({ many, one }) => ({
|
|||
notes: many(Notes, {
|
||||
relationName: "NoteToAuthor",
|
||||
}),
|
||||
avatar: one(Medias, {
|
||||
fields: [Users.avatarId],
|
||||
references: [Medias.id],
|
||||
relationName: "UserToAvatar",
|
||||
}),
|
||||
header: one(Medias, {
|
||||
fields: [Users.headerId],
|
||||
references: [Medias.id],
|
||||
relationName: "UserToHeader",
|
||||
}),
|
||||
likes: many(Likes),
|
||||
relationships: many(Relationships, {
|
||||
relationName: "RelationshipToOwner",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue