import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn, } from 'typeorm'; import TgBot from './TgBot'; import TgGroup from './TgGroup'; @Index('idx_bot', [ 'botId' ], {}) @Index('idx_group', [ 'groupId' ], {}) @Index('uk_group_bot', [ 'groupId', 'botId' ], { unique: true }) @Entity('tg_group_bot', { schema: 'tgbot' }) export default class TgGroupBot { @PrimaryGeneratedColumn({ type: 'int', name: 'id' }) id: number; @Column('bigint', { name: 'groupId', comment: '群组ID' }) groupId: number; @Column('bigint', { name: 'botId', comment: '机器人ID' }) botId: number; @Column('datetime', { name: 'createTime', comment: '创建时间', default: () => 'CURRENT_TIMESTAMP', }) createTime: Date; @Column('datetime', { name: 'updateTime', comment: '更新时间', default: () => 'CURRENT_TIMESTAMP', }) updateTime: Date; @ManyToOne(() => TgBot, tgBot => tgBot.tgGroupBots, { onDelete: 'CASCADE', onUpdate: 'NO ACTION', }) @JoinColumn([{ name: 'botId', referencedColumnName: 'botId' }]) bot: TgBot; @ManyToOne(() => TgGroup, tgGroup => tgGroup.tgGroupBots, { onDelete: 'CASCADE', onUpdate: 'NO ACTION', }) @JoinColumn([{ name: 'groupId', referencedColumnName: 'groupId' }]) group: TgGroup; }