feat: add Dockerfiles and MySQL TypeORM wiring for center/guild backends
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { buildTypeOrmConfig } from './database.config';
|
||||
import { HealthController } from './common/health.controller';
|
||||
import { GuildsModule } from './guilds/guilds.module';
|
||||
import { ChannelsModule } from './channels/channels.module';
|
||||
import { MessagingModule } from './messaging/messaging.module';
|
||||
|
||||
@Module({
|
||||
imports: [GuildsModule, ChannelsModule, MessagingModule],
|
||||
imports: [TypeOrmModule.forRoot(buildTypeOrmConfig()), GuildsModule, ChannelsModule, MessagingModule],
|
||||
controllers: [HealthController],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
16
Fabric.Backend.Guild/src/database.config.ts
Normal file
16
Fabric.Backend.Guild/src/database.config.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { Guild } from './entities/guild.entity';
|
||||
import { Channel } from './entities/channel.entity';
|
||||
import { Message } from './entities/message.entity';
|
||||
|
||||
export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||
type: 'mysql',
|
||||
host: process.env.DB_HOST ?? 'mysql-guild',
|
||||
port: Number(process.env.DB_PORT ?? 3306),
|
||||
username: process.env.DB_USER ?? 'fabric',
|
||||
password: process.env.DB_PASSWORD ?? 'fabric',
|
||||
database: process.env.DB_NAME ?? 'fabric_guild',
|
||||
entities: [Guild, Channel, Message],
|
||||
synchronize: (process.env.DB_SYNC ?? 'true') === 'true',
|
||||
logging: (process.env.DB_LOGGING ?? 'false') === 'true',
|
||||
});
|
||||
20
Fabric.Backend.Guild/src/entities/channel.entity.ts
Normal file
20
Fabric.Backend.Guild/src/entities/channel.entity.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('channels')
|
||||
export class Channel {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Column()
|
||||
guildId!: string;
|
||||
|
||||
@Column()
|
||||
name!: string;
|
||||
|
||||
@Index()
|
||||
@Column({ default: 0 })
|
||||
lastSeq!: number;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
}
|
||||
13
Fabric.Backend.Guild/src/entities/guild.entity.ts
Normal file
13
Fabric.Backend.Guild/src/entities/guild.entity.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('guilds')
|
||||
export class Guild {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Column()
|
||||
name!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
}
|
||||
21
Fabric.Backend.Guild/src/entities/message.entity.ts
Normal file
21
Fabric.Backend.Guild/src/entities/message.entity.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('messages')
|
||||
@Index(['channelId', 'seq'], { unique: true })
|
||||
export class Message {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
channelId!: string;
|
||||
|
||||
@Column()
|
||||
seq!: number;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
content!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user