2024-06-29 08:36:15 +02:00
|
|
|
import type { Source as ApiSource } from "@lysand-org/client/types";
|
2024-06-20 01:21:02 +02:00
|
|
|
import type { ContentFormat } from "@lysand-org/federation/types";
|
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,
|
|
|
|
|
foreignKey,
|
|
|
|
|
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";
|
|
|
|
|
|
2024-06-14 10:03:51 +02:00
|
|
|
export const Challenges = pgTable("Challenges", {
|
2024-06-13 01:48:58 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
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-06-13 01:48:58 +02:00
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Emojis = pgTable("Emojis", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
shortcode: text("shortcode").notNull(),
|
|
|
|
|
url: text("url").notNull(),
|
|
|
|
|
visibleInPicker: boolean("visible_in_picker").notNull(),
|
|
|
|
|
alt: text("alt"),
|
|
|
|
|
contentType: text("content_type").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
|
|
|
});
|
|
|
|
|
|
2024-04-18 01:47:03 +02:00
|
|
|
export const Filters = pgTable("Filters", {
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
userId: uuid("userId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
context: text("context")
|
|
|
|
|
.array()
|
|
|
|
|
.$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" }),
|
|
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const FilterKeywords = pgTable("FilterKeywords", {
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
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", {
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
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">(),
|
|
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Likes = pgTable("Likes", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
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",
|
|
|
|
|
}),
|
|
|
|
|
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const LysandObjects = pgTable(
|
2024-04-11 13:39:07 +02:00
|
|
|
"LysandObject",
|
|
|
|
|
{
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
remoteId: text("remote_id").notNull(),
|
|
|
|
|
type: text("type").notNull(),
|
|
|
|
|
uri: text("uri").notNull(),
|
|
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
authorId: uuid("authorId"),
|
|
|
|
|
extraData: jsonb("extra_data").notNull(),
|
|
|
|
|
extensions: jsonb("extensions").notNull(),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
2024-04-14 03:21:38 +02:00
|
|
|
remoteIdKey: uniqueIndex().on(table.remoteId),
|
|
|
|
|
uriKey: uniqueIndex().on(table.uri),
|
2024-04-11 13:39:07 +02:00
|
|
|
lysandObjectAuthorIdFkey: foreignKey({
|
|
|
|
|
columns: [table.authorId],
|
|
|
|
|
foreignColumns: [table.id],
|
|
|
|
|
})
|
|
|
|
|
.onUpdate("cascade")
|
|
|
|
|
.onDelete("cascade"),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Relationships = pgTable("Relationships", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
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(),
|
2024-04-14 03:21:38 +02:00
|
|
|
followedBy: boolean("followed_by").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
blocking: boolean("blocking").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
blockedBy: boolean("blocked_by").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
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-06-12 01:42:36 +02:00
|
|
|
requestedBy: boolean("requested_by").notNull().default(false),
|
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-04-14 03:21:38 +02:00
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
2024-04-11 13:39:07 +02:00
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
updatedAt: timestamp("updated_at", {
|
2024-04-11 13:39:07 +02:00
|
|
|
precision: 3,
|
|
|
|
|
mode: "string",
|
2024-04-14 03:21:38 +02:00
|
|
|
})
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Applications = pgTable(
|
|
|
|
|
"Applications",
|
2024-04-11 13:39:07 +02:00
|
|
|
{
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
name: text("name").notNull(),
|
|
|
|
|
website: text("website"),
|
|
|
|
|
vapidKey: text("vapid_key"),
|
|
|
|
|
clientId: text("client_id").notNull(),
|
|
|
|
|
secret: text("secret").notNull(),
|
|
|
|
|
scopes: text("scopes").notNull(),
|
2024-04-18 10:42:12 +02:00
|
|
|
redirectUri: text("redirect_uri").notNull(),
|
2024-04-11 13:39:07 +02:00
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
2024-04-14 03:21:38 +02:00
|
|
|
clientIdKey: uniqueIndex().on(table.clientId),
|
2024-04-11 13:39:07 +02:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const ApplicationsRelations = relations(Applications, ({ many }) => ({
|
|
|
|
|
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-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
tokenType: text("token_type").notNull(),
|
|
|
|
|
scope: text("scope").notNull(),
|
|
|
|
|
accessToken: text("access_token").notNull(),
|
2024-04-18 10:42:12 +02:00
|
|
|
code: text("code"),
|
|
|
|
|
expiresAt: timestamp("expires_at", { precision: 3, mode: "string" }),
|
2024-04-11 13:39:07 +02:00
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
2024-04-18 10:42:12 +02:00
|
|
|
clientId: text("client_id").notNull().default(""),
|
|
|
|
|
redirectUri: text("redirect_uri").notNull().default(""),
|
|
|
|
|
idToken: text("id_token"),
|
2024-04-18 03:54:30 +02:00
|
|
|
userId: uuid("userId")
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
})
|
|
|
|
|
.notNull(),
|
2024-04-17 08:36:01 +02:00
|
|
|
applicationId: uuid("applicationId").references(() => Applications.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Attachments = pgTable("Attachments", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
url: text("url").notNull(),
|
|
|
|
|
remoteUrl: text("remote_url"),
|
|
|
|
|
thumbnailUrl: text("thumbnail_url"),
|
|
|
|
|
mimeType: text("mime_type").notNull(),
|
|
|
|
|
description: text("description"),
|
|
|
|
|
blurhash: text("blurhash"),
|
|
|
|
|
sha256: text("sha256"),
|
|
|
|
|
fps: integer("fps"),
|
|
|
|
|
duration: integer("duration"),
|
|
|
|
|
width: integer("width"),
|
|
|
|
|
height: integer("height"),
|
|
|
|
|
size: integer("size"),
|
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
|
|
|
export const Notifications = pgTable("Notifications", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
type: text("type").notNull(),
|
|
|
|
|
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
2024-04-26 23:19:01 +02:00
|
|
|
export const Notes = pgTable("Notes", {
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
uri: text("uri").unique(),
|
|
|
|
|
authorId: uuid("authorId")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => Users.id, {
|
|
|
|
|
onDelete: "cascade",
|
2024-04-11 13:39:07 +02:00
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
2024-04-26 23:19:01 +02:00
|
|
|
createdAt: timestamp("createdAt", { precision: 3, mode: "string" })
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
updatedAt: timestamp("updatedAt", {
|
|
|
|
|
precision: 3,
|
|
|
|
|
mode: "string",
|
|
|
|
|
})
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
reblogId: uuid("reblogId").references((): AnyPgColumn => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
content: text("content").default("").notNull(),
|
|
|
|
|
contentType: text("content_type").default("text/plain").notNull(),
|
|
|
|
|
visibility: text("visibility").notNull(),
|
|
|
|
|
replyId: uuid("replyId").references((): AnyPgColumn => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
quotingId: uuid("quoteId").references((): AnyPgColumn => Notes.id, {
|
|
|
|
|
onDelete: "cascade",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
sensitive: boolean("sensitive").notNull(),
|
|
|
|
|
spoilerText: text("spoiler_text").default("").notNull(),
|
|
|
|
|
applicationId: uuid("applicationId").references(() => Applications.id, {
|
|
|
|
|
onDelete: "set null",
|
|
|
|
|
onUpdate: "cascade",
|
|
|
|
|
}),
|
|
|
|
|
contentSource: text("content_source").default("").notNull(),
|
|
|
|
|
});
|
2024-04-11 13:39:07 +02:00
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Instances = pgTable("Instances", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
baseUrl: text("base_url").notNull(),
|
|
|
|
|
name: text("name").notNull(),
|
|
|
|
|
version: text("version").notNull(),
|
|
|
|
|
logo: jsonb("logo").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
disableAutomoderation: boolean("disable_automoderation")
|
2024-04-11 13:39:07 +02:00
|
|
|
.default(false)
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const OpenIdAccounts = pgTable("OpenIdAccounts", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
2024-04-17 08:36:01 +02:00
|
|
|
userId: uuid("userId").references(() => Users.id, {
|
2024-04-11 13:39:07 +02:00
|
|
|
onDelete: "set null",
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
uri: text("uri"),
|
|
|
|
|
username: text("username").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
displayName: text("display_name").notNull(),
|
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<
|
|
|
|
|
{
|
2024-06-20 01:21:02 +02:00
|
|
|
key: ContentFormat;
|
|
|
|
|
value: ContentFormat;
|
2024-04-25 06:37:55 +02:00
|
|
|
}[]
|
|
|
|
|
>(),
|
2024-04-17 06:09:21 +02:00
|
|
|
endpoints: jsonb("endpoints").$type<Partial<{
|
|
|
|
|
dislikes: string;
|
|
|
|
|
featured: string;
|
|
|
|
|
likes: string;
|
|
|
|
|
followers: string;
|
|
|
|
|
following: string;
|
|
|
|
|
inbox: string;
|
|
|
|
|
outbox: string;
|
|
|
|
|
}> | null>(),
|
2024-06-29 08:36:15 +02:00
|
|
|
source: jsonb("source").notNull().$type<ApiSource>(),
|
2024-04-11 13:39:07 +02:00
|
|
|
avatar: text("avatar").notNull(),
|
|
|
|
|
header: text("header").notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
2024-04-11 13:39:07 +02:00
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
updatedAt: timestamp("updated_at", {
|
2024-04-11 13:39:07 +02:00
|
|
|
precision: 3,
|
|
|
|
|
mode: "string",
|
|
|
|
|
})
|
|
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
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(),
|
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(),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
2024-04-14 03:21:38 +02:00
|
|
|
uriKey: uniqueIndex().on(table.uri),
|
|
|
|
|
usernameKey: uniqueIndex().on(table.username),
|
|
|
|
|
emailKey: uniqueIndex().on(table.email),
|
2024-04-11 13:39:07 +02:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const OpenIdLoginFlows = pgTable("OpenIdLoginFlows", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
codeVerifier: text("code_verifier").notNull(),
|
2024-04-17 08:36:01 +02:00
|
|
|
applicationId: uuid("applicationId").references(() => Applications.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 }) => ({
|
2024-04-17 08:36:01 +02:00
|
|
|
application: one(Applications, {
|
|
|
|
|
fields: [OpenIdLoginFlows.applicationId],
|
|
|
|
|
references: [Applications.id],
|
2024-04-14 02:07:05 +02:00
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const Flags = pgTable("Flags", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
2024-04-14 03:21:38 +02:00
|
|
|
flagType: text("flag_type").default("other").notNull(),
|
|
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
2024-04-11 13:39:07 +02:00
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
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-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
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-04-14 03:21:38 +02:00
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
2024-04-11 13:39:07 +02:00
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const ModTags = pgTable("ModTags", {
|
2024-04-11 13:39:07 +02:00
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
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-04-14 03:21:38 +02:00
|
|
|
createdAt: timestamp("created_at", { precision: 3, mode: "string" })
|
2024-04-11 13:39:07 +02:00
|
|
|
.defaultNow()
|
|
|
|
|
.notNull(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-08 05:31:17 +02:00
|
|
|
/**
|
|
|
|
|
* Permissions not prefixed with `owner:` let the role manage all instances of the resource.
|
|
|
|
|
* For example, a user with the `notes` permission can manage all notes of every user
|
|
|
|
|
* - Manage: Delete, Update, Create
|
|
|
|
|
* - Owner: Only manage their own resources
|
|
|
|
|
*/
|
|
|
|
|
export enum RolePermissions {
|
2024-06-13 04:26:43 +02:00
|
|
|
ManageNotes = "notes",
|
|
|
|
|
ManageOwnNotes = "owner:note",
|
|
|
|
|
ViewNotes = "read:note",
|
|
|
|
|
ViewNoteLikes = "read:note_likes",
|
|
|
|
|
ViewNoteBoosts = "read:note_boosts",
|
|
|
|
|
ManageAccounts = "accounts",
|
|
|
|
|
ManageOwnAccount = "owner:account",
|
|
|
|
|
ViewAccountFollows = "read:account_follows",
|
|
|
|
|
ManageLikes = "likes",
|
|
|
|
|
ManageOwnLikes = "owner:like",
|
|
|
|
|
ManageBoosts = "boosts",
|
|
|
|
|
ManageOwnBoosts = "owner:boost",
|
|
|
|
|
ViewAccounts = "read:account",
|
|
|
|
|
ManageEmojis = "emojis",
|
|
|
|
|
ViewEmojis = "read:emoji",
|
|
|
|
|
ManageOwnEmojis = "owner:emoji",
|
|
|
|
|
ManageMedia = "media",
|
|
|
|
|
ManageOwnMedia = "owner:media",
|
|
|
|
|
ManageBlocks = "blocks",
|
|
|
|
|
ManageOwnBlocks = "owner:block",
|
|
|
|
|
ManageFilters = "filters",
|
|
|
|
|
ManageOwnFilters = "owner:filter",
|
|
|
|
|
ManageMutes = "mutes",
|
|
|
|
|
ManageOwnMutes = "owner:mute",
|
|
|
|
|
ManageReports = "reports",
|
|
|
|
|
ManageOwnReports = "owner:report",
|
|
|
|
|
ManageSettings = "settings",
|
|
|
|
|
ManageOwnSettings = "owner:settings",
|
|
|
|
|
ManageRoles = "roles",
|
|
|
|
|
ManageNotifications = "notifications",
|
|
|
|
|
ManageOwnNotifications = "owner:notification",
|
|
|
|
|
ManageFollows = "follows",
|
|
|
|
|
ManageOwnFollows = "owner:follow",
|
|
|
|
|
ManageOwnApps = "owner:app",
|
|
|
|
|
Search = "search",
|
|
|
|
|
ViewPublicTimelines = "public_timelines",
|
|
|
|
|
ViewPrimateTimelines = "private_timelines",
|
|
|
|
|
IgnoreRateLimits = "ignore_rate_limits",
|
|
|
|
|
Impersonate = "impersonate",
|
|
|
|
|
ManageInstance = "instance",
|
|
|
|
|
ManageInstanceFederation = "instance:federation",
|
|
|
|
|
ManageInstanceSettings = "instance:settings",
|
2024-06-08 05:31:17 +02:00
|
|
|
/** Users who do not have this permission will not be able to login! */
|
2024-06-13 04:26:43 +02:00
|
|
|
OAuth = "oauth",
|
2024-06-08 05:31:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DEFAULT_ROLES = [
|
2024-06-13 04:26:43 +02:00
|
|
|
RolePermissions.ManageOwnNotes,
|
|
|
|
|
RolePermissions.ViewNotes,
|
|
|
|
|
RolePermissions.ViewNoteLikes,
|
|
|
|
|
RolePermissions.ViewNoteBoosts,
|
|
|
|
|
RolePermissions.ManageOwnAccount,
|
|
|
|
|
RolePermissions.ViewAccountFollows,
|
|
|
|
|
RolePermissions.ManageOwnLikes,
|
|
|
|
|
RolePermissions.ManageOwnBoosts,
|
|
|
|
|
RolePermissions.ViewAccounts,
|
|
|
|
|
RolePermissions.ManageOwnEmojis,
|
|
|
|
|
RolePermissions.ViewEmojis,
|
|
|
|
|
RolePermissions.ManageOwnMedia,
|
|
|
|
|
RolePermissions.ManageOwnBlocks,
|
|
|
|
|
RolePermissions.ManageOwnFilters,
|
|
|
|
|
RolePermissions.ManageOwnMutes,
|
|
|
|
|
RolePermissions.ManageOwnReports,
|
|
|
|
|
RolePermissions.ManageOwnSettings,
|
|
|
|
|
RolePermissions.ManageOwnNotifications,
|
|
|
|
|
RolePermissions.ManageOwnFollows,
|
|
|
|
|
RolePermissions.ManageOwnApps,
|
|
|
|
|
RolePermissions.Search,
|
|
|
|
|
RolePermissions.ViewPublicTimelines,
|
|
|
|
|
RolePermissions.ViewPrimateTimelines,
|
|
|
|
|
RolePermissions.OAuth,
|
2024-06-08 05:31:17 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const ADMIN_ROLES = [
|
|
|
|
|
...DEFAULT_ROLES,
|
2024-06-13 04:26:43 +02:00
|
|
|
RolePermissions.ManageNotes,
|
|
|
|
|
RolePermissions.ManageAccounts,
|
|
|
|
|
RolePermissions.ManageLikes,
|
|
|
|
|
RolePermissions.ManageBoosts,
|
|
|
|
|
RolePermissions.ManageEmojis,
|
|
|
|
|
RolePermissions.ManageMedia,
|
|
|
|
|
RolePermissions.ManageBlocks,
|
|
|
|
|
RolePermissions.ManageFilters,
|
|
|
|
|
RolePermissions.ManageMutes,
|
|
|
|
|
RolePermissions.ManageReports,
|
|
|
|
|
RolePermissions.ManageSettings,
|
|
|
|
|
RolePermissions.ManageRoles,
|
|
|
|
|
RolePermissions.ManageNotifications,
|
|
|
|
|
RolePermissions.ManageFollows,
|
|
|
|
|
RolePermissions.Impersonate,
|
|
|
|
|
RolePermissions.IgnoreRateLimits,
|
|
|
|
|
RolePermissions.ManageInstance,
|
|
|
|
|
RolePermissions.ManageInstanceFederation,
|
|
|
|
|
RolePermissions.ManageInstanceSettings,
|
2024-06-08 05:31:17 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const Roles = pgTable("Roles", {
|
|
|
|
|
id: uuid("id").default(sql`uuid_generate_v7()`).primaryKey().notNull(),
|
|
|
|
|
name: text("name").notNull(),
|
|
|
|
|
permissions: text("permissions")
|
|
|
|
|
.array()
|
|
|
|
|
.notNull()
|
|
|
|
|
.$type<RolePermissions[]>(),
|
|
|
|
|
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",
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
2024-04-14 03:21:38 +02:00
|
|
|
abUnique: uniqueIndex().on(table.emojiId, table.userId),
|
|
|
|
|
bIdx: 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",
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
2024-04-17 08:36:01 +02:00
|
|
|
abUnique: uniqueIndex().on(table.emojiId, table.noteId),
|
|
|
|
|
bIdx: index().on(table.noteId),
|
2024-04-11 13:39:07 +02:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
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",
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
2024-04-17 08:36:01 +02:00
|
|
|
abUnique: uniqueIndex().on(table.noteId, table.userId),
|
2024-04-14 03:21:38 +02:00
|
|
|
bIdx: index().on(table.userId),
|
2024-04-11 13:39:07 +02:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
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",
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
(table) => {
|
|
|
|
|
return {
|
2024-04-17 08:36:01 +02:00
|
|
|
abUnique: uniqueIndex().on(table.userId, table.noteId),
|
|
|
|
|
bIdx: index().on(table.noteId),
|
2024-04-11 13:39:07 +02:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const AttachmentsRelations = relations(Attachments, ({ one }) => ({
|
|
|
|
|
notes: one(Notes, {
|
|
|
|
|
fields: [Attachments.noteId],
|
|
|
|
|
references: [Notes.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const UsersRelations = relations(Users, ({ many, one }) => ({
|
|
|
|
|
emojis: many(EmojiToUser),
|
|
|
|
|
pinnedNotes: many(UserToPinnedNotes),
|
|
|
|
|
notes: many(Notes, {
|
|
|
|
|
relationName: "NoteToAuthor",
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
likes: many(Likes),
|
|
|
|
|
relationships: many(Relationships, {
|
2024-04-11 13:39:07 +02:00
|
|
|
relationName: "RelationshipToOwner",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
relationshipSubjects: many(Relationships, {
|
2024-04-11 13:39:07 +02:00
|
|
|
relationName: "RelationshipToSubject",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
notificationsMade: many(Notifications, {
|
2024-04-11 14:12:16 +02:00
|
|
|
relationName: "NotificationToAccount",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
notificationsReceived: many(Notifications, {
|
2024-04-11 14:12:16 +02:00
|
|
|
relationName: "NotificationToNotified",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
openIdAccounts: many(OpenIdAccounts),
|
|
|
|
|
flags: many(Flags),
|
|
|
|
|
modNotes: many(ModNotes),
|
|
|
|
|
modTags: many(ModTags),
|
|
|
|
|
tokens: many(Tokens),
|
|
|
|
|
instance: one(Instances, {
|
|
|
|
|
fields: [Users.instanceId],
|
|
|
|
|
references: [Instances.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
mentionedIn: many(NoteToMentions),
|
2024-06-08 06:57:29 +02:00
|
|
|
roles: many(RoleToUsers),
|
2024-04-11 13:39:07 +02:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const RelationshipsRelations = relations(Relationships, ({ one }) => ({
|
|
|
|
|
owner: one(Users, {
|
|
|
|
|
fields: [Relationships.ownerId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
relationName: "RelationshipToOwner",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
subject: one(Users, {
|
|
|
|
|
fields: [Relationships.subjectId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
relationName: "RelationshipToSubject",
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const TokensRelations = relations(Tokens, ({ one }) => ({
|
|
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [Tokens.userId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
application: one(Applications, {
|
|
|
|
|
fields: [Tokens.applicationId],
|
|
|
|
|
references: [Applications.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const NotesToUsersRelations = relations(NoteToMentions, ({ one }) => ({
|
|
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [NoteToMentions.noteId],
|
|
|
|
|
references: [Notes.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [NoteToMentions.userId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const UserToPinnedNotesRelations = relations(
|
|
|
|
|
UserToPinnedNotes,
|
2024-04-11 13:39:07 +02:00
|
|
|
({ one }) => ({
|
2024-04-17 08:36:01 +02:00
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [UserToPinnedNotes.noteId],
|
|
|
|
|
references: [Notes.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
user: one(Users, {
|
|
|
|
|
fields: [UserToPinnedNotes.userId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const NotesRelations = relations(Notes, ({ many, one }) => ({
|
|
|
|
|
emojis: many(EmojiToNote),
|
|
|
|
|
author: one(Users, {
|
|
|
|
|
fields: [Notes.authorId],
|
|
|
|
|
references: [Users.id],
|
|
|
|
|
relationName: "NoteToAuthor",
|
|
|
|
|
}),
|
|
|
|
|
attachments: many(Attachments),
|
|
|
|
|
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",
|
|
|
|
|
}),
|
|
|
|
|
application: one(Applications, {
|
|
|
|
|
fields: [Notes.applicationId],
|
|
|
|
|
references: [Applications.id],
|
|
|
|
|
}),
|
|
|
|
|
quotes: many(Notes, {
|
|
|
|
|
relationName: "NoteToQuotes",
|
|
|
|
|
}),
|
|
|
|
|
replies: many(Notes, {
|
|
|
|
|
relationName: "NoteToReplies",
|
|
|
|
|
}),
|
|
|
|
|
likes: many(Likes),
|
|
|
|
|
reblogs: many(Notes, {
|
|
|
|
|
relationName: "NoteToReblogs",
|
|
|
|
|
}),
|
|
|
|
|
notifications: many(Notifications),
|
2024-04-11 14:12:16 +02:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const NotificationsRelations = relations(Notifications, ({ one }) => ({
|
|
|
|
|
account: one(Users, {
|
|
|
|
|
fields: [Notifications.accountId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 14:12:16 +02:00
|
|
|
relationName: "NotificationToAccount",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
notified: one(Users, {
|
|
|
|
|
fields: [Notifications.notifiedId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 14:12:16 +02:00
|
|
|
relationName: "NotificationToNotified",
|
|
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [Notifications.noteId],
|
|
|
|
|
references: [Notes.id],
|
2024-04-11 14:12:16 +02:00
|
|
|
}),
|
2024-04-11 13:39:07 +02:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const LikesRelations = relations(Likes, ({ one }) => ({
|
|
|
|
|
liker: one(Users, {
|
|
|
|
|
fields: [Likes.likerId],
|
|
|
|
|
references: [Users.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
liked: one(Notes, {
|
|
|
|
|
fields: [Likes.likedId],
|
|
|
|
|
references: [Notes.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const EmojisRelations = relations(Emojis, ({ one, many }) => ({
|
|
|
|
|
instance: one(Instances, {
|
|
|
|
|
fields: [Emojis.instanceId],
|
|
|
|
|
references: [Instances.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
users: many(EmojiToUser),
|
|
|
|
|
notes: many(EmojiToNote),
|
2024-04-11 13:39:07 +02:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const InstancesRelations = relations(Instances, ({ many }) => ({
|
|
|
|
|
users: many(Users),
|
|
|
|
|
emojis: many(Emojis),
|
2024-04-11 13:39:07 +02:00
|
|
|
}));
|
|
|
|
|
|
2024-04-17 08:36:01 +02:00
|
|
|
export const EmojisToNotesRelations = relations(EmojiToNote, ({ one }) => ({
|
|
|
|
|
emoji: one(Emojis, {
|
|
|
|
|
fields: [EmojiToNote.emojiId],
|
|
|
|
|
references: [Emojis.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
2024-04-17 08:36:01 +02:00
|
|
|
note: one(Notes, {
|
|
|
|
|
fields: [EmojiToNote.noteId],
|
|
|
|
|
references: [Notes.id],
|
2024-04-11 13:39:07 +02:00
|
|
|
}),
|
|
|
|
|
}));
|