Skip to content

Commit

Permalink
feat: add auto-run migrations config to typeorm
Browse files Browse the repository at this point in the history
  • Loading branch information
meysamhadeli committed Dec 14, 2023
1 parent 580c0c4 commit 3df7eab
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/booking/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ POSTGRES_Database=booking
POSTGRES_SYNCHRONIZE =false
POSTGRES_ENTITIES=/../**/*.entity.{js,ts}
POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts}
POSTGRES_MIGRATIONS_RUN=true

# Rabbitmq
RABBITMQ_Host=localhost
Expand Down
1 change: 1 addition & 0 deletions src/booking/src/data/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const postgresOptions: DataSourceOptions = {
entities: [__dirname + configs.postgres.entities],
migrations: [__dirname + configs.postgres.migrations],
logging: configs.postgres.logging,
migrationsRun: configs.postgres.migrationsRun
};

const dataSource = new DataSource(postgresOptions);
Expand Down
1 change: 1 addition & 0 deletions src/building-blocks/configs/configs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ declare const _default: {
entities: any;
migrations: any;
logging: any;
migrationsRun: any;
};
jwt: {
secret: any;
Expand Down
4 changes: 4 additions & 0 deletions src/building-blocks/configs/configs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/building-blocks/configs/configs.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/building-blocks/configs/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ const envVarsSchema = Joi.object()
POSTGRES_LOGGING: Joi.boolean()
.default(false)
.description('Postgres logging'),
RABBITMQ_Host: Joi.string()
POSTGRES_MIGRATIONS_RUN: Joi.boolean()
.default(false)
.description('Run migrations after running project'),
RABBITMQ_Host: Joi.string()
.default('localhost')
.description('Rabbitmq host'),
RABBITMQ_PORT: Joi.number().default(5672).description('Rabbitmq port'),
Expand Down Expand Up @@ -109,6 +112,7 @@ export default {
entities: envVars.POSTGRES_ENTITIES,
migrations: envVars.POSTGRES_MIGRATIONS,
logging: envVars.POSTGRES_LOGGING,
migrationsRun: envVars.POSTGRES_MIGRATIONS_RUN
},
jwt: {
secret: envVars.JWT_SECRET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface PostgresContainerOptions {
password: string;
synchronize: boolean;
entities: MixedList<Function | string | EntitySchema>;
migrationsRun: boolean;
}
export declare class PostgresContainer {
start(): Promise<[StartedTestContainer, DataSourceOptions]>;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface PostgresContainerOptions {
password: string;
synchronize: boolean;
entities: MixedList<Function | string | EntitySchema>;
migrationsRun: boolean;
}

export class PostgresContainer{
Expand Down Expand Up @@ -55,6 +56,7 @@ export class PostgresContainer{
password: 'testcontainers',
imageName: 'postgres:latest',
synchronize: true,
migrationsRun: false,
entities: ['src/**/entities/*.{js,ts}']
};

Expand Down
2 changes: 1 addition & 1 deletion src/building-blocks/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/flight/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ POSTGRES_Database=flight
POSTGRES_SYNCHRONIZE =false
POSTGRES_ENTITIES=/../**/*.entity.{js,ts}
POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts}
POSTGRES_MIGRATIONS_RUN=true

# Rabbitmq
RABBITMQ_Host=localhost
Expand Down
3 changes: 2 additions & 1 deletion src/flight/src/data/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const postgresOptions: DataSourceOptions = {
synchronize: configs.postgres.synchronize,
entities: [__dirname + configs.postgres.entities],
migrations: [__dirname + configs.postgres.migrations],
logging: configs.postgres.logging
logging: configs.postgres.logging,
migrationsRun: configs.postgres.migrationsRun
};

const dataSource = new DataSource(postgresOptions);
Expand Down
1 change: 1 addition & 0 deletions src/identity/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ POSTGRES_Database=identity
POSTGRES_SYNCHRONIZE =false
POSTGRES_ENTITIES=/../**/*.entity.{js,ts}
POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts}
POSTGRES_MIGRATIONS_RUN=true

# Rabbitmq
RABBITMQ_Host=localhost
Expand Down
1 change: 1 addition & 0 deletions src/identity/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_Database=identity_test
POSTGRES_SYNCHRONIZE =true
POSTGRES_MIGRATIONS_RUN=false

# Rabbitmq
RABBITMQ_Host=localhost
Expand Down
3 changes: 2 additions & 1 deletion src/identity/src/data/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const postgresOptions: DataSourceOptions = {
synchronize: configs.postgres.synchronize,
entities: [__dirname + configs.postgres.entities],
migrations: [__dirname + configs.postgres.migrations],
logging: configs.postgres.logging
logging: configs.postgres.logging,
migrationsRun: configs.postgres.migrationsRun
};

const dataSource = new DataSource(postgresOptions);
Expand Down
1 change: 1 addition & 0 deletions src/passenger/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ POSTGRES_Database=passenger
POSTGRES_SYNCHRONIZE =false
POSTGRES_ENTITIES=/../**/*.entity.{js,ts}
POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts}
POSTGRES_MIGRATIONS_RUN=true

# Rabbitmq
RABBITMQ_Host=localhost
Expand Down
1 change: 1 addition & 0 deletions src/passenger/src/data/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const postgresOptions: DataSourceOptions = {
entities: [__dirname + configs.postgres.entities],
migrations: [__dirname + configs.postgres.migrations],
logging: configs.postgres.logging,
migrationsRun: configs.postgres.migrationsRun
};

const dataSource = new DataSource(postgresOptions);
Expand Down

0 comments on commit 3df7eab

Please sign in to comment.