feat: add Dockerfiles and MySQL TypeORM wiring for center/guild backends
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { buildTypeOrmConfig } from './database.config';
|
||||
import { HealthController } from './common/health.controller';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { NodesModule } from './nodes/nodes.module';
|
||||
|
||||
@Module({
|
||||
imports: [AuthModule, NodesModule],
|
||||
imports: [TypeOrmModule.forRoot(buildTypeOrmConfig()), AuthModule, NodesModule],
|
||||
controllers: [HealthController],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
15
Fabric.Backend.Center/src/database.config.ts
Normal file
15
Fabric.Backend.Center/src/database.config.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { GuildNode } from './entities/guild-node.entity';
|
||||
|
||||
export const buildTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||
type: 'mysql',
|
||||
host: process.env.DB_HOST ?? 'mysql-center',
|
||||
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_center',
|
||||
entities: [User, GuildNode],
|
||||
synchronize: (process.env.DB_SYNC ?? 'true') === 'true',
|
||||
logging: (process.env.DB_LOGGING ?? 'false') === 'true',
|
||||
});
|
||||
22
Fabric.Backend.Center/src/entities/guild-node.entity.ts
Normal file
22
Fabric.Backend.Center/src/entities/guild-node.entity.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('guild_nodes')
|
||||
export class GuildNode {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Column({ unique: true })
|
||||
nodeId!: string;
|
||||
|
||||
@Column()
|
||||
name!: string;
|
||||
|
||||
@Column()
|
||||
endpoint!: string;
|
||||
|
||||
@Column({ default: 'active' })
|
||||
status!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
}
|
||||
16
Fabric.Backend.Center/src/entities/user.entity.ts
Normal file
16
Fabric.Backend.Center/src/entities/user.entity.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('users')
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Column({ unique: true })
|
||||
email!: string;
|
||||
|
||||
@Column()
|
||||
passwordHash!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user