refactor (backend): distinguish between database columns and relations, set correct nullability

This commit is contained in:
naskya 2024-04-11 21:56:40 +09:00
parent 8287874cd6
commit aedf873248
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
56 changed files with 756 additions and 552 deletions

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -24,34 +25,16 @@ export class AbuseUserReport {
@Column(id())
public targetUserId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public targetUser: User | null;
@Index()
@Column(id())
public reporterId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public reporter: User | null;
@Column({
...id(),
nullable: true,
})
public assigneeId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "SET NULL",
})
@JoinColumn()
public assignee: User | null;
@Index()
@Column("boolean", {
default: false,
@ -85,4 +68,25 @@ export class AbuseUserReport {
})
public reporterHost: string | null;
//#endregion
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public targetUser: Relation<User>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public reporter: Relation<User>;
@ManyToOne(() => User, {
onDelete: "SET NULL",
nullable: true,
})
@JoinColumn()
public assignee: Relation<User | null>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
Column,
ManyToOne,
JoinColumn,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { App } from "./app.js";
@ -48,24 +49,12 @@ export class AccessToken {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column({
...id(),
nullable: true,
})
public appId: App["id"] | null;
@ManyToOne((type) => App, {
onDelete: "CASCADE",
})
@JoinColumn()
public app: App | null;
@Column("varchar", {
length: 128,
nullable: true,
@ -95,4 +84,18 @@ export class AccessToken {
default: false,
})
public fetched: boolean;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
@ManyToOne(() => App, {
onDelete: "CASCADE",
})
@JoinColumn()
public app: Relation<App>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { Announcement } from "./announcement.js";
@ -25,19 +26,21 @@ export class AnnouncementRead {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column(id())
public announcementId: Announcement["id"];
@ManyToOne((type) => Announcement, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public announcement: Announcement | null;
public user: Relation<User>;
@ManyToOne(() => Announcement, {
onDelete: "CASCADE",
})
@JoinColumn()
public announcement: Relation<Announcement>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -28,12 +29,6 @@ export class Antenna {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
comment: "The name of the Antenna.",
@ -51,24 +46,12 @@ export class Antenna {
})
public userListId: UserList["id"] | null;
@ManyToOne((type) => UserList, {
onDelete: "CASCADE",
})
@JoinColumn()
public userList: UserList | null;
@Column({
...id(),
nullable: true,
})
public userGroupJoiningId: UserGroupJoining["id"] | null;
@ManyToOne((type) => UserGroupJoining, {
onDelete: "CASCADE",
})
@JoinColumn()
public userGroupJoining: UserGroupJoining | null;
@Column("varchar", {
length: 1024,
array: true,
@ -112,4 +95,27 @@ export class Antenna {
@Column("boolean")
public notify: boolean;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public user: Relation<User | null>;
@ManyToOne(() => UserList, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public userList: Relation<UserList | null>;
@ManyToOne(() => UserGroupJoining, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public userGroupJoining: Relation<UserGroupJoining | null>;
//#endregion
}

View file

@ -1,4 +1,11 @@
import { Entity, PrimaryColumn, Column, Index, ManyToOne } from "typeorm";
import {
Entity,
PrimaryColumn,
Column,
Index,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -21,12 +28,6 @@ export class App {
})
public userId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "SET NULL",
nullable: true,
})
public user: User | null;
@Index()
@Column("varchar", {
length: 64,
@ -59,4 +60,12 @@ export class App {
comment: "The callbackUrl of the App.",
})
public callbackUrl: string | null;
//#region Relations
@ManyToOne(() => User, {
onDelete: "SET NULL",
nullable: true,
})
public user: Relation<User | null>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
Column,
ManyToOne,
Index,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -18,12 +19,6 @@ export class AttestationChallenge {
@PrimaryColumn(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column("varchar", {
length: 64,
@ -43,6 +38,14 @@ export class AttestationChallenge {
})
public registrationChallenge: boolean;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
constructor(data: Partial<AttestationChallenge>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
Column,
ManyToOne,
JoinColumn,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { App } from "./app.js";
@ -32,19 +33,20 @@ export class AuthSession {
})
public userId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public user: User | null;
@Column(id())
public appId: App["id"];
@ManyToOne((type) => App, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public app: App | null;
public user: Relation<User>;
@ManyToOne(() => App, {
onDelete: "CASCADE",
})
@JoinColumn()
public app: App;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -28,12 +29,6 @@ export class Blocking {
})
public blockeeId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public blockee: User | null;
@Index()
@Column({
...id(),
@ -41,9 +36,17 @@ export class Blocking {
})
public blockerId: User["id"];
@ManyToOne((type) => User, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public blocker: User | null;
public blockee: Relation<User>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public blocker: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -29,12 +30,6 @@ export class ChannelFollowing {
})
public followeeId: Channel["id"];
@ManyToOne((type) => Channel, {
onDelete: "CASCADE",
})
@JoinColumn()
public followee: Channel | null;
@Index()
@Column({
...id(),
@ -42,9 +37,17 @@ export class ChannelFollowing {
})
public followerId: User["id"];
@ManyToOne((type) => User, {
//#region Relations
@ManyToOne(() => Channel, {
onDelete: "CASCADE",
})
@JoinColumn()
public follower: User | null;
public followee: Relation<Channel>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public follower: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { Note } from "./note.js";
import { Channel } from "./channel.js";
@ -25,18 +26,20 @@ export class ChannelNotePining {
@Column(id())
public channelId: Channel["id"];
@ManyToOne((type) => Channel, {
onDelete: "CASCADE",
})
@JoinColumn()
public channel: Channel | null;
@Column(id())
public noteId: Note["id"];
@ManyToOne((type) => Note, {
//#region Relations
@ManyToOne(() => Channel, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
public channel: Relation<Channel>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -35,12 +36,6 @@ export class Channel {
})
public userId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "SET NULL",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
comment: "The name of the Channel.",
@ -61,12 +56,6 @@ export class Channel {
})
public bannerId: DriveFile["id"] | null;
@ManyToOne((type) => DriveFile, {
onDelete: "SET NULL",
})
@JoinColumn()
public banner: DriveFile | null;
@Index()
@Column("integer", {
default: 0,
@ -80,4 +69,18 @@ export class Channel {
comment: "The count of users.",
})
public usersCount: number;
//#region Relations
@ManyToOne(() => User, {
onDelete: "SET NULL",
})
@JoinColumn()
public user: Relation<User>;
@ManyToOne(() => DriveFile, {
onDelete: "SET NULL",
})
@JoinColumn()
public banner: Relation<DriveFile>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
Column,
ManyToOne,
PrimaryColumn,
type Relation,
} from "typeorm";
import { Note } from "./note.js";
import { Clip } from "./clip.js";
@ -23,12 +24,6 @@ export class ClipNote {
})
public noteId: Note["id"];
@ManyToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
@Index()
@Column({
...id(),
@ -36,9 +31,17 @@ export class ClipNote {
})
public clipId: Clip["id"];
@ManyToOne((type) => Clip, {
//#region Relations
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public clip: Clip | null;
public note: Relation<Note>;
@ManyToOne(() => Clip, {
onDelete: "CASCADE",
})
@JoinColumn()
public clip: Relation<Clip>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -26,12 +27,6 @@ export class Clip {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
comment: "The name of the Clip.",
@ -49,4 +44,12 @@ export class Clip {
comment: "The description of the Clip.",
})
public description: string | null;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -214,12 +214,14 @@ export class DriveFile {
@ManyToOne(() => User, {
onDelete: "SET NULL",
nullable: true,
})
@JoinColumn()
public user: User | null;
@ManyToOne(() => DriveFolder, {
onDelete: "SET NULL",
nullable: true,
})
@JoinColumn()
public folder: DriveFolder | null;

View file

@ -5,6 +5,7 @@ import {
PrimaryColumn,
Index,
Column,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -34,12 +35,6 @@ export class DriveFolder {
})
public userId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column({
...id(),
@ -49,9 +44,19 @@ export class DriveFolder {
})
public parentId: DriveFolder["id"] | null;
@ManyToOne((type) => DriveFolder, {
onDelete: "SET NULL",
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public parent: DriveFolder | null;
public user: Relation<User | null>;
@ManyToOne(() => DriveFolder, {
onDelete: "SET NULL",
nullable: true,
})
@JoinColumn()
public parent: Relation<DriveFolder | null>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -27,12 +28,6 @@ export class FollowRequest {
})
public followeeId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public followee: User | null;
@Index()
@Column({
...id(),
@ -40,12 +35,6 @@ export class FollowRequest {
})
public followerId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public follower: User | null;
@Column("varchar", {
length: 128,
nullable: true,
@ -96,4 +85,18 @@ export class FollowRequest {
})
public followeeSharedInbox: string | null;
//#endregion
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public followee: Relation<User>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public follower: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -28,12 +29,6 @@ export class Following {
})
public followeeId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public followee: User | null;
@Index()
@Column({
...id(),
@ -41,12 +36,6 @@ export class Following {
})
public followerId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public follower: User | null;
//#region Denormalized fields
@Index()
@Column("varchar", {
@ -92,4 +81,18 @@ export class Following {
})
public followeeSharedInbox: string | null;
//#endregion
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public followee: Relation<User>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public follower: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -23,18 +24,20 @@ export class GalleryLike {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column(id())
public postId: GalleryPost["id"];
@ManyToOne((type) => GalleryPost, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public post: GalleryPost | null;
public user: Relation<User>;
@ManyToOne(() => GalleryPost, {
onDelete: "CASCADE",
})
@JoinColumn()
public post: Relation<GalleryPost>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
Column,
PrimaryColumn,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -45,12 +46,6 @@ export class GalleryPost {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column({
...id(),
@ -80,6 +75,14 @@ export class GalleryPost {
})
public tags: string[];
//#region Relations
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
constructor(data: Partial<GalleryPost>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { DriveFile } from "./drive-file.js";
@ -29,12 +30,6 @@ export class MessagingMessage {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column({
...id(),
@ -43,12 +38,6 @@ export class MessagingMessage {
})
public recipientId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public recipient: User | null;
@Index()
@Column({
...id(),
@ -57,12 +46,6 @@ export class MessagingMessage {
})
public groupId: UserGroup["id"] | null;
@ManyToOne((type) => UserGroup, {
onDelete: "CASCADE",
})
@JoinColumn()
public group: UserGroup | null;
@Column("varchar", {
length: 4096,
nullable: true,
@ -93,9 +76,31 @@ export class MessagingMessage {
})
public fileId: DriveFile["id"] | null;
@ManyToOne((type) => DriveFile, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public file: DriveFile | null;
public user: Relation<User>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public recipient: Relation<User>;
@ManyToOne(() => UserGroup, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public group: Relation<UserGroup | null>;
@ManyToOne(() => DriveFile, {
onDelete: "CASCADE", // TODO: change this to SET NULL
nullable: true,
})
@JoinColumn()
public file: Relation<DriveFile | null>;
//#endregion
}

View file

@ -1,4 +1,11 @@
import { Entity, Column, PrimaryColumn, ManyToOne, JoinColumn } from "typeorm";
import {
Entity,
Column,
PrimaryColumn,
ManyToOne,
JoinColumn,
type Relation,
} from "typeorm";
import { id } from "../id.js";
import { User } from "./user.js";
import type { Clip } from "./clip.js";
@ -218,12 +225,6 @@ export class Meta {
})
public proxyAccountId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "SET NULL",
})
@JoinColumn()
public proxyAccount: User | null;
@Column("boolean", {
default: false,
})
@ -500,4 +501,13 @@ export class Meta {
nullable: true,
})
public donationLink: string | null;
//#region Relations
@ManyToOne(() => User, {
onDelete: "SET NULL",
nullable: true,
})
@JoinColumn()
public proxyAccount: Relation<User | null>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -23,12 +24,6 @@ export class ModerationLog {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
})
@ -36,4 +31,12 @@ export class ModerationLog {
@Column("jsonb")
public info: Record<string, any>;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
Column,
ManyToOne,
PrimaryColumn,
type Relation,
} from "typeorm";
import { Note } from "./note.js";
import { User } from "./user.js";
@ -24,12 +25,6 @@ export class MutedNote {
})
public noteId: Note["id"];
@ManyToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
@Index()
@Column({
...id(),
@ -37,12 +32,6 @@ export class MutedNote {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
/**
*
*/
@ -52,4 +41,18 @@ export class MutedNote {
comment: "The reason of the MutedNote.",
})
public reason: (typeof mutedNoteReasons)[number];
//#region Relations
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -34,12 +35,6 @@ export class Muting {
})
public muteeId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public mutee: User | null;
@Index()
@Column({
...id(),
@ -47,9 +42,17 @@ export class Muting {
})
public muterId: User["id"];
@ManyToOne((type) => User, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public muter: User | null;
public mutee: Relation<User>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public muter: Relation<User>;
//#endregion
}

View file

@ -8,7 +8,7 @@ import {
} from "typeorm";
import { Note } from "./note.js";
import { id } from "../id.js";
import { DriveFile } from "./drive-file.js";
import type { DriveFile } from "./drive-file.js";
@Entity()
export class NoteEdit {
@ -22,12 +22,6 @@ export class NoteEdit {
})
public noteId: Note["id"];
@ManyToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
@Column("text", {
nullable: true,
})
@ -57,4 +51,12 @@ export class NoteEdit {
default: "{}",
})
public emojis: string[];
//#region Relations
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { Note } from "./note.js";
import { User } from "./user.js";
@ -25,18 +26,20 @@ export class NoteFavorite {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column(id())
public noteId: Note["id"];
@ManyToOne((type) => Note, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
public user: Relation<User>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { Note } from "./note.js";
@ -26,26 +27,28 @@ export class NoteReaction {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user?: User | null;
@Index()
@Column(id())
public noteId: Note["id"];
@ManyToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note?: Note | null;
// TODO: 対象noteのuserIdを非正規化したい(「受け取ったリアクション一覧」のようなものを(JOIN無しで)実装したいため)
@Column("varchar", {
length: 260,
})
public reaction: string;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -24,15 +25,17 @@ export class NoteThreadMuting {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column("varchar", {
length: 256,
})
public threadId: string;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { Note } from "./note.js";
@ -21,22 +22,10 @@ export class NoteUnread {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column(id())
public noteId: Note["id"];
@ManyToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
/**
*
*/
@ -67,4 +56,18 @@ export class NoteUnread {
})
public noteChannelId: Channel["id"] | null;
//#endregion
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { Note } from "./note.js";
@ -29,12 +30,6 @@ export class NoteWatching {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column({
...id(),
@ -42,12 +37,6 @@ export class NoteWatching {
})
public noteId: Note["id"];
@ManyToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
//#region Denormalized fields
@Index()
@Column({
@ -56,4 +45,18 @@ export class NoteWatching {
})
public noteUserId: Note["userId"];
//#endregion
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -206,55 +206,6 @@ export class Note {
})
public channelId: Channel["id"] | null;
//#region Relations
@OneToMany(
() => NoteFile,
(noteFile: NoteFile) => noteFile.note,
)
public noteFiles: Relation<NoteFile[]>;
@ManyToMany(
() => DriveFile,
(file: DriveFile) => file.notes,
)
@JoinTable({
name: "note_file",
joinColumn: {
name: "noteId",
referencedColumnName: "id",
},
inverseJoinColumn: {
name: "fileId",
referencedColumnName: "id",
},
})
public files: Relation<DriveFile[]>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public reply: Note | null;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public renote: Note | null;
@ManyToOne(() => Channel, {
onDelete: "CASCADE",
})
@JoinColumn()
public channel: Channel | null;
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
//#endregion Relations
//#region Denormalized fields
@Index()
@Column("varchar", {
@ -299,6 +250,59 @@ export class Note {
public updatedAt: Date | null;
//#endregion
//#region Relations
@OneToMany(
() => NoteFile,
(noteFile: NoteFile) => noteFile.note,
)
public noteFiles: Relation<NoteFile[]>;
@ManyToMany(
() => DriveFile,
(file: DriveFile) => file.notes,
)
@JoinTable({
name: "note_file",
joinColumn: {
name: "noteId",
referencedColumnName: "id",
},
inverseJoinColumn: {
name: "fileId",
referencedColumnName: "id",
},
})
public files: Relation<DriveFile[]>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public reply: Relation<Note | null>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public renote: Relation<Note | null>;
@ManyToOne(() => Channel, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public channel: Relation<Channel | null>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public user: Relation<User | null>;
//#endregion Relations
constructor(data: Partial<Note>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
ManyToOne,
Column,
PrimaryColumn,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -35,12 +36,6 @@ export class Notification {
})
public notifieeId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public notifiee: User | null;
/**
* Notification sender (initiator)
*/
@ -52,12 +47,6 @@ export class Notification {
})
public notifierId: User["id"] | null;
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public notifier: User | null;
/**
* Notification types:
* follow - Follow request
@ -96,36 +85,18 @@ export class Notification {
})
public noteId: Note["id"] | null;
@ManyToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
@Column({
...id(),
nullable: true,
})
public followRequestId: FollowRequest["id"] | null;
@ManyToOne((type) => FollowRequest, {
onDelete: "CASCADE",
})
@JoinColumn()
public followRequest: FollowRequest | null;
@Column({
...id(),
nullable: true,
})
public userGroupInvitationId: UserGroupInvitation["id"] | null;
@ManyToOne((type) => UserGroupInvitation, {
onDelete: "CASCADE",
})
@JoinColumn()
public userGroupInvitation: UserGroupInvitation | null;
@Column("varchar", {
length: 128,
nullable: true,
@ -176,9 +147,46 @@ export class Notification {
})
public appAccessTokenId: AccessToken["id"] | null;
@ManyToOne((type) => AccessToken, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public appAccessToken: AccessToken | null;
public notifiee: Relation<User>;
@ManyToOne(() => User, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public notifier: Relation<User | null>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public note: Relation<Note | null>;
@ManyToOne(() => FollowRequest, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public followRequest: Relation<FollowRequest | null>;
@ManyToOne(() => UserGroupInvitation, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public userGroupInvitation: Relation<UserGroupInvitation | null>;
@ManyToOne(() => AccessToken, {
onDelete: "CASCADE",
nullable: true,
})
@JoinColumn()
public appAccessToken: Relation<AccessToken | null>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -23,18 +24,20 @@ export class PageLike {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column(id())
public pageId: Page["id"];
@ManyToOne((type) => Page, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public page: Page | null;
public user: Relation<User>;
@ManyToOne(() => Page, {
onDelete: "CASCADE",
})
@JoinColumn()
public page: Relation<Page>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
Column,
PrimaryColumn,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -68,24 +69,12 @@ export class Page {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column({
...id(),
nullable: true,
})
public eyeCatchingImageId: DriveFile["id"] | null;
@ManyToOne((type) => DriveFile, {
onDelete: "CASCADE",
})
@JoinColumn()
public eyeCatchingImage: DriveFile | null;
@Column("jsonb", {
default: [],
})
@ -123,6 +112,20 @@ export class Page {
})
public likedCount: number;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
@ManyToOne(() => DriveFile, {
onDelete: "CASCADE", // TODO: this should be SET NULL
})
@JoinColumn()
public eyeCatchingImage: Relation<DriveFile | null>;
//#endregion
constructor(data: Partial<Page>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
Column,
ManyToOne,
JoinColumn,
type Relation,
} from "typeorm";
import { id } from "../id.js";
import { User } from "./user.js";
@ -29,9 +30,11 @@ export class PasswordResetRequest {
})
public userId: User["id"];
@ManyToOne((type) => User, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
public user: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { Note } from "./note.js";
@ -26,22 +27,24 @@ export class PollVote {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column(id())
public noteId: Note["id"];
@ManyToOne((type) => Note, {
@Column("integer")
public choice: number;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
public user: Relation<User>;
@Column("integer")
public choice: number;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,23 +5,18 @@ import {
JoinColumn,
Column,
OneToOne,
type Relation,
} from "typeorm";
import { id } from "../id.js";
import { Note } from "./note.js";
import type { User } from "./user.js";
import { noteVisibilities } from "../../types.js";
import { noteVisibilities } from "@/types.js";
@Entity()
export class Poll {
@PrimaryColumn(id())
public noteId: Note["id"];
@OneToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
@Column("timestamp without time zone", {
nullable: true,
})
@ -65,6 +60,14 @@ export class Poll {
public userHost: string | null;
//#endregion
//#region Relations
@OneToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
constructor(data: Partial<Poll>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
OneToOne,
type Relation,
} from "typeorm";
import { Note } from "./note.js";
import type { User } from "./user.js";
@ -15,12 +16,6 @@ export class PromoNote {
@PrimaryColumn(id())
public noteId: Note["id"];
@OneToOne((type) => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
@Column("timestamp without time zone")
public expiresAt: Date;
@ -32,4 +27,12 @@ export class PromoNote {
})
public userId: User["id"];
//#endregion
//#region Relations
@OneToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { Note } from "./note.js";
import { User } from "./user.js";
@ -25,18 +26,20 @@ export class PromoRead {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column(id())
public noteId: Note["id"];
@ManyToOne((type) => Note, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
public user: Relation<User>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -32,12 +33,6 @@ export class RegistryItem {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 1024,
comment: "The key of the RegistryItem.",
@ -66,4 +61,12 @@ export class RegistryItem {
nullable: true,
})
public domain: string | null;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -2,12 +2,13 @@ import {
PrimaryColumn,
Entity,
Index,
JoinColumn,
// JoinColumn,
Column,
ManyToOne,
// ManyToOne,
// type Relation,
} from "typeorm";
import { id } from "../id.js";
import { User } from "./user.js";
import type { User } from "./user.js";
@Entity()
@Index(["muterId", "muteeId"], { unique: true })
@ -28,12 +29,6 @@ export class RenoteMuting {
})
public muteeId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public mutee: User | null;
@Index()
@Column({
...id(),
@ -41,9 +36,19 @@ export class RenoteMuting {
})
public muterId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public muter: User | null;
//#region Relations
/* FIXME: There is no such relation */
// @ManyToOne(() => User, {
// onDelete: "CASCADE",
// })
// @JoinColumn()
// public mutee: Relation<User>;
/* FIXME: There is no such relation */
// @ManyToOne(() => User, {
// onDelete: "CASCADE",
// })
// @JoinColumn()
// public muter: Relation<User>;
//#endregion
}

View file

@ -2,12 +2,13 @@ import {
PrimaryColumn,
Entity,
Index,
JoinColumn,
// JoinColumn,
Column,
ManyToOne,
// ManyToOne,
// type Relation,
} from "typeorm";
import { id } from "../id.js";
import { User } from "./user.js";
import type { User } from "./user.js";
@Entity()
@Index(["muterId", "muteeId"], { unique: true })
@ -28,12 +29,6 @@ export class ReplyMuting {
})
public muteeId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public mutee: User | null;
@Index()
@Column({
...id(),
@ -41,9 +36,19 @@ export class ReplyMuting {
})
public muterId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public muter: User | null;
//#region Relations
/* FIXME: There is no such relation */
// @ManyToOne(() => User, {
// onDelete: "CASCADE",
// })
// @JoinColumn()
// public mutee: Relation<User>;
/* FIXME: There is no such relation */
// @ManyToOne(() => User, {
// onDelete: "CASCADE",
// })
// @JoinColumn()
// public muter: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -23,12 +24,6 @@ export class Signin {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
})
@ -39,4 +34,12 @@ export class Signin {
@Column("boolean")
public success: boolean;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -21,12 +22,6 @@ export class SwSubscription {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 512,
})
@ -46,4 +41,12 @@ export class SwSubscription {
default: false,
})
public sendReadMessage: boolean;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { UserGroup } from "./user-group.js";
@ -28,12 +29,6 @@ export class UserGroupInvitation {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column({
...id(),
@ -41,9 +36,17 @@ export class UserGroupInvitation {
})
public userGroupId: UserGroup["id"];
@ManyToOne((type) => UserGroup, {
//#region Relation
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public userGroup: UserGroup | null;
public user: Relation<User>;
@ManyToOne(() => UserGroup, {
onDelete: "CASCADE",
})
@JoinColumn()
public userGroup: Relation<UserGroup>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { UserGroup } from "./user-group.js";
@ -28,12 +29,6 @@ export class UserGroupJoining {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column({
...id(),
@ -41,9 +36,17 @@ export class UserGroupJoining {
})
public userGroupId: UserGroup["id"];
@ManyToOne((type) => UserGroup, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public userGroup: UserGroup | null;
public user: Relation<User>;
@ManyToOne(() => UserGroup, {
onDelete: "CASCADE",
})
@JoinColumn()
public userGroup: Relation<UserGroup>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
Column,
PrimaryColumn,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -32,17 +33,19 @@ export class UserGroup {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("boolean", {
default: false,
})
public isPrivate: boolean;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
constructor(data: Partial<UserGroup>) {
if (data == null) return;

View file

@ -1,4 +1,11 @@
import { PrimaryColumn, Entity, JoinColumn, Column, OneToOne } from "typeorm";
import {
PrimaryColumn,
Entity,
JoinColumn,
Column,
OneToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -7,12 +14,6 @@ export class UserKeypair {
@PrimaryColumn(id())
public userId: User["id"];
@OneToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 4096,
})
@ -23,6 +24,14 @@ export class UserKeypair {
})
public privateKey: string;
//#region Relations
@OneToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
constructor(data: Partial<UserKeypair>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { UserList } from "./user-list.js";
@ -28,12 +29,6 @@ export class UserListJoining {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column({
...id(),
@ -41,9 +36,17 @@ export class UserListJoining {
})
public userListId: UserList["id"];
@ManyToOne((type) => UserList, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public userList: UserList | null;
public user: Relation<User>;
@ManyToOne(() => UserList, {
onDelete: "CASCADE",
})
@JoinColumn()
public userList: Relation<UserList>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -26,15 +27,17 @@ export class UserList {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
comment: "The name of the UserList.",
})
public name: string;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { Note } from "./note.js";
import { User } from "./user.js";
@ -25,18 +26,20 @@ export class UserNotePining {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column(id())
public noteId: Note["id"];
@ManyToOne((type) => Note, {
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Note | null;
public user: Relation<User>;
@ManyToOne(() => Note, {
onDelete: "CASCADE",
})
@JoinColumn()
public note: Relation<Note>;
//#endregion
}

View file

@ -5,6 +5,7 @@ import {
OneToOne,
JoinColumn,
PrimaryColumn,
type Relation,
} from "typeorm";
import { ffVisibility, notificationTypes } from "@/types.js";
import { id } from "../id.js";
@ -18,12 +19,6 @@ export class UserProfile {
@PrimaryColumn(id())
public userId: User["id"];
@OneToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
nullable: true,
@ -246,6 +241,14 @@ export class UserProfile {
public userHost: string | null;
//#endregion
//#region Relations
@OneToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
constructor(data: Partial<UserProfile>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
OneToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -14,12 +15,6 @@ export class UserPublickey {
@PrimaryColumn(id())
public userId: User["id"];
@OneToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index({ unique: true })
@Column("varchar", {
length: 512,
@ -31,6 +26,14 @@ export class UserPublickey {
})
public keyPem: string;
//#region Relations
@OneToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
constructor(data: Partial<UserPublickey>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
Column,
ManyToOne,
Index,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -20,12 +21,6 @@ export class UserSecurityKey {
@Column(id())
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
@Column("varchar", {
comment:
@ -45,6 +40,14 @@ export class UserSecurityKey {
})
public name: string;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
constructor(data: Partial<UserSecurityKey>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
OneToOne,
JoinColumn,
PrimaryColumn,
type Relation,
} from "typeorm";
import { id } from "../id.js";
import { DriveFile } from "./drive-file.js";
@ -106,12 +107,6 @@ export class User {
})
public avatarId: DriveFile["id"] | null;
@OneToOne((type) => DriveFile, {
onDelete: "SET NULL",
})
@JoinColumn()
public avatar: DriveFile | null;
@Column({
...id(),
nullable: true,
@ -119,12 +114,6 @@ export class User {
})
public bannerId: DriveFile["id"] | null;
@OneToOne((type) => DriveFile, {
onDelete: "SET NULL",
})
@JoinColumn()
public banner: DriveFile | null;
@Index()
@Column("varchar", {
length: 128,
@ -286,6 +275,22 @@ export class User {
})
public isIndexable: boolean;
//#region Relations
@OneToOne(() => DriveFile, {
onDelete: "SET NULL",
nullable: true,
})
@JoinColumn()
public avatar: Relation<DriveFile | null>;
@OneToOne(() => DriveFile, {
onDelete: "SET NULL",
nullable: true,
})
@JoinColumn()
public banner: Relation<DriveFile | null>;
//#endregion
constructor(data: Partial<User>) {
if (data == null) return;

View file

@ -5,6 +5,7 @@ import {
JoinColumn,
Column,
ManyToOne,
type Relation,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@ -37,12 +38,6 @@ export class Webhook {
})
public userId: User["id"];
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Column("varchar", {
length: 128,
comment: "The name of the Antenna.",
@ -88,4 +83,12 @@ export class Webhook {
nullable: true,
})
public latestStatus: number | null;
//#region Relations
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: Relation<User>;
//#endregion
}