Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection probleme #14

Open
gondfreecs opened this issue Jun 27, 2021 · 1 comment
Open

Connection probleme #14

gondfreecs opened this issue Jun 27, 2021 · 1 comment

Comments

@gondfreecs
Copy link

How did u connect back end to the database ?

image

i got this probleme

@wesleyfeitosa
Copy link
Owner

wesleyfeitosa commented Jun 27, 2021

@gondfreecs You have to adjust the "entities" and "migrations" attributes in your ormconfig.js for Typeorm to correctly read your entities and migations in your project's src folder.

Here is an example of ormconfig.js configured with different runtime environments.

const devConfig =  [
  {
    name: 'default',
    type: 'postgres',
    host: process.env.DATABASE_HOST,
    port: process.env.DATABASE_PORT,
    username: process.env.DATABASE_USER,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME,
    entities: [
      './src/modules/**/infra/typeorm/entities/*.ts'
    ],
    migrations: [
      './src/shared/infra/typeorm/migrations/*.ts'
    ],
    cli: {
      migrationsDir: './src/shared/infra/typeorm/migrations'
    }
  }
]

const prodConfig =  [
  {
    name: 'default',
    type: 'postgres',
    host: process.env.DATABASE_HOST,
    port: process.env.DATABASE_PORT,
    username: process.env.DATABASE_USER,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME,
    entities: [
      './dist/modules/**/infra/typeorm/entities/*.js'
    ],
    migrations: [
      './dist/shared/infra/typeorm/migrations/*.js'
    ],
    cli: {
      migrationsDir: './dist/shared/infra/typeorm/migrations'
    }
  }
]

const homoConfig =  [
  {
    name: 'default',
    type: 'postgres',
    host: process.env.DATABASE_HOST,
    port: process.env.DATABASE_PORT,
    username: process.env.DATABASE_USER,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME,
    ssl: true,
    extra: {
      ssl: {
        rejectUnauthorized: false,
      },
    },
    entities: [
      './dist/modules/**/infra/typeorm/entities/*.js'
    ],
    migrations: [
      './dist/shared/infra/typeorm/migrations/*.js'
    ],
    cli: {
      migrationsDir: './dist/shared/infra/typeorm/migrations'
    }
  }
]

let config;

if(process.env.NODE_ENV === 'production') {
  if (process.env.DATABASE_SSL === 'true') {
    console.log('Usando database de: HOMOLOGAÇÃO');
    config = homoConfig;
  } else {
    console.log('Usando database de: PRODUÇÃO');
    config = prodConfig;
  }
} else {
  console.log('Usando database de: DESENVOLVIMENTO');
  config = devConfig;
}

module.exports = config;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants