mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
add foreign keys to following where instance is referenced
This commit is contained in:
parent
59099a2b2a
commit
51128028f4
2 changed files with 47 additions and 0 deletions
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class
|
||||||
|
* @implements {MigrationInterface}
|
||||||
|
*/
|
||||||
|
export class AddInstanceForeignKeysToFollowing1748137683887 {
|
||||||
|
name = 'AddInstanceForeignKeysToFollowing1748137683887'
|
||||||
|
|
||||||
|
async up(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "following" ADD CONSTRAINT "FK_following_followerHost" FOREIGN KEY ("followerHost") REFERENCES "instance"("host") ON DELETE CASCADE ON UPDATE NO ACTION`);
|
||||||
|
await queryRunner.query(`ALTER TABLE "following" ADD CONSTRAINT "FK_following_followeeHost" FOREIGN KEY ("followeeHost") REFERENCES "instance"("host") ON DELETE CASCADE ON UPDATE NO ACTION`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "following" DROP CONSTRAINT "FK_following_followeeHost"`);
|
||||||
|
await queryRunner.query(`ALTER TABLE "following" DROP CONSTRAINT "FK_following_followerHost"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typeorm';
|
import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typeorm';
|
||||||
|
import { MiInstance } from '@/models/Instance.js';
|
||||||
import { id } from './util/id.js';
|
import { id } from './util/id.js';
|
||||||
import { MiUser } from './User.js';
|
import { MiUser } from './User.js';
|
||||||
|
|
||||||
|
@ -66,6 +67,16 @@ export class MiFollowing {
|
||||||
})
|
})
|
||||||
public followerHost: string | null;
|
public followerHost: string | null;
|
||||||
|
|
||||||
|
@ManyToOne(() => MiInstance, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn({
|
||||||
|
name: 'followerHost',
|
||||||
|
foreignKeyConstraintName: 'FK_following_followerHost',
|
||||||
|
referencedColumnName: 'host',
|
||||||
|
})
|
||||||
|
public followerInstance: MiInstance | null;
|
||||||
|
|
||||||
@Column('varchar', {
|
@Column('varchar', {
|
||||||
length: 512, nullable: true,
|
length: 512, nullable: true,
|
||||||
comment: '[Denormalized]',
|
comment: '[Denormalized]',
|
||||||
|
@ -85,6 +96,16 @@ export class MiFollowing {
|
||||||
})
|
})
|
||||||
public followeeHost: string | null;
|
public followeeHost: string | null;
|
||||||
|
|
||||||
|
@ManyToOne(() => MiInstance, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn({
|
||||||
|
name: 'followeeHost',
|
||||||
|
foreignKeyConstraintName: 'FK_following_followeeHost',
|
||||||
|
referencedColumnName: 'host',
|
||||||
|
})
|
||||||
|
public followeeInstance: MiInstance | null;
|
||||||
|
|
||||||
@Column('varchar', {
|
@Column('varchar', {
|
||||||
length: 512, nullable: true,
|
length: 512, nullable: true,
|
||||||
comment: '[Denormalized]',
|
comment: '[Denormalized]',
|
||||||
|
|
Loading…
Add table
Reference in a new issue