mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
refactor(database): ➖ Remove dependency on pg_uuidv7 extension
This commit is contained in:
parent
2bb3731187
commit
37f68bbffd
|
|
@ -42,6 +42,7 @@ Versia Server now serves static files directly from a configurable path, and `ve
|
|||
### Backend
|
||||
|
||||
- [x] 🚀 Upgraded Bun to `1.2.7`
|
||||
- [x] 🔥 Removed dependency on the `pg_uuidv7` extension. Versia Server can now be used with "vanilla" PostgreSQL.
|
||||
- [x] 🖼️ Simplified media pipeline: this will improve S3 performance
|
||||
- [ ] 📈 It is now possible to disable media proxying for your CDN (offloading considerable bandwidth to your more optimized CDN).
|
||||
- [x] 👷 Outbound federation, inbox processing, data fetching and media processing are now handled by a queue system.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import { randomString } from "@/math";
|
||||
import { Application } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { config } from "~/config.ts";
|
||||
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||
|
||||
|
|
@ -8,6 +9,7 @@ const { users, deleteUsers, passwords } = await getTestUsers(1);
|
|||
|
||||
// Create application
|
||||
const application = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "Test Application",
|
||||
clientId: randomString(32, "hex"),
|
||||
secret: "test",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import { randomString } from "@/math";
|
||||
import { Application } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { config } from "~/config.ts";
|
||||
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ const newPassword = randomString(16, "hex");
|
|||
|
||||
// Create application
|
||||
const application = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "Test Application",
|
||||
clientId: randomString(32, "hex"),
|
||||
secret: "test",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Role } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { generateClient, getTestUsers } from "~/tests/utils";
|
||||
|
||||
const { users, deleteUsers } = await getTestUsers(2);
|
||||
let role: Role;
|
||||
let higherPriorityRole: Role;
|
||||
|
|
@ -10,6 +10,7 @@ let higherPriorityRole: Role;
|
|||
beforeAll(async () => {
|
||||
// Create new role
|
||||
role = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "test",
|
||||
permissions: [RolePermission.ManageRoles],
|
||||
priority: 2,
|
||||
|
|
@ -24,6 +25,7 @@ beforeAll(async () => {
|
|||
|
||||
// Create a role with higher priority than the user's role
|
||||
higherPriorityRole = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "higherPriorityRole",
|
||||
permissions: [RolePermission.ManageRoles],
|
||||
priority: 3, // Higher priority than the user's role
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Role } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { generateClient, getTestUsers } from "~/tests/utils";
|
||||
|
||||
const { users, deleteUsers } = await getTestUsers(2);
|
||||
|
|
@ -9,6 +10,7 @@ let role: Role;
|
|||
beforeAll(async () => {
|
||||
// Create new role
|
||||
role = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "test",
|
||||
permissions: [RolePermission.ManageRoles],
|
||||
priority: 2,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
CredentialApplication as CredentialApplicationSchema,
|
||||
} from "@versia/client/schemas";
|
||||
import { Application } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
|
|
@ -66,6 +67,7 @@ export default apiRoute((app) =>
|
|||
context.req.valid("json");
|
||||
|
||||
const app = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: client_name,
|
||||
redirectUri: redirect_uris.join("\n"),
|
||||
scopes: scopes.join(" "),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { CustomEmoji as CustomEmojiSchema } from "@versia/client/schemas";
|
|||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Emoji, Media } from "@versia/kit/db";
|
||||
import { Emojis } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { and, eq, isNull, or } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -124,6 +125,7 @@ export default apiRoute((app) =>
|
|||
});
|
||||
|
||||
const emoji = await Emoji.insert({
|
||||
id: randomUUIDv7(),
|
||||
shortcode,
|
||||
mediaId: media.id,
|
||||
visibleInPicker: true,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {
|
|||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { db } from "@versia/kit/db";
|
||||
import { Markers } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { type SQL, and, eq } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -189,6 +190,7 @@ export default apiRoute((app) => {
|
|||
await db
|
||||
.insert(Markers)
|
||||
.values({
|
||||
id: randomUUIDv7(),
|
||||
userId: user.id,
|
||||
timeline: "home",
|
||||
noteId: homeId,
|
||||
|
|
@ -218,6 +220,7 @@ export default apiRoute((app) => {
|
|||
await db
|
||||
.insert(Markers)
|
||||
.values({
|
||||
id: randomUUIDv7(),
|
||||
userId: user.id,
|
||||
timeline: "notifications",
|
||||
notificationId: notificationsId,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
} from "@versia/client/schemas";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { PushSubscription } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import { ApiError } from "~/classes/errors/api-error";
|
||||
|
|
@ -64,6 +65,7 @@ export default apiRoute((app) =>
|
|||
await PushSubscription.clearAllOfToken(token);
|
||||
|
||||
const ps = await PushSubscription.insert({
|
||||
id: randomUUIDv7(),
|
||||
alerts: data.alerts,
|
||||
policy,
|
||||
endpoint: subscription.endpoint,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { PushSubscription } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { generateClient, getTestUsers } from "~/tests/utils";
|
||||
|
||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||
|
|
@ -44,6 +45,7 @@ describe("/api/v1/push/subscriptions", () => {
|
|||
await using client = await generateClient(users[1]);
|
||||
|
||||
await PushSubscription.insert({
|
||||
id: randomUUIDv7(),
|
||||
endpoint: "https://example.com",
|
||||
alerts: {
|
||||
update: true,
|
||||
|
|
@ -76,6 +78,7 @@ describe("/api/v1/push/subscriptions", () => {
|
|||
await using client = await generateClient(users[0]);
|
||||
|
||||
await PushSubscription.insert({
|
||||
id: randomUUIDv7(),
|
||||
endpoint: "https://example.com",
|
||||
alerts: {
|
||||
update: true,
|
||||
|
|
@ -175,6 +178,7 @@ describe("/api/v1/push/subscriptions", () => {
|
|||
await using client = await generateClient(users[0]);
|
||||
|
||||
await PushSubscription.insert({
|
||||
id: randomUUIDv7(),
|
||||
endpoint: "https://example.com",
|
||||
alerts: {
|
||||
update: true,
|
||||
|
|
@ -217,6 +221,7 @@ describe("/api/v1/push/subscriptions", () => {
|
|||
await using client = await generateClient(users[0]);
|
||||
|
||||
await PushSubscription.insert({
|
||||
id: randomUUIDv7(),
|
||||
endpoint: "https://example.com",
|
||||
alerts: {
|
||||
update: true,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Role } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { generateClient, getTestUsers } from "~/tests/utils";
|
||||
|
||||
const { users, deleteUsers } = await getTestUsers(2);
|
||||
|
|
@ -10,6 +11,7 @@ let higherPriorityRole: Role;
|
|||
beforeAll(async () => {
|
||||
// Create new role
|
||||
role = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "test",
|
||||
permissions: [RolePermission.ManageRoles],
|
||||
priority: 2,
|
||||
|
|
@ -24,6 +26,7 @@ beforeAll(async () => {
|
|||
|
||||
// Create a role with higher priority than the user's role
|
||||
higherPriorityRole = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "higherPriorityRole",
|
||||
permissions: [RolePermission.ManageRoles],
|
||||
priority: 3, // Higher priority than the user's role
|
||||
|
|
@ -173,6 +176,7 @@ describe("/api/v1/roles/:id", () => {
|
|||
|
||||
test("should delete role", async () => {
|
||||
const newRole = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "test2",
|
||||
permissions: [RolePermission.ManageRoles],
|
||||
priority: 2,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Role } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { config } from "~/config.ts";
|
||||
import { generateClient, getTestUsers } from "~/tests/utils";
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ let role: Role;
|
|||
beforeAll(async () => {
|
||||
// Create new role
|
||||
role = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
name: "test",
|
||||
permissions: [RolePermission.ManageRoles],
|
||||
priority: 10,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { apiRoute, auth, handleZodError } from "@/api";
|
|||
import { Role as RoleSchema } from "@versia/client/schemas";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Role } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
|
|
@ -105,6 +106,7 @@ export default apiRoute((app) => {
|
|||
}
|
||||
|
||||
const newRole = await Role.insert({
|
||||
id: randomUUIDv7(),
|
||||
description,
|
||||
icon,
|
||||
name,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Status as StatusSchema } from "@versia/client/schemas";
|
|||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Note } from "@versia/kit/db";
|
||||
import { Notes } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -66,6 +67,7 @@ export default apiRoute((app) =>
|
|||
}
|
||||
|
||||
const newReblog = await Note.insert({
|
||||
id: randomUUIDv7(),
|
||||
authorId: user.id,
|
||||
reblogId: note.data.id,
|
||||
visibility,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|||
import type { Status } from "@versia/client/schemas";
|
||||
import { Media, db } from "@versia/kit/db";
|
||||
import { Emojis } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { z } from "zod";
|
||||
import { config } from "~/config.ts";
|
||||
|
|
@ -17,6 +18,7 @@ afterAll(async () => {
|
|||
|
||||
beforeAll(async () => {
|
||||
media = await Media.insert({
|
||||
id: randomUUIDv7(),
|
||||
content: {
|
||||
"image/png": {
|
||||
content: "https://example.com/test.png",
|
||||
|
|
@ -24,7 +26,9 @@ beforeAll(async () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
await db.insert(Emojis).values({
|
||||
id: randomUUIDv7(),
|
||||
shortcode: "test",
|
||||
mediaId: media.id,
|
||||
visibleInPicker: true,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { db } from "@versia/kit/db";
|
||||
import { FilterKeywords, Filters } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import type { SQL } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -139,6 +140,7 @@ export default apiRoute((app) => {
|
|||
await db
|
||||
.insert(Filters)
|
||||
.values({
|
||||
id: randomUUIDv7(),
|
||||
title,
|
||||
context: ctx,
|
||||
filterAction: filter_action,
|
||||
|
|
@ -160,6 +162,7 @@ export default apiRoute((app) => {
|
|||
.insert(FilterKeywords)
|
||||
.values(
|
||||
keywords_attributes?.map((keyword) => ({
|
||||
id: randomUUIDv7(),
|
||||
filterId: newFilter.id,
|
||||
keyword: keyword.keyword,
|
||||
wholeWord: keyword.whole_word ?? false,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { randomString } from "@/math.ts";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import chalk from "chalk";
|
||||
// @ts-expect-error - Root import is required or the Clec type definitions won't work
|
||||
// biome-ignore lint/correctness/noUnusedImports: Root import is required or the Clec type definitions won't work
|
||||
|
|
@ -22,6 +23,7 @@ export const generateTokenCommand = defineCommand(
|
|||
}
|
||||
|
||||
const token = await Token.insert({
|
||||
id: randomUUIDv7(),
|
||||
accessToken: randomString(64, "base64url"),
|
||||
code: null,
|
||||
scope: "read write follow",
|
||||
|
|
|
|||
22
drizzle/migrations/0048_chilly_vector.sql
Normal file
22
drizzle/migrations/0048_chilly_vector.sql
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
ALTER TABLE "Applications" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Challenges" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Emojis" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "FilterKeywords" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Filters" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Flags" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Instances" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Likes" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Markers" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Medias" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "ModNotes" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "ModTags" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Notes" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Notifications" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "OpenIdAccounts" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "OpenIdLoginFlows" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "PushSubscriptions" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Reaction" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Relationships" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Roles" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Tokens" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "Users" ALTER COLUMN "id" DROP DEFAULT;
|
||||
2341
drizzle/migrations/meta/0048_snapshot.json
Normal file
2341
drizzle/migrations/meta/0048_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -337,6 +337,13 @@
|
|||
"when": 1743359397906,
|
||||
"tag": "0047_black_vermin",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 48,
|
||||
"version": "7",
|
||||
"when": 1743365238468,
|
||||
"tag": "0048_chilly_vector",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ const updatedAt = () =>
|
|||
const uri = () => text("uri").unique();
|
||||
|
||||
// biome-ignore lint/nursery/useExplicitType: Type is too complex
|
||||
const id = () =>
|
||||
uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull();
|
||||
const id = () => uuid("id").primaryKey().notNull();
|
||||
|
||||
export const Challenges = pgTable("Challenges", {
|
||||
id: id(),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { afterAll, describe, expect, test } from "bun:test";
|
|||
import { randomString } from "@/math";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Application } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { SignJWT } from "jose";
|
||||
import { config } from "~/config.ts";
|
||||
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||
|
|
@ -19,6 +20,7 @@ const privateKey = await crypto.subtle.importKey(
|
|||
);
|
||||
|
||||
const application = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
clientId: "test-client-id",
|
||||
redirectUri: "https://example.com/callback",
|
||||
scopes: "openid profile email",
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { auth, handleZodError, jsonOrForm } from "@/api";
|
|||
import { randomString } from "@/math";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Application, Token, User } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { validator } from "hono-openapi/zod";
|
||||
import { type JWTPayload, SignJWT, jwtVerify } from "jose";
|
||||
|
|
@ -241,6 +242,7 @@ export default (plugin: PluginType): void =>
|
|||
.sign(keys.private);
|
||||
|
||||
await Token.insert({
|
||||
id: randomUUIDv7(),
|
||||
accessToken: randomString(64, "base64url"),
|
||||
code,
|
||||
scope: scope ?? application.data.scopes,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import { Application } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { fakeRequest } from "~/tests/utils";
|
||||
|
||||
const application = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
clientId: "test-client-id",
|
||||
redirectUri: "https://example.com/callback",
|
||||
scopes: "openid profile email",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { RolePermission } from "@versia/client/schemas";
|
|||
import { Media, Token, User, db } from "@versia/kit/db";
|
||||
import { type SQL, and, eq, isNull } from "@versia/kit/drizzle";
|
||||
import { OpenIdAccounts, Users } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { validator } from "hono-openapi/zod";
|
||||
import { setCookie } from "hono/cookie";
|
||||
|
|
@ -175,6 +176,7 @@ export default (plugin: PluginType): void => {
|
|||
|
||||
// Link the account
|
||||
await db.insert(OpenIdAccounts).values({
|
||||
id: randomUUIDv7(),
|
||||
serverId: sub,
|
||||
issuerId: issuer.id,
|
||||
userId: user_id,
|
||||
|
|
@ -242,6 +244,7 @@ export default (plugin: PluginType): void => {
|
|||
|
||||
// Link account
|
||||
await db.insert(OpenIdAccounts).values({
|
||||
id: randomUUIDv7(),
|
||||
serverId: sub,
|
||||
issuerId: issuer.id,
|
||||
userId: user.id,
|
||||
|
|
@ -294,6 +297,7 @@ export default (plugin: PluginType): void => {
|
|||
const code = randomString(32, "hex");
|
||||
|
||||
await Token.insert({
|
||||
id: randomUUIDv7(),
|
||||
accessToken: randomString(64, "base64url"),
|
||||
code,
|
||||
scope: flow.application.scopes,
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import { Application, Token } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||
|
||||
const { deleteUsers, users } = await getTestUsers(1);
|
||||
|
||||
const application = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
clientId: "test-client-id",
|
||||
redirectUri: "https://example.com/callback",
|
||||
scopes: "openid profile email",
|
||||
secret: "test-secret",
|
||||
name: "Test Application",
|
||||
});
|
||||
|
||||
const token = await Token.insert({
|
||||
id: randomUUIDv7(),
|
||||
code: "test-code",
|
||||
redirectUri: application.data.redirectUri,
|
||||
clientId: application.data.clientId,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { handleZodError } from "@/api.ts";
|
||||
import { Application, db } from "@versia/kit/db";
|
||||
import { OpenIdLoginFlows } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { validator } from "hono-openapi/zod";
|
||||
import {
|
||||
|
|
@ -103,6 +104,7 @@ export default (plugin: PluginType): void => {
|
|||
await db
|
||||
.insert(OpenIdLoginFlows)
|
||||
.values({
|
||||
id: randomUUIDv7(),
|
||||
codeVerifier,
|
||||
applicationId: application.id,
|
||||
issuerId,
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import { Application, Token } from "@versia/kit/db";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||
|
||||
const { deleteUsers, users } = await getTestUsers(1);
|
||||
|
||||
const application = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
clientId: "test-client-id",
|
||||
redirectUri: "https://example.com/callback",
|
||||
scopes: "openid profile email",
|
||||
secret: "test-secret",
|
||||
name: "Test Application",
|
||||
});
|
||||
|
||||
const token = await Token.insert({
|
||||
id: randomUUIDv7(),
|
||||
code: "test-code",
|
||||
redirectUri: application.data.redirectUri,
|
||||
clientId: application.data.clientId,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { auth, handleZodError } from "@/api";
|
|||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Application, db } from "@versia/kit/db";
|
||||
import { OpenIdLoginFlows } from "@versia/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import {
|
||||
|
|
@ -117,6 +118,7 @@ export default (plugin: PluginType): void => {
|
|||
);
|
||||
|
||||
const application = await Application.insert({
|
||||
id: randomUUIDv7(),
|
||||
clientId:
|
||||
user.id +
|
||||
Buffer.from(
|
||||
|
|
@ -133,6 +135,7 @@ export default (plugin: PluginType): void => {
|
|||
await db
|
||||
.insert(OpenIdLoginFlows)
|
||||
.values({
|
||||
id: randomUUIDv7(),
|
||||
codeVerifier,
|
||||
issuerId,
|
||||
applicationId: application.id,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Client as VersiaClient } from "@versia/client";
|
|||
import { Note, Token, User, db } from "@versia/kit/db";
|
||||
import { Notes, Users } from "@versia/kit/tables";
|
||||
import { solveChallenge } from "altcha-lib";
|
||||
import { env } from "bun";
|
||||
import { env, randomUUIDv7 } from "bun";
|
||||
import { type InferSelectModel, asc, inArray, like } from "drizzle-orm";
|
||||
import { appFactory } from "~/app";
|
||||
import { searchManager } from "~/classes/search/search-manager";
|
||||
|
|
@ -46,6 +46,7 @@ export const generateClient = async (
|
|||
> => {
|
||||
const token = user
|
||||
? await Token.insert({
|
||||
id: randomUUIDv7(),
|
||||
accessToken: randomString(32, "hex"),
|
||||
tokenType: "bearer",
|
||||
userId: user.id,
|
||||
|
|
@ -118,6 +119,7 @@ export const getTestUsers = async (
|
|||
|
||||
const tokens = await Token.insertMany(
|
||||
users.map((u) => ({
|
||||
id: randomUUIDv7(),
|
||||
accessToken: randomString(32, "hex"),
|
||||
tokenType: "bearer",
|
||||
userId: u.id,
|
||||
|
|
@ -155,6 +157,7 @@ export const getTestStatuses = async (
|
|||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const newStatus = await Note.insert({
|
||||
id: randomUUIDv7(),
|
||||
content: `${i} ${randomString(32, "hex")}`,
|
||||
authorId: user.id,
|
||||
sensitive: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue