mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor(database): ➖ Remove dependency on pg_uuidv7 extension
This commit is contained in:
parent
2bb3731187
commit
37f68bbffd
37 changed files with 2465 additions and 4 deletions
|
|
@ -4,6 +4,7 @@ import type { CustomEmoji } from "@versia/client/schemas";
|
|||
import type { CustomEmojiExtension } from "@versia/federation/types";
|
||||
import { type Instance, Media, db } from "@versia/kit/db";
|
||||
import { Emojis, type Instances, type Medias } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
type InferSelectModel,
|
||||
|
|
@ -212,6 +213,7 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiType> {
|
|||
const media = await Media.fromVersia(emoji.url);
|
||||
|
||||
return Emoji.insert({
|
||||
id: randomUUIDv7(),
|
||||
shortcode,
|
||||
mediaId: media.id,
|
||||
visibleInPicker: true,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { EntityValidator, type ResponseError } from "@versia/federation";
|
|||
import type { InstanceMetadata } from "@versia/federation/types";
|
||||
import { db } from "@versia/kit/db";
|
||||
import { Instances } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import chalk from "chalk";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
|
|
@ -337,6 +338,7 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
const { metadata, protocol } = output;
|
||||
|
||||
return Instance.insert({
|
||||
id: randomUUIDv7(),
|
||||
baseUrl: host,
|
||||
name: metadata.name,
|
||||
version: metadata.software.version,
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@ export class Media extends BaseInterface<typeof Medias> {
|
|||
: undefined;
|
||||
|
||||
const newAttachment = await Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content,
|
||||
thumbnail: thumbnailContent,
|
||||
});
|
||||
|
|
@ -242,6 +243,7 @@ export class Media extends BaseInterface<typeof Medias> {
|
|||
};
|
||||
|
||||
const newAttachment = await Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content,
|
||||
});
|
||||
|
||||
|
|
@ -525,6 +527,7 @@ export class Media extends BaseInterface<typeof Medias> {
|
|||
|
||||
public static fromVersia(contentFormat: ContentFormat): Promise<Media> {
|
||||
return Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content: contentFormat,
|
||||
originalContent: contentFormat,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
Notes,
|
||||
Users,
|
||||
} from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
type InferSelectModel,
|
||||
|
|
@ -369,6 +370,7 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
const htmlContent = await contentToHtml(data.content, parsedMentions);
|
||||
|
||||
const newNote = await Note.insert({
|
||||
id: randomUUIDv7(),
|
||||
authorId: data.author.id,
|
||||
content: htmlContent,
|
||||
contentSource:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { ReactionExtension } from "@versia/federation/types";
|
||||
import { Emoji, Instance, type Note, User, db } from "@versia/kit/db";
|
||||
import { type Notes, Reactions, type Users } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
type InferSelectModel,
|
||||
|
|
@ -231,6 +232,7 @@ export class Reaction extends BaseInterface<typeof Reactions, ReactionType> {
|
|||
: null;
|
||||
|
||||
return Reaction.insert({
|
||||
id: randomUUIDv7(),
|
||||
uri: reactionToConvert.uri,
|
||||
authorId: author.id,
|
||||
noteId: note.id,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { Relationship as RelationshipSchema } from "@versia/client/schemas";
|
||||
import { db } from "@versia/kit/db";
|
||||
import { Relationships } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
type InferSelectModel,
|
||||
|
|
@ -83,6 +84,7 @@ export class Relationship extends BaseInterface<
|
|||
if (!found) {
|
||||
// Create a new relationship if one doesn't exist
|
||||
return await Relationship.insert({
|
||||
id: randomUUIDv7(),
|
||||
ownerId: owner.id,
|
||||
subjectId: subject.id,
|
||||
languages: [],
|
||||
|
|
@ -119,6 +121,7 @@ export class Relationship extends BaseInterface<
|
|||
|
||||
for (const subjectId of missingSubjectsIds) {
|
||||
await Relationship.insert({
|
||||
id: randomUUIDv7(),
|
||||
ownerId: owner.id,
|
||||
subjectId,
|
||||
languages: [],
|
||||
|
|
@ -213,6 +216,7 @@ export class Relationship extends BaseInterface<
|
|||
await db
|
||||
.insert(Relationships)
|
||||
.values({
|
||||
id: randomUUIDv7(),
|
||||
ownerId: oppositeTo.subjectId,
|
||||
subjectId: oppositeTo.ownerId,
|
||||
languages: [],
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import {
|
|||
UserToPinnedNotes,
|
||||
Users,
|
||||
} from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import chalk from "chalk";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
|
|
@ -471,6 +472,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
}
|
||||
|
||||
const newLike = await Like.insert({
|
||||
id: randomUUIDv7(),
|
||||
likerId: this.id,
|
||||
likedId: note.id,
|
||||
uri,
|
||||
|
|
@ -520,6 +522,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
note?: Note,
|
||||
): Promise<void> {
|
||||
const notification = await Notification.insert({
|
||||
id: randomUUIDv7(),
|
||||
accountId: relatedUser.id,
|
||||
type,
|
||||
notifiedId: this.id,
|
||||
|
|
@ -723,6 +726,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
);
|
||||
} else {
|
||||
avatar = await Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content: user.avatar,
|
||||
});
|
||||
}
|
||||
|
|
@ -737,6 +741,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
);
|
||||
} else {
|
||||
header = await Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content: user.header,
|
||||
});
|
||||
}
|
||||
|
|
@ -755,17 +760,20 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
// Else, create a new user
|
||||
const avatar = user.avatar
|
||||
? await Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content: user.avatar,
|
||||
})
|
||||
: null;
|
||||
|
||||
const header = user.header
|
||||
? await Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content: user.header,
|
||||
})
|
||||
: null;
|
||||
|
||||
const newUser = await User.insert({
|
||||
id: randomUUIDv7(),
|
||||
...data,
|
||||
avatarId: avatar?.id,
|
||||
headerId: header?.id,
|
||||
|
|
@ -876,6 +884,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
await db
|
||||
.insert(Users)
|
||||
.values({
|
||||
id: randomUUIDv7(),
|
||||
username: data.username,
|
||||
displayName: data.display_name ?? data.username,
|
||||
password:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue