2025-03-22 02:34:03 +01:00
|
|
|
import type {
|
|
|
|
|
Notification as NotificationSchema,
|
2025-05-01 16:27:34 +02:00
|
|
|
RolePermission,
|
2025-03-22 02:34:03 +01:00
|
|
|
Source,
|
|
|
|
|
Status as StatusSchema,
|
2025-03-22 18:04:47 +01:00
|
|
|
} from "@versia/client/schemas";
|
2025-06-15 04:38:20 +02:00
|
|
|
import type {
|
|
|
|
|
ContentFormatSchema,
|
|
|
|
|
ImageContentFormatSchema,
|
|
|
|
|
InstanceMetadataSchema,
|
|
|
|
|
NonTextContentFormatSchema,
|
|
|
|
|
TextContentFormatSchema,
|
|
|
|
|
} from "@versia/sdk/schemas";
|
2024-06-13 01:48:58 +02:00
|
|
|
import type { Challenge } from "altcha-lib/types";
|
2024-04-13 14:20:12 +02:00
|
|
|
import { relations, sql } from "drizzle-orm";
|
2024-04-11 13:39:07 +02:00
|
|
|
import {
|
2024-04-29 01:47:14 +02:00
|
|
|
type AnyPgColumn,
|
2024-04-13 14:20:12 +02:00
|
|
|
boolean,
|
|
|
|
|
index,
|
|
|
|
|
integer,
|
|
|
|
|
jsonb,
|
2024-04-11 13:39:07 +02:00
|
|
|
pgTable,
|
|
|
|
|
text,
|
2024-04-13 14:20:12 +02:00
|
|
|
timestamp,
|
2024-04-11 13:39:07 +02:00
|
|
|
uniqueIndex,
|
2024-04-13 14:20:12 +02:00
|
|
|
uuid,
|
2024-04-11 13:39:07 +02:00
|
|
|
} from "drizzle-orm/pg-core";
|
2025-11-21 08:31:02 +01:00
|
|
|
import type { z } from "zod";
|
2024-04-11 13:39:07 +02:00
|
|
|
|
2024-12-18 21:52:53 +01:00
|
|
|
const createdAt = () =>
|
2025-08-21 00:45:58 +02:00
|
|
|
// TODO: Change mode to Date
|
2024-12-18 21:52:53 +01:00
|
|
|
timestamp("created_at", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull();
|
|
|
|
|
|
|
|
|
|
const updatedAt = () =>
|
|
|
|
|
timestamp("updated_at", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull();
|
|
|
|
|
|
|
|
|
|
const uri = () => text("uri").unique();
|
|
|
|
|
|
2025-08-21 00:45:58 +02:00
|
|
|
const id = () => uuid("id").primaryKey();
|
2024-12-18 21:52:53 +01:00
|
|
|
|
2024-06-14 10:03:51 +02:00
|
|
|
export const Challenges = pgTable("Challenges", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-06-13 01:48:58 +02:00
|
|
|
challenge: jsonb("challenge").notNull().$type<Challenge>(),
|
|
|
|
|
expiresAt: timestamp("expires_at", {
|
|
|
|
|
precision: 3,
|
|
|
|
|
mode: "string",
|
2024-06-14 10:03:51 +02:00
|
|
|
})
|
|
|
|
|
.default(
|
|
|
|
|
// 5 minutes
|
|
|
|
|
sql`NOW() + INTERVAL '5 minutes'`,
|
|
|
|
|
)
|
|
|
|
|
.notNull(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-06-13 01:48:58 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Emojis = pgTable("Emojis", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-11 13:39:07 +02:00
|
|
|
shortcode: text("shortcode").notNull(),
|
2025-01-28 17:43:43 +01:00
|
|
|
mediaId: uuid("mediaId")
|
|
|
|
|
.references(() => Medias.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
visibleInPicker: boolean("visible_in_picker").notNull(),
|
2024-04-17 08:36:01 +02:00
|
|
|
instanceId: uuid("instanceId").references(() => Instances.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-05-13 04:09:57 +02:00
|
|
|
ownerId: uuid("ownerId").references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
category: text("category"),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const EmojisRelations = relations(Emojis, ({ one, many }) => ({
|
2025-01-28 17:43:43 +01:00
|
|
|
media: one(Medias, {
|
|
|
|
|
fields: [Emojis.mediaId],
|
|
|
|
|
references: [Medias.id],
|
|
|
|
|
}),
|
2025-01-28 17:06:28 +01:00
|
|
|
instance: one(Instances, {
|
|
|
|
|
fields: [Emojis.instanceId],
|
|
|
|
|
references: [Instances.id],
|
|
|
|
|
}),
|
|
|
|
|
users: many(EmojiToUser),
|
|
|
|
|
notes: many(EmojiToNote),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-01-02 01:29:33 +01:00
|
|
|
export const PushSubscriptions = pgTable("PushSubscriptions", {
|
|
|
|
|
id: id(),
|
|
|
|
|
endpoint: text("endpoint").notNull(),
|
|
|
|
|
publicKey: text("public_key").notNull(),
|
|
|
|
|
authSecret: text("auth_secret").notNull(),
|
|
|
|
|
alerts: jsonb("alerts").notNull().$type<
|
|
|
|
|
Partial<{
|
|
|
|
|
mention: boolean;
|
|
|
|
|
favourite: boolean;
|
|
|
|
|
reblog: boolean;
|
|
|
|
|
follow: boolean;
|
|
|
|
|
poll: boolean;
|
|
|
|
|
follow_request: boolean;
|
|
|
|
|
status: boolean;
|
|
|
|
|
update: boolean;
|
|
|
|
|
"admin.sign_up": boolean;
|
|
|
|
|
"admin.report": boolean;
|
|
|
|
|
}>
|
|
|
|
|
>(),
|
|
|
|
|
policy: text("policy")
|
|
|
|
|
.notNull()
|
|
|
|
|
.$type<"all" | "followed" | "follower" | "none">(),
|
|
|
|
|
createdAt: createdAt(),
|
|
|
|
|
updatedAt: updatedAt(),
|
|
|
|
|
tokenId: uuid("tokenId")
|
|
|
|
|
.references(() => Tokens.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.unique(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const PushSubscriptionsRelations = relations(
|
|
|
|
|
PushSubscriptions,
|
|
|
|
|
({ one }) => ({
|
|
|
|
|
token: one(Tokens, {
|
|
|
|
|
fields: [PushSubscriptions.tokenId],
|
|
|
|
|
references: [Tokens.id],
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2024-12-18 20:01:26 +01:00
|
|
|
export const Reactions = pgTable("Reaction", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
|
|
|
|
uri: uri(),
|
2024-12-18 20:01:26 +01:00
|
|
|
// Emoji ID is nullable, in which case it is a text emoji, and the emojiText field is used
|
|
|
|
|
emojiId: uuid("emojiId").references(() => Emojis.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
emojiText: text("emoji_text"),
|
2024-12-18 19:25:45 +01:00
|
|
|
noteId: uuid("noteId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
authorId: uuid("authorId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
|
|
|
|
updatedAt: updatedAt(),
|
2024-12-18 19:25:45 +01:00
|
|
|
});
|
|
|
|
|
|
2024-12-18 20:01:26 +01:00
|
|
|
export const ReactionRelations = relations(Reactions, ({ one }) => ({
|
2024-12-18 19:25:45 +01:00
|
|
|
emoji: one(Emojis, {
|
2024-12-18 20:01:26 +01:00
|
|
|
fields: [Reactions.emojiId],
|
2024-12-18 19:25:45 +01:00
|
|
|
references: [Emojis.id],
|
|
|
|
|
}),
|
|
|
|
|
note: one(Notes, {
|
2024-12-18 20:01:26 +01:00
|
|
|
fields: [Reactions.noteId],
|
2024-12-18 19:25:45 +01:00
|
|
|
references: [Notes.id],
|
2025-05-25 16:11:56 +02:00
|
|
|
relationName: "NoteToReactions",
|
2024-12-18 19:25:45 +01:00
|
|
|
}),
|
|
|
|
|
author: one(Users, {
|
2024-12-18 20:01:26 +01:00
|
|
|
fields: [Reactions.authorId],
|
2024-12-18 19:25:45 +01:00
|
|
|
references: [Users.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-18 01:47:03 +02:00
|
|
|
export const Filters = pgTable("Filters", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-18 01:47:03 +02:00
|
|
|
userId: uuid("userId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
context: text("context")
|
|
|
|
|
.array()
|
2024-09-16 15:29:09 +02:00
|
|
|
.notNull()
|
2024-04-18 01:47:03 +02:00
|
|
|
.$type<
|
|
|
|
|
("home" | "notifications" | "public" | "thread" | "account")[]
|
|
|
|
|
>(),
|
|
|
|
|
title: text("title").notNull(),
|
|
|
|
|
filterAction: text("filter_action").notNull().$type<"warn" | "hide">(),
|
|
|
|
|
expireAt: timestamp("expires_at", { precision: 3, mode: "string" }),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-18 01:47:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const FilterKeywords = pgTable("FilterKeywords", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-18 01:47:03 +02:00
|
|
|
filterId: uuid("filterId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Filters.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
keyword: text("keyword").notNull(),
|
|
|
|
|
wholeWord: boolean("whole_word").notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const FilterRelations = relations(Filters, ({ many }) => ({
|
|
|
|
|
keywords: many(FilterKeywords),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
export const FilterKeywordsRelations = relations(FilterKeywords, ({ one }) => ({
|
|
|
|
|
filter: one(Filters, {
|
|
|
|
|
fields: [FilterKeywords.filterId],
|
|
|
|
|
references: [Filters.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 09:04:03 +02:00
|
|
|
export const Markers = pgTable("Markers", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-17 09:04:03 +02:00
|
|
|
noteId: uuid("noteId").references(() => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
notificationId: uuid("notificationId").references(() => Notifications.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
userId: uuid("userId")
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull(),
|
|
|
|
|
timeline: text("timeline").notNull().$type<"home" | "notifications">(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-17 09:04:03 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Likes = pgTable("Likes", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
|
|
|
|
uri: uri(),
|
2024-04-11 13:39:07 +02:00
|
|
|
likerId: uuid("likerId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
likedId: uuid("likedId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const LikesRelations = relations(Likes, ({ one }) => ({
|
|
|
|
|
liker: one(Users, {
|
|
|
|
|
fields: [Likes.likerId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
}),
|
|
|
|
|
liked: one(Notes, {
|
|
|
|
|
fields: [Likes.likedId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Relationships = pgTable("Relationships", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-11 13:39:07 +02:00
|
|
|
ownerId: uuid("ownerId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
subjectId: uuid("subjectId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
following: boolean("following").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
showingReblogs: boolean("showing_reblogs").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
notifying: boolean("notifying").notNull(),
|
|
|
|
|
blocking: boolean("blocking").notNull(),
|
|
|
|
|
muting: boolean("muting").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
mutingNotifications: boolean("muting_notifications").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
requested: boolean("requested").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
domainBlocking: boolean("domain_blocking").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
endorsed: boolean("endorsed").notNull(),
|
|
|
|
|
languages: text("languages").array(),
|
|
|
|
|
note: text("note").notNull(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
|
|
|
|
updatedAt: updatedAt(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const RelationshipsRelations = relations(Relationships, ({ one }) => ({
|
|
|
|
|
owner: one(Users, {
|
|
|
|
|
fields: [Relationships.ownerId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
relationName: "RelationshipToOwner",
|
|
|
|
|
}),
|
|
|
|
|
subject: one(Users, {
|
|
|
|
|
fields: [Relationships.subjectId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
relationName: "RelationshipToSubject",
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-08-21 01:21:32 +02:00
|
|
|
export const Clients = pgTable("Clients", {
|
2025-08-21 00:45:58 +02:00
|
|
|
id: text("client_id").primaryKey(),
|
|
|
|
|
secret: text("secret").notNull(),
|
|
|
|
|
redirectUris: text("redirect_uris")
|
|
|
|
|
.array()
|
|
|
|
|
.notNull()
|
|
|
|
|
.default(sql`ARRAY[]::text[]`),
|
|
|
|
|
scopes: text("scopes").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
|
|
|
name: text("name").notNull(),
|
|
|
|
|
website: text("website"),
|
|
|
|
|
});
|
2024-04-11 13:39:07 +02:00
|
|
|
|
2025-08-21 00:45:58 +02:00
|
|
|
export const ClientsRelations = relations(Clients, ({ many }) => ({
|
2024-04-17 08:36:01 +02:00
|
|
|
tokens: many(Tokens),
|
|
|
|
|
loginFlows: many(OpenIdLoginFlows),
|
2024-04-14 02:07:05 +02:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Tokens = pgTable("Tokens", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2025-08-21 00:45:58 +02:00
|
|
|
scopes: text("scopes").array().notNull().default(sql`ARRAY[]::text[]`),
|
2024-04-11 13:39:07 +02:00
|
|
|
accessToken: text("access_token").notNull(),
|
2024-04-18 10:42:12 +02:00
|
|
|
expiresAt: timestamp("expires_at", { precision: 3, mode: "string" }),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-18 03:54:30 +02:00
|
|
|
userId: uuid("userId")
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull(),
|
2025-08-21 00:45:58 +02:00
|
|
|
clientId: text("clientId")
|
|
|
|
|
.references(() => Clients.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const TokensRelations = relations(Tokens, ({ one }) => ({
|
|
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [Tokens.userId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
}),
|
2025-08-21 00:45:58 +02:00
|
|
|
client: one(Clients, {
|
|
|
|
|
fields: [Tokens.clientId],
|
|
|
|
|
references: [Clients.id],
|
2025-01-28 17:06:28 +01:00
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-08-21 00:45:58 +02:00
|
|
|
export const AuthorizationCodes = pgTable("AuthorizationCodes", {
|
|
|
|
|
code: text("code").primaryKey(),
|
|
|
|
|
scopes: text("scopes").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
|
|
|
redirectUri: text("redirect_uri"),
|
|
|
|
|
expiresAt: timestamp("expires_at", {
|
|
|
|
|
precision: 3,
|
|
|
|
|
mode: "string",
|
|
|
|
|
}).notNull(),
|
|
|
|
|
createdAt: createdAt(),
|
|
|
|
|
codeChallenge: text("code_challenge"),
|
|
|
|
|
codeChallengeMethod: text("code_challenge_method"),
|
|
|
|
|
userId: uuid("userId")
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull(),
|
|
|
|
|
clientId: text("clientId")
|
|
|
|
|
.references(() => Clients.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const AuthorizationCodesRelations = relations(
|
|
|
|
|
AuthorizationCodes,
|
|
|
|
|
({ one }) => ({
|
|
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [AuthorizationCodes.userId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
}),
|
|
|
|
|
client: one(Clients, {
|
|
|
|
|
fields: [AuthorizationCodes.clientId],
|
|
|
|
|
references: [Clients.id],
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2025-01-23 16:08:42 +01:00
|
|
|
export const Medias = pgTable("Medias", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2025-04-08 16:01:10 +02:00
|
|
|
content: jsonb("content")
|
|
|
|
|
.notNull()
|
|
|
|
|
.$type<z.infer<typeof ContentFormatSchema>>(),
|
|
|
|
|
originalContent:
|
|
|
|
|
jsonb("original_content").$type<z.infer<typeof ContentFormatSchema>>(),
|
|
|
|
|
thumbnail:
|
|
|
|
|
jsonb("thumbnail").$type<z.infer<typeof ImageContentFormatSchema>>(),
|
2024-04-11 13:39:07 +02:00
|
|
|
blurhash: text("blurhash"),
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const MediasRelations = relations(Medias, ({ many }) => ({
|
|
|
|
|
notes: many(Notes),
|
2025-01-28 17:43:43 +01:00
|
|
|
emojis: many(Emojis),
|
2025-01-28 19:07:55 +01:00
|
|
|
avatars: many(Users, {
|
|
|
|
|
relationName: "UserToAvatar",
|
|
|
|
|
}),
|
|
|
|
|
headers: many(Users, {
|
|
|
|
|
relationName: "UserToHeader",
|
|
|
|
|
}),
|
2025-01-28 17:06:28 +01:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Notifications = pgTable("Notifications", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2025-02-12 23:25:22 +01:00
|
|
|
type: text("type")
|
|
|
|
|
.$type<z.infer<typeof NotificationSchema.shape.type>>()
|
|
|
|
|
.notNull(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-11 13:39:07 +02:00
|
|
|
notifiedId: uuid("notifiedId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
accountId: uuid("accountId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
noteId: uuid("noteId").references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-16 08:00:40 +02:00
|
|
|
dismissed: boolean("dismissed").default(false).notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const NotificationsRelations = relations(Notifications, ({ one }) => ({
|
|
|
|
|
account: one(Users, {
|
|
|
|
|
fields: [Notifications.accountId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
relationName: "NotificationToAccount",
|
|
|
|
|
}),
|
|
|
|
|
notified: one(Users, {
|
|
|
|
|
fields: [Notifications.notifiedId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
relationName: "NotificationToNotified",
|
|
|
|
|
}),
|
|
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [Notifications.noteId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-26 23:19:01 +02:00
|
|
|
export const Notes = pgTable("Notes", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
|
|
|
|
uri: uri(),
|
2024-04-26 23:19:01 +02:00
|
|
|
authorId: uuid("authorId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
2024-04-11 13:39:07 +02:00
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
|
|
|
|
updatedAt: updatedAt(),
|
2024-04-26 23:19:01 +02:00
|
|
|
reblogId: uuid("reblogId").references((): AnyPgColumn => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
content: text("content").default("").notNull(),
|
|
|
|
|
contentType: text("content_type").default("text/plain").notNull(),
|
2025-02-12 23:25:22 +01:00
|
|
|
visibility: text("visibility")
|
|
|
|
|
.$type<z.infer<typeof StatusSchema.shape.visibility>>()
|
|
|
|
|
.notNull(),
|
2025-05-04 16:38:37 +02:00
|
|
|
reblogCount: integer("reblog_count").default(0).notNull(),
|
|
|
|
|
likeCount: integer("like_count").default(0).notNull(),
|
|
|
|
|
replyCount: integer("reply_count").default(0).notNull(),
|
2024-04-26 23:19:01 +02:00
|
|
|
replyId: uuid("replyId").references((): AnyPgColumn => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
quotingId: uuid("quoteId").references((): AnyPgColumn => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2025-04-08 18:13:30 +02:00
|
|
|
sensitive: boolean("sensitive").notNull().default(false),
|
2024-04-26 23:19:01 +02:00
|
|
|
spoilerText: text("spoiler_text").default("").notNull(),
|
2025-08-21 01:21:32 +02:00
|
|
|
clientId: text("clientId").references(() => Clients.id, {
|
2024-04-26 23:19:01 +02:00
|
|
|
onDelete: "set null",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
contentSource: text("content_source").default("").notNull(),
|
|
|
|
|
});
|
2024-04-11 13:39:07 +02:00
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const NotesRelations = relations(Notes, ({ many, one }) => ({
|
|
|
|
|
emojis: many(EmojiToNote),
|
|
|
|
|
author: one(Users, {
|
|
|
|
|
fields: [Notes.authorId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
relationName: "NoteToAuthor",
|
|
|
|
|
}),
|
|
|
|
|
attachments: many(MediasToNotes, {
|
|
|
|
|
relationName: "AttachmentToNote",
|
|
|
|
|
}),
|
|
|
|
|
mentions: many(NoteToMentions),
|
|
|
|
|
reblog: one(Notes, {
|
|
|
|
|
fields: [Notes.reblogId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
relationName: "NoteToReblogs",
|
|
|
|
|
}),
|
|
|
|
|
usersThatHavePinned: many(UserToPinnedNotes),
|
|
|
|
|
reply: one(Notes, {
|
|
|
|
|
fields: [Notes.replyId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
relationName: "NoteToReplies",
|
|
|
|
|
}),
|
|
|
|
|
quote: one(Notes, {
|
|
|
|
|
fields: [Notes.quotingId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
relationName: "NoteToQuotes",
|
|
|
|
|
}),
|
2025-08-21 01:21:32 +02:00
|
|
|
client: one(Clients, {
|
|
|
|
|
fields: [Notes.clientId],
|
2025-08-21 00:45:58 +02:00
|
|
|
references: [Clients.id],
|
2025-01-28 17:06:28 +01:00
|
|
|
}),
|
|
|
|
|
quotes: many(Notes, {
|
|
|
|
|
relationName: "NoteToQuotes",
|
|
|
|
|
}),
|
|
|
|
|
replies: many(Notes, {
|
|
|
|
|
relationName: "NoteToReplies",
|
|
|
|
|
}),
|
|
|
|
|
likes: many(Likes),
|
|
|
|
|
reblogs: many(Notes, {
|
|
|
|
|
relationName: "NoteToReblogs",
|
|
|
|
|
}),
|
|
|
|
|
notifications: many(Notifications),
|
2025-05-25 16:11:56 +02:00
|
|
|
reactions: many(Reactions, {
|
|
|
|
|
relationName: "NoteToReactions",
|
|
|
|
|
}),
|
2025-01-28 17:06:28 +01:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Instances = pgTable("Instances", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-11 13:39:07 +02:00
|
|
|
baseUrl: text("base_url").notNull(),
|
|
|
|
|
name: text("name").notNull(),
|
|
|
|
|
version: text("version").notNull(),
|
2025-04-08 16:01:10 +02:00
|
|
|
logo: jsonb("logo").$type<typeof NonTextContentFormatSchema._input>(),
|
2024-04-14 03:21:38 +02:00
|
|
|
disableAutomoderation: boolean("disable_automoderation")
|
2024-04-11 13:39:07 +02:00
|
|
|
.default(false)
|
|
|
|
|
.notNull(),
|
2024-06-30 08:58:39 +02:00
|
|
|
protocol: text("protocol")
|
|
|
|
|
.notNull()
|
2024-08-19 15:16:01 +02:00
|
|
|
.$type<"versia" | "activitypub">()
|
|
|
|
|
.default("versia"),
|
2024-11-25 20:37:00 +01:00
|
|
|
inbox: text("inbox"),
|
2025-04-08 16:01:10 +02:00
|
|
|
publicKey:
|
|
|
|
|
jsonb("public_key").$type<
|
|
|
|
|
(typeof InstanceMetadataSchema._input)["public_key"]
|
|
|
|
|
>(),
|
|
|
|
|
extensions:
|
|
|
|
|
jsonb("extensions").$type<
|
|
|
|
|
(typeof InstanceMetadataSchema._input)["extensions"]
|
|
|
|
|
>(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const InstancesRelations = relations(Instances, ({ many }) => ({
|
|
|
|
|
users: many(Users),
|
|
|
|
|
emojis: many(Emojis),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const OpenIdAccounts = pgTable("OpenIdAccounts", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-17 08:36:01 +02:00
|
|
|
userId: uuid("userId").references(() => Users.id, {
|
2024-12-18 21:52:53 +01:00
|
|
|
onDelete: "cascade",
|
2024-04-11 13:39:07 +02:00
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-14 03:21:38 +02:00
|
|
|
serverId: text("server_id").notNull(),
|
|
|
|
|
issuerId: text("issuer_id").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Users = pgTable(
|
|
|
|
|
"Users",
|
2024-04-11 13:39:07 +02:00
|
|
|
{
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
|
|
|
|
uri: uri(),
|
2024-04-11 13:39:07 +02:00
|
|
|
username: text("username").notNull(),
|
2025-04-08 16:59:18 +02:00
|
|
|
displayName: text("display_name"),
|
2024-04-11 13:39:07 +02:00
|
|
|
password: text("password"),
|
|
|
|
|
email: text("email"),
|
|
|
|
|
note: text("note").default("").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
isAdmin: boolean("is_admin").default(false).notNull(),
|
2024-05-17 10:27:41 +02:00
|
|
|
emailVerificationToken: text("email_verification_token"),
|
|
|
|
|
passwordResetToken: text("password_reset_token"),
|
2024-04-25 06:37:55 +02:00
|
|
|
fields: jsonb("fields").notNull().default("[]").$type<
|
|
|
|
|
{
|
2025-04-08 16:01:10 +02:00
|
|
|
key: z.infer<typeof TextContentFormatSchema>;
|
|
|
|
|
value: z.infer<typeof TextContentFormatSchema>;
|
2024-04-25 06:37:55 +02:00
|
|
|
}[]
|
|
|
|
|
>(),
|
2024-04-17 06:09:21 +02:00
|
|
|
endpoints: jsonb("endpoints").$type<Partial<{
|
2024-08-26 19:06:49 +02:00
|
|
|
dislikes?: string;
|
2024-04-17 06:09:21 +02:00
|
|
|
featured: string;
|
2024-08-26 19:06:49 +02:00
|
|
|
likes?: string;
|
2024-04-17 06:09:21 +02:00
|
|
|
followers: string;
|
|
|
|
|
following: string;
|
|
|
|
|
inbox: string;
|
|
|
|
|
outbox: string;
|
|
|
|
|
}> | null>(),
|
2025-04-08 16:59:18 +02:00
|
|
|
source: jsonb("source").$type<z.infer<typeof Source>>(),
|
2025-01-28 19:07:55 +01:00
|
|
|
avatarId: uuid("avatarId").references(() => Medias.id, {
|
|
|
|
|
onDelete: "set null",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
headerId: uuid("headerId").references(() => Medias.id, {
|
|
|
|
|
onDelete: "set null",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2025-05-04 16:38:37 +02:00
|
|
|
followerCount: integer("follower_count").default(0).notNull(),
|
|
|
|
|
followingCount: integer("following_count").default(0).notNull(),
|
|
|
|
|
statusCount: integer("status_count").default(0).notNull(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
|
|
|
|
updatedAt: updatedAt(),
|
2024-04-14 03:21:38 +02:00
|
|
|
isBot: boolean("is_bot").default(false).notNull(),
|
|
|
|
|
isLocked: boolean("is_locked").default(false).notNull(),
|
|
|
|
|
isDiscoverable: boolean("is_discoverable").default(false).notNull(),
|
2025-03-30 20:32:42 +02:00
|
|
|
isHidingCollections: boolean("is_hiding_collections")
|
|
|
|
|
.default(false)
|
|
|
|
|
.notNull(),
|
|
|
|
|
isIndexable: boolean("is_indexable").default(true).notNull(),
|
2024-04-15 01:41:11 +02:00
|
|
|
sanctions: text("sanctions").array(),
|
2024-04-14 03:21:38 +02:00
|
|
|
publicKey: text("public_key").notNull(),
|
|
|
|
|
privateKey: text("private_key"),
|
2024-04-17 08:36:01 +02:00
|
|
|
instanceId: uuid("instanceId").references(() => Instances.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-14 03:21:38 +02:00
|
|
|
disableAutomoderation: boolean("disable_automoderation")
|
2024-04-11 13:39:07 +02:00
|
|
|
.default(false)
|
|
|
|
|
.notNull(),
|
|
|
|
|
},
|
2024-12-18 21:52:53 +01:00
|
|
|
(table) => [
|
|
|
|
|
uniqueIndex().on(table.uri),
|
|
|
|
|
index().on(table.username),
|
|
|
|
|
uniqueIndex().on(table.email),
|
|
|
|
|
],
|
2024-04-11 13:39:07 +02:00
|
|
|
);
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const UsersRelations = relations(Users, ({ many, one }) => ({
|
|
|
|
|
emojis: many(EmojiToUser),
|
|
|
|
|
pinnedNotes: many(UserToPinnedNotes),
|
|
|
|
|
notes: many(Notes, {
|
|
|
|
|
relationName: "NoteToAuthor",
|
|
|
|
|
}),
|
2025-01-28 19:07:55 +01:00
|
|
|
avatar: one(Medias, {
|
|
|
|
|
fields: [Users.avatarId],
|
|
|
|
|
references: [Medias.id],
|
|
|
|
|
relationName: "UserToAvatar",
|
|
|
|
|
}),
|
|
|
|
|
header: one(Medias, {
|
|
|
|
|
fields: [Users.headerId],
|
|
|
|
|
references: [Medias.id],
|
|
|
|
|
relationName: "UserToHeader",
|
|
|
|
|
}),
|
2025-01-28 17:06:28 +01:00
|
|
|
likes: many(Likes),
|
|
|
|
|
relationships: many(Relationships, {
|
|
|
|
|
relationName: "RelationshipToOwner",
|
|
|
|
|
}),
|
|
|
|
|
relationshipSubjects: many(Relationships, {
|
|
|
|
|
relationName: "RelationshipToSubject",
|
|
|
|
|
}),
|
|
|
|
|
notificationsMade: many(Notifications, {
|
|
|
|
|
relationName: "NotificationToAccount",
|
|
|
|
|
}),
|
|
|
|
|
notificationsReceived: many(Notifications, {
|
|
|
|
|
relationName: "NotificationToNotified",
|
|
|
|
|
}),
|
|
|
|
|
openIdAccounts: many(OpenIdAccounts),
|
|
|
|
|
flags: many(Flags),
|
|
|
|
|
modNotes: many(ModNotes),
|
|
|
|
|
modTags: many(ModTags),
|
|
|
|
|
tokens: many(Tokens),
|
|
|
|
|
instance: one(Instances, {
|
|
|
|
|
fields: [Users.instanceId],
|
|
|
|
|
references: [Instances.id],
|
|
|
|
|
}),
|
|
|
|
|
mentionedIn: many(NoteToMentions),
|
|
|
|
|
roles: many(RoleToUsers),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const OpenIdLoginFlows = pgTable("OpenIdLoginFlows", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-14 03:21:38 +02:00
|
|
|
codeVerifier: text("code_verifier").notNull(),
|
2025-08-21 00:45:58 +02:00
|
|
|
state: text("state"),
|
|
|
|
|
clientState: text("client_state"),
|
|
|
|
|
clientRedirectUri: text("client_redirect_uri"),
|
|
|
|
|
clientScopes: text("client_scopes").array(),
|
2025-08-21 01:21:32 +02:00
|
|
|
clientId: text("clientId").references(() => Clients.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-14 03:21:38 +02:00
|
|
|
issuerId: text("issuer_id").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const OpenIdLoginFlowsRelations = relations(
|
|
|
|
|
OpenIdLoginFlows,
|
2024-04-14 02:07:05 +02:00
|
|
|
({ one }) => ({
|
2025-08-21 01:21:32 +02:00
|
|
|
client: one(Clients, {
|
|
|
|
|
fields: [OpenIdLoginFlows.clientId],
|
2025-08-21 00:45:58 +02:00
|
|
|
references: [Clients.id],
|
2024-04-14 02:07:05 +02:00
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Flags = pgTable("Flags", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-14 03:21:38 +02:00
|
|
|
flagType: text("flag_type").default("other").notNull(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-17 08:36:01 +02:00
|
|
|
noteId: uuid("noteId").references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
userId: uuid("userId").references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const ModNotes = pgTable("ModNotes", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-17 08:36:01 +02:00
|
|
|
nodeId: uuid("noteId").references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
userId: uuid("userId").references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
modId: uuid("modId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
note: text("note").notNull(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const ModTags = pgTable("ModTags", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-04-17 08:36:01 +02:00
|
|
|
noteId: uuid("noteId").references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
userId: uuid("userId").references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
modId: uuid("modId")
|
|
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
tag: text("tag").notNull(),
|
2024-12-18 21:52:53 +01:00
|
|
|
createdAt: createdAt(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2024-06-08 05:31:17 +02:00
|
|
|
export const Roles = pgTable("Roles", {
|
2024-12-18 21:52:53 +01:00
|
|
|
id: id(),
|
2024-06-08 05:31:17 +02:00
|
|
|
name: text("name").notNull(),
|
|
|
|
|
permissions: text("permissions")
|
|
|
|
|
.array()
|
|
|
|
|
.notNull()
|
2025-03-22 18:04:47 +01:00
|
|
|
.$type<RolePermission[]>(),
|
2024-06-08 05:31:17 +02:00
|
|
|
priority: integer("priority").notNull().default(0),
|
|
|
|
|
description: text("description"),
|
|
|
|
|
visible: boolean("visible").notNull().default(false),
|
|
|
|
|
icon: text("icon"),
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-08 06:57:29 +02:00
|
|
|
export const RolesRelations = relations(Roles, ({ many }) => ({
|
|
|
|
|
users: many(RoleToUsers),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-06-08 05:31:17 +02:00
|
|
|
export const RoleToUsers = pgTable("RoleToUsers", {
|
|
|
|
|
roleId: uuid("roleId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Roles.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
userId: uuid("userId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const RoleToUsersRelations = relations(RoleToUsers, ({ one }) => ({
|
|
|
|
|
role: one(Roles, {
|
|
|
|
|
fields: [RoleToUsers.roleId],
|
|
|
|
|
references: [Roles.id],
|
|
|
|
|
}),
|
|
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [RoleToUsers.userId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const EmojiToUser = pgTable(
|
2024-04-14 03:21:38 +02:00
|
|
|
"EmojiToUser",
|
2024-04-11 13:39:07 +02:00
|
|
|
{
|
2024-04-14 03:21:38 +02:00
|
|
|
emojiId: uuid("emojiId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Emojis.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-14 03:21:38 +02:00
|
|
|
userId: uuid("userId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
},
|
2024-12-18 21:52:53 +01:00
|
|
|
(table) => [
|
|
|
|
|
uniqueIndex().on(table.emojiId, table.userId),
|
|
|
|
|
index().on(table.userId),
|
|
|
|
|
],
|
2024-04-11 13:39:07 +02:00
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const EmojiToUserRelations = relations(EmojiToUser, ({ one }) => ({
|
|
|
|
|
emoji: one(Emojis, {
|
|
|
|
|
fields: [EmojiToUser.emojiId],
|
|
|
|
|
references: [Emojis.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [EmojiToUser.userId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const EmojiToNote = pgTable(
|
|
|
|
|
"EmojiToNote",
|
2024-04-11 13:39:07 +02:00
|
|
|
{
|
2024-04-14 03:21:38 +02:00
|
|
|
emojiId: uuid("emojiId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Emojis.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
noteId: uuid("noteId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
},
|
2024-12-18 21:52:53 +01:00
|
|
|
(table) => [
|
|
|
|
|
uniqueIndex().on(table.emojiId, table.noteId),
|
|
|
|
|
index().on(table.noteId),
|
|
|
|
|
],
|
2024-04-11 13:39:07 +02:00
|
|
|
);
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const EmojisToNotesRelations = relations(EmojiToNote, ({ one }) => ({
|
|
|
|
|
emoji: one(Emojis, {
|
|
|
|
|
fields: [EmojiToNote.emojiId],
|
|
|
|
|
references: [Emojis.id],
|
|
|
|
|
}),
|
|
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [EmojiToNote.noteId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const NoteToMentions = pgTable(
|
|
|
|
|
"NoteToMentions",
|
2024-04-11 13:39:07 +02:00
|
|
|
{
|
2024-04-17 08:36:01 +02:00
|
|
|
noteId: uuid("noteId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-14 03:21:38 +02:00
|
|
|
userId: uuid("userId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
},
|
2024-12-18 21:52:53 +01:00
|
|
|
(table) => [
|
|
|
|
|
uniqueIndex().on(table.noteId, table.userId),
|
|
|
|
|
index().on(table.userId),
|
|
|
|
|
],
|
2024-04-11 13:39:07 +02:00
|
|
|
);
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const NotesToMentionsRelations = relations(
|
|
|
|
|
NoteToMentions,
|
|
|
|
|
({ one }) => ({
|
|
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [NoteToMentions.noteId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
}),
|
|
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [NoteToMentions.userId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const UserToPinnedNotes = pgTable(
|
2024-04-14 03:21:38 +02:00
|
|
|
"UserToPinnedNotes",
|
2024-04-11 13:39:07 +02:00
|
|
|
{
|
2024-04-14 03:21:38 +02:00
|
|
|
userId: uuid("userId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
noteId: uuid("noteId")
|
2024-04-11 13:39:07 +02:00
|
|
|
.notNull()
|
2024-04-17 08:36:01 +02:00
|
|
|
.references(() => Notes.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
},
|
2024-12-18 21:52:53 +01:00
|
|
|
(table) => [
|
|
|
|
|
uniqueIndex().on(table.userId, table.noteId),
|
|
|
|
|
index().on(table.noteId),
|
|
|
|
|
],
|
2024-04-11 13:39:07 +02:00
|
|
|
);
|
|
|
|
|
|
2025-01-28 17:06:28 +01:00
|
|
|
export const UserToPinnedNotesRelations = relations(
|
|
|
|
|
UserToPinnedNotes,
|
|
|
|
|
({ one }) => ({
|
|
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [UserToPinnedNotes.noteId],
|
|
|
|
|
references: [Notes.id],
|
|
|
|
|
}),
|
|
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [UserToPinnedNotes.userId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
2025-01-23 20:36:09 +01:00
|
|
|
|
|
|
|
|
export const MediasToNotes = pgTable(
|
|
|
|
|
"MediasToNote",
|
|
|
|
|
{
|
|
|
|
|
mediaId: uuid("mediaId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Medias.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
noteId: uuid("noteId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
(table) => [index().on(table.mediaId), index().on(table.noteId)],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const MediasToNotesRelations = relations(MediasToNotes, ({ one }) => ({
|
|
|
|
|
media: one(Medias, {
|
|
|
|
|
fields: [MediasToNotes.mediaId],
|
|
|
|
|
references: [Medias.id],
|
|
|
|
|
}),
|
|
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [MediasToNotes.noteId],
|
2024-04-17 08:36:01 +02:00
|
|
|
references: [Notes.id],
|
2025-01-23 20:36:09 +01:00
|
|
|
relationName: "AttachmentToNote",
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}));
|