add channel_muting table and entities

This commit is contained in:
samunohito 2024-06-10 20:02:40 +09:00
parent 4096dabe1e
commit cbc256b7ce
6 changed files with 99 additions and 4 deletions

View file

@ -0,0 +1,37 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
export class AddChannelMuting1718015380000 {
name = 'AddChannelMuting1718015380000'
async up(queryRunner) {
await queryRunner.query(`
CREATE TABLE "channel_muting"
(
"id" varchar(32) NOT NULL,
"userId" varchar(32) NOT NULL,
"channelId" varchar(32) NOT NULL,
"expiresAt" timestamp with time zone,
CONSTRAINT "PK_channel_muting_id" PRIMARY KEY ("id"),
CONSTRAINT "FK_channel_muting_userId" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "FK_channel_muting_channelId" FOREIGN KEY ("channelId") REFERENCES "channel"("id") ON DELETE CASCADE ON UPDATE NO ACTION
);
CREATE INDEX "IDX_channel_muting_userId" ON "channel_muting" ("userId");
CREATE INDEX "IDX_channel_muting_channelId" ON "channel_muting" ("channelId");
`);
}
async down(queryRunner) {
await queryRunner.query(`
ALTER TABLE "channel_muting"
DROP CONSTRAINT "FK_channel_muting_userId";
ALTER TABLE "channel_muting"
DROP CONSTRAINT "FK_channel_muting_channelId";
DROP INDEX "IDX_channel_muting_userId";
DROP INDEX "IDX_channel_muting_channelId";
DROP TABLE "channel_muting";
`);
}
}

View file

@ -69,6 +69,7 @@ export const DI = {
channelsRepository: Symbol('channelsRepository'),
channelFollowingsRepository: Symbol('channelFollowingsRepository'),
channelFavoritesRepository: Symbol('channelFavoritesRepository'),
channelMutingRepository: Symbol('channelMutingRepository'),
registryItemsRepository: Symbol('registryItemsRepository'),
webhooksRepository: Symbol('webhooksRepository'),
systemWebhooksRepository: Symbol('systemWebhooksRepository'),

View file

@ -0,0 +1,46 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
import { id } from './util/id.js';
import { MiUser } from './User.js';
import { MiChannel } from './Channel.js';
@Entity('channel_muting')
@Index(['userId', 'channelId'], {})
export class MiChannelMuting {
@PrimaryColumn(id())
public id: string;
@Index()
@Column({
...id(),
})
public userId: MiUser['id'];
@ManyToOne(type => MiUser, {
onDelete: 'CASCADE',
})
@JoinColumn()
public user: MiUser | null;
@Index()
@Column({
...id(),
})
public channelId: MiChannel['id'];
@ManyToOne(type => MiChannel, {
onDelete: 'CASCADE',
})
@JoinColumn()
public channel: MiChannel | null;
@Index()
@Column('timestamp with time zone', {
nullable: true,
})
public expiresAt: Date | null;
}

View file

@ -22,6 +22,7 @@ import {
MiChannel,
MiChannelFavorite,
MiChannelFollowing,
MiChannelMuting,
MiClip,
MiClipFavorite,
MiClipNote,
@ -417,6 +418,12 @@ const $channelFavoritesRepository: Provider = {
inject: [DI.db],
};
const $channelMutingRepository: Provider = {
provide: DI.channelMutingRepository,
useFactory: (db: DataSource) => db.getRepository(MiChannelMuting).extend(miRepository as MiRepository<MiChannelMuting>),
inject: [DI.db],
};
const $registryItemsRepository: Provider = {
provide: DI.registryItemsRepository,
useFactory: (db: DataSource) => db.getRepository(MiRegistryItem).extend(miRepository as MiRepository<MiRegistryItem>),
@ -554,6 +561,7 @@ const $reversiGamesRepository: Provider = {
$channelsRepository,
$channelFollowingsRepository,
$channelFavoritesRepository,
$channelMutingRepository,
$registryItemsRepository,
$webhooksRepository,
$systemWebhooksRepository,
@ -625,6 +633,7 @@ const $reversiGamesRepository: Provider = {
$channelsRepository,
$channelFollowingsRepository,
$channelFavoritesRepository,
$channelMutingRepository,
$registryItemsRepository,
$webhooksRepository,
$systemWebhooksRepository,

View file

@ -3,13 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { FindOneOptions, InsertQueryBuilder, ObjectLiteral, Repository, SelectQueryBuilder, TypeORMError } from 'typeorm';
import { DriverUtils } from 'typeorm/driver/DriverUtils.js';
import { FindOneOptions, InsertQueryBuilder, ObjectLiteral, Repository, SelectQueryBuilder } from 'typeorm';
import { RelationCountLoader } from 'typeorm/query-builder/relation-count/RelationCountLoader.js';
import { RelationIdLoader } from 'typeorm/query-builder/relation-id/RelationIdLoader.js';
import { RawSqlResultsToEntityTransformer } from 'typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js';
import { ObjectUtils } from 'typeorm/util/ObjectUtils.js';
import { OrmUtils } from 'typeorm/util/OrmUtils.js';
import { MiAbuseUserReport } from '@/models/AbuseUserReport.js';
import { MiAbuseReportNotificationRecipient } from '@/models/AbuseReportNotificationRecipient.js';
import { MiAccessToken } from '@/models/AccessToken.js';
@ -23,6 +20,7 @@ import { MiAuthSession } from '@/models/AuthSession.js';
import { MiBlocking } from '@/models/Blocking.js';
import { MiChannelFollowing } from '@/models/ChannelFollowing.js';
import { MiChannelFavorite } from '@/models/ChannelFavorite.js';
import { MiChannelMuting } from "@/models/ChannelMuting.js";
import { MiClip } from '@/models/Clip.js';
import { MiClipNote } from '@/models/ClipNote.js';
import { MiClipFavorite } from '@/models/ClipFavorite.js';
@ -138,6 +136,7 @@ export {
MiBlocking,
MiChannelFollowing,
MiChannelFavorite,
MiChannelMuting,
MiClip,
MiClipNote,
MiClipFavorite,
@ -209,6 +208,7 @@ export type AuthSessionsRepository = Repository<MiAuthSession> & MiRepository<Mi
export type BlockingsRepository = Repository<MiBlocking> & MiRepository<MiBlocking>;
export type ChannelFollowingsRepository = Repository<MiChannelFollowing> & MiRepository<MiChannelFollowing>;
export type ChannelFavoritesRepository = Repository<MiChannelFavorite> & MiRepository<MiChannelFavorite>;
export type ChannelMutingRepository = Repository<MiChannelMuting> & MiRepository<MiChannelMuting>;
export type ClipsRepository = Repository<MiClip> & MiRepository<MiClip>;
export type ClipNotesRepository = Repository<MiClipNote> & MiRepository<MiClipNote>;
export type ClipFavoritesRepository = Repository<MiClipFavorite> & MiRepository<MiClipFavorite>;

View file

@ -22,6 +22,7 @@ import { MiAuthSession } from '@/models/AuthSession.js';
import { MiBlocking } from '@/models/Blocking.js';
import { MiChannelFollowing } from '@/models/ChannelFollowing.js';
import { MiChannelFavorite } from '@/models/ChannelFavorite.js';
import { MiChannelMuting } from "@/models/ChannelMuting.js";
import { MiClip } from '@/models/Clip.js';
import { MiClipNote } from '@/models/ClipNote.js';
import { MiClipFavorite } from '@/models/ClipFavorite.js';
@ -183,6 +184,7 @@ export const entities = [
MiChannel,
MiChannelFollowing,
MiChannelFavorite,
MiChannelMuting,
MiRegistryItem,
MiAd,
MiPasswordResetRequest,