Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import config from 'building-blocks/config/config';
- import { DataSource, DataSourceOptions } from 'typeorm';
- import { createDatabase } from 'typeorm-extension';
- // use this file for running migration
- export const postgresOptions: DataSourceOptions = {
- type: 'postgres',
- host: config.postgres.host,
- port: config.postgres.port,
- username: config.postgres.username,
- password: config.postgres.password,
- database: config.postgres.database,
- synchronize: config.postgres.synchronize,
- entities: [__dirname + config.postgres.entities],
- migrations: [__dirname + config.postgres.migrations],
- logging: config.postgres.logging
- };
- async function initializeDatabase() {
- try {
- await createDatabase({ options: postgresOptions, ifNotExist: true });
- const dataSource = new DataSource(postgresOptions);
- await dataSource.initialize();
- console.log('Database has been initialized!');
- } catch (error) {
- console.error('Error during Database initialization', error);
- }
- }
- export default initializeDatabase;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement