Skip to content

Commit

Permalink
Auto apply migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed Mar 2, 2024
1 parent 8b0f9a7 commit edeb971
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,12 @@ import { LanguageModule } from './languages/language.module';
import { SharedModule } from './shared/shared.module';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { entitySchemas } from './shared/_dependencyInjection/entitySchemas';
import { dataSourceConfig } from './shared/infrastructure/persistence/typeOrm/dataSource';

@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
TypeOrmModule.forRoot({
type: 'postgres',
url: process.env.POSTGRESQL_DB_URL,
synchronize: false,
logging: true,
entities: entitySchemas,
subscribers: [],
migrationsRun: true,
autoLoadEntities: false,
logger: 'advanced-console',
migrations: [`${__dirname}../migrations/**/*{.ts,.js}`],
poolSize: 10,
}),
TypeOrmModule.forRoot(dataSourceConfig),
SharedModule,
LanguageModule,
],
Expand Down
19 changes: 19 additions & 0 deletions src/shared/infrastructure/persistence/typeOrm/dataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { entitySchemas } from '@src/shared/_dependencyInjection/entitySchemas';
import { DataSource, DataSourceOptions } from 'typeorm';

export const dataSourceConfig: DataSourceOptions = {
type: 'postgres',
url: process.env.POSTGRESQL_DB_URL,
synchronize: false,
logging: true,
entities: entitySchemas,
subscribers: [],
migrationsRun: true,
logger: 'advanced-console',
migrations: [`${__dirname}../../../../../languages/app/migrations/**/*{.ts,.js}`],
poolSize: 10,
};

const dataSource = new DataSource(dataSourceConfig);

export default dataSource;

0 comments on commit edeb971

Please sign in to comment.