refactor(database): ♻️ Make user avatar and header into a Media instead of plaintext

This commit is contained in:
Jesse Wierzbinski 2025-01-28 19:07:55 +01:00
parent bc961b70bb
commit ba431e2b11
No known key found for this signature in database
11 changed files with 2480 additions and 89 deletions

View 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";

File diff suppressed because it is too large Load diff

View file

@ -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
}
]
}

View file

@ -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",