Skip to content

Commit

Permalink
refactor(database): remove migrations execution in constructor function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicotsx committed Dec 7, 2024
1 parent c01e219 commit f25d525
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/backend/src/core/database/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class DatabaseService {
private logger: LoggerService,
) {
const { username, port, database, host, password } = this.configurationService.get('database');
const { appDir } = this.configurationService.get('directories');
const connectionString = `postgresql://${username}:${password}@${host}:${port}/${database}?connect_timeout=300`;

const pool = new Pool({
Expand All @@ -36,15 +35,21 @@ export class DatabaseService {
});

this.db = drizzle(pool, { schema });
}

migrate(this.db, { migrationsFolder: path.join(appDir, 'assets', 'migrations') });
private getMigrationsPath(): string {
const { appDir } = this.configurationService.get('directories');
return path.join(appDir, 'assets', 'migrations');
}

migrate = async () => {
try {
await migrate(this.db, { migrationsFolder: path.join(this.configurationService.get('directories').appDir, 'assets', 'migrations') });
this.logger.debug('Starting database migration...');
await migrate(this.db, { migrationsFolder: this.getMigrationsPath() });
this.logger.debug('Database migration complete.');
} catch (error) {
this.logger.error('Error migrating database:', error);
throw error;
}
};
}

0 comments on commit f25d525

Please sign in to comment.