Skip to content

Commit

Permalink
add minimal repro
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-deeporigin committed May 8, 2024
1 parent fe8233c commit 9d7f075
Show file tree
Hide file tree
Showing 8 changed files with 1,050 additions and 287 deletions.
5 changes: 5 additions & 0 deletions apps/test-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POSTGRES_DATABASE=local
POSTGRES_HOST=localhost
POSTGRES_PORT=55432
POSTGRES_USER=local
POSTGRES_PASSWORD=local
9 changes: 9 additions & 0 deletions apps/test-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
"buildTarget": "test-app:build:production"
}
}
},
"migration-create": {
"executor": "nx:run-commands",
"options": {
"cwd": "apps/test-app",
"commands": [
"mikro-orm migration:create --initial --config ./src/mikro-orm.config.ts"
]
}
}
}
}
4 changes: 3 additions & 1 deletion apps/test-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import config from '../mikro-orm.config';
import { MikroOrmModule } from '@mikro-orm/nestjs';

@Module({
imports: [],
imports: [MikroOrmModule.forRoot(config)],
controllers: [AppController],
providers: [AppService],
})
Expand Down
52 changes: 52 additions & 0 deletions apps/test-app/src/app/my-model.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
Collection,
Entity,
Enum,
ManyToMany,
Property,
} from '@mikro-orm/core';

export enum RoleName {
Owner = 'Owner',
Admin = 'Admin',
BillingManager = 'BillingManager',
InfrastructureManager = 'InfrastructureManager',
Member = 'Member',
}
export enum PermissionAction {
CREATE = 'create',
READ = 'read',
UPDATE = 'update',
DELETE = 'delete',
}

export enum PermissableSubject {
USER = 'Users',
}

export interface PermissionCondition {
[key: string]: string | number | PermissionCondition;
}

@Entity({ tableName: 'permissions' })
export class PermissionModel {
@Enum(() => PermissionAction)
action!: PermissionAction;

@Enum(() => PermissableSubject)
subject!: PermissableSubject;

@Property({ type: 'json', nullable: false, default: '{}' })
condition!: PermissionCondition;
}

@Entity({ tableName: 'roles' })
export class RoleModel {
@Enum(() => RoleName)
name!: RoleName;

@ManyToMany(() => PermissionModel)
permissions: Collection<PermissionModel> = new Collection<PermissionModel>(
this
);
}
16 changes: 16 additions & 0 deletions apps/test-app/src/mikro-orm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from '@mikro-orm/postgresql';

export default defineConfig({
dbName: process.env.POSTGRES_DATABASE,
host: process.env['POSTGRES_HOST'],
port: Number(process.env['POSTGRES_PORT'] || '23455'),
user: process.env['POSTGRES_USER'],
password: process.env['POSTGRES_PASSWORD'],
entities: ['dist/src/**/*.entity.js'],
entitiesTs: ['src/**/*.entity.ts'],
migrations: {
path: 'dist/migrations',
pathTs: 'src/migrations',
},
debug: true,
});
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '2'
services:
postgres:
image: postgres:15.5
environment:
POSTGRES_USER: local
POSTGRES_PASSWORD: local
POSTGRES_DB: local
ports:
- 23455:5432
Loading

0 comments on commit 9d7f075

Please sign in to comment.