feat(guild-model): complete guild/channel/dm entities
This commit is contained in:
@@ -2,6 +2,8 @@ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|||||||
import { Guild } from './entities/guild.entity';
|
import { Guild } from './entities/guild.entity';
|
||||||
import { Channel } from './entities/channel.entity';
|
import { Channel } from './entities/channel.entity';
|
||||||
import { Message } from './entities/message.entity';
|
import { Message } from './entities/message.entity';
|
||||||
|
import { DmConversation } from './entities/dm-conversation.entity';
|
||||||
|
import { DmParticipant } from './entities/dm-participant.entity';
|
||||||
|
|
||||||
export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||||
type: 'mysql',
|
type: 'mysql',
|
||||||
@@ -10,7 +12,7 @@ export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
|||||||
username: process.env.DB_USER ?? 'fabric',
|
username: process.env.DB_USER ?? 'fabric',
|
||||||
password: process.env.DB_PASSWORD ?? 'fabric',
|
password: process.env.DB_PASSWORD ?? 'fabric',
|
||||||
database: process.env.DB_NAME ?? 'fabric_guild',
|
database: process.env.DB_NAME ?? 'fabric_guild',
|
||||||
entities: [Guild, Channel, Message],
|
entities: [Guild, Channel, Message, DmConversation, DmParticipant],
|
||||||
synchronize: (process.env.DB_SYNC ?? 'true') === 'true',
|
synchronize: (process.env.DB_SYNC ?? 'true') === 'true',
|
||||||
logging: (process.env.DB_LOGGING ?? 'false') === 'true',
|
logging: (process.env.DB_LOGGING ?? 'false') === 'true',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,12 +5,18 @@ export class Channel {
|
|||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'char', length: 36 })
|
||||||
guildId!: string;
|
guildId!: string;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 120 })
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 16, default: 'text' })
|
||||||
|
kind!: 'text' | 'announcement';
|
||||||
|
|
||||||
|
@Column({ type: 'boolean', default: false })
|
||||||
|
isPrivate!: boolean;
|
||||||
|
|
||||||
@Index()
|
@Index()
|
||||||
@Column({ default: 0 })
|
@Column({ default: 0 })
|
||||||
lastSeq!: number;
|
lastSeq!: number;
|
||||||
|
|||||||
16
Fabric.Backend.Guild/src/entities/dm-conversation.entity.ts
Normal file
16
Fabric.Backend.Guild/src/entities/dm-conversation.entity.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('dm_conversations')
|
||||||
|
export class DmConversation {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 64, unique: true })
|
||||||
|
pairKey!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 255, nullable: true })
|
||||||
|
topic!: string | null;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt!: Date;
|
||||||
|
}
|
||||||
19
Fabric.Backend.Guild/src/entities/dm-participant.entity.ts
Normal file
19
Fabric.Backend.Guild/src/entities/dm-participant.entity.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
|
@Entity('dm_participants')
|
||||||
|
export class DmParticipant {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'char', length: 36 })
|
||||||
|
conversationId!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 64 })
|
||||||
|
userId!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 16, default: 'member' })
|
||||||
|
role!: 'member';
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt!: Date;
|
||||||
|
}
|
||||||
@@ -5,9 +5,15 @@ export class Guild {
|
|||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 120 })
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 120, unique: true })
|
||||||
|
slug!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 64, nullable: true })
|
||||||
|
ownerUserId!: string | null;
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,21 @@ import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from
|
|||||||
|
|
||||||
@Entity('messages')
|
@Entity('messages')
|
||||||
@Index(['channelId', 'seq'], { unique: true })
|
@Index(['channelId', 'seq'], { unique: true })
|
||||||
|
@Index(['conversationId', 'seq'], { unique: true })
|
||||||
export class Message {
|
export class Message {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@Index()
|
@Index()
|
||||||
@Column()
|
@Column({ type: 'char', length: 36, nullable: true })
|
||||||
channelId!: string;
|
channelId!: string | null;
|
||||||
|
|
||||||
|
@Index()
|
||||||
|
@Column({ type: 'char', length: 36, nullable: true })
|
||||||
|
conversationId!: string | null;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 64 })
|
||||||
|
authorUserId!: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
seq!: number;
|
seq!: number;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
## 2. Fabric.Backend.Guild(Guild Node)
|
## 2. Fabric.Backend.Guild(Guild Node)
|
||||||
|
|
||||||
### 2.1 领域模型
|
### 2.1 领域模型
|
||||||
- [ ] Guild/Channel/DM 实体补全
|
- [x] Guild/Channel/DM 实体补全
|
||||||
- [ ] Member/Role 基础模型(即使 MVP 权限全开,也先留结构)
|
- [ ] Member/Role 基础模型(即使 MVP 权限全开,也先留结构)
|
||||||
- [ ] 索引设计(channel_id + seq, created_at 等)
|
- [ ] 索引设计(channel_id + seq, created_at 等)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user