-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the use of SSL connections to the postgres database. (#1256)
* Allow the use of SSL connections to the postgres database. * Add default SSL false when no env set * Add commented out example of DB_SSL env * Refactor add SSL option into PostgresConnectionOptions * Refactor the database connection to optionally use a URL string instead of the env variables * Refactor the database connection based on feedback * Add dynamic validation around the DB envs * Remove DB_URL from example * Fix rebase * Add back the optional database port in the example * Formatted file correctly * change types to a const to fix tests
- Loading branch information
Showing
2 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions'; | ||
import { DataSource } from 'typeorm'; | ||
|
||
export const databaseConfig: PostgresConnectionOptions = { | ||
const baseDatabaseConfig: PostgresConnectionOptions = { | ||
type: 'postgres', | ||
host: process.env.DB_HOSTNAME || 'immich_postgres', | ||
port: parseInt(process.env.DB_PORT || '5432'), | ||
username: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_DATABASE_NAME, | ||
entities: [__dirname + '/../**/*.entity.{js,ts}'], | ||
synchronize: false, | ||
migrations: [__dirname + '/../migrations/*.{js,ts}'], | ||
migrationsRun: true, | ||
connectTimeoutMS: 10000, // 10 seconds | ||
}; | ||
|
||
const envBasedDatabaseConfig = { | ||
host: process.env.DB_HOSTNAME || 'immich_postgres', | ||
port: parseInt(process.env.DB_PORT || '5432'), | ||
username: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_DATABASE_NAME, | ||
}; | ||
|
||
const url = process.env.DB_URL; | ||
const additionalSSLDatabaseConfig = url ? { url } : envBasedDatabaseConfig; | ||
|
||
export const databaseConfig: PostgresConnectionOptions = { ...baseDatabaseConfig, ...additionalSSLDatabaseConfig }; | ||
|
||
export const dataSource = new DataSource(databaseConfig); |
5340683
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
immich – ./docs
immich-immich.vercel.app
immich.app
immich-git-main-immich.vercel.app
immich.vercel.app
www.immich.app
documentation.immich.app
docs.immich.app
5340683
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
immich-code-coverage – ./server
immich-code-coverage-git-main-immich.vercel.app
server.code.immich.app
immich-code-coverage.vercel.app
immich-code-coverage-immich.vercel.app