mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: Remove unused PostgresConfig file and update PostgresDatabase imports
This commit is contained in:
42
CommonServer/Infrastructure/Postgres/DataSourceOptions.ts
Normal file
42
CommonServer/Infrastructure/Postgres/DataSourceOptions.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import DatabaseType from 'Common/Types/DatabaseType';
|
||||
import {
|
||||
DatabaseHost,
|
||||
DatabaseName,
|
||||
DatabasePassword,
|
||||
DatabasePort,
|
||||
DatabaseRejectUnauthorized,
|
||||
DatabaseSslCa,
|
||||
DatabaseSslCert,
|
||||
DatabaseSslKey,
|
||||
DatabaseUsername,
|
||||
ShouldDatabaseSslEnable,
|
||||
} from '../../EnvironmentConfig';
|
||||
import { DataSourceOptions } from 'typeorm';
|
||||
import Migrations from './SchemaMigrations/Index';
|
||||
import Entities from 'Model/Models/Index';
|
||||
|
||||
const dataSourceOptions: DataSourceOptions = {
|
||||
type: DatabaseType.Postgres,
|
||||
host: DatabaseHost.toString(),
|
||||
port: DatabasePort.toNumber(),
|
||||
username: DatabaseUsername,
|
||||
password: DatabasePassword,
|
||||
database: DatabaseName,
|
||||
migrationsTableName: 'migrations',
|
||||
migrations: Migrations,
|
||||
migrationsRun: true,
|
||||
entities: Entities,
|
||||
applicationName: 'oneuptime',
|
||||
ssl: ShouldDatabaseSslEnable
|
||||
? {
|
||||
rejectUnauthorized: DatabaseRejectUnauthorized,
|
||||
ca: DatabaseSslCa,
|
||||
key: DatabaseSslKey,
|
||||
cert: DatabaseSslCert,
|
||||
}
|
||||
: false,
|
||||
// logging: 'all',
|
||||
synchronize: false,
|
||||
};
|
||||
|
||||
export default dataSourceOptions;
|
||||
@@ -0,0 +1,15 @@
|
||||
import { DataSource } from "typeorm";
|
||||
import dataSourceOptions from "./DataSourceOptions";
|
||||
|
||||
const dataSourceOptionToMigrate: any = {
|
||||
...dataSourceOptions,
|
||||
host: 'localhost',
|
||||
database: 'oneuptimeabc',
|
||||
port: 5400
|
||||
}
|
||||
|
||||
const PostgresDataSource: DataSource = new DataSource(
|
||||
dataSourceOptionToMigrate
|
||||
);
|
||||
|
||||
export default PostgresDataSource;
|
||||
@@ -0,0 +1,5 @@
|
||||
import InitialMigration from "./InitialMigration";
|
||||
|
||||
export default [
|
||||
InitialMigration
|
||||
];
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
import DatabaseType from "Common/Types/DatabaseType";
|
||||
import { DatabaseName } from "../../EnvironmentConfig";
|
||||
import Faker from "Common/Utils/Faker";
|
||||
import { DataSourceOptions } from "typeorm";
|
||||
import Entities from 'Model/Models/Index';
|
||||
|
||||
type GetTestDataSourceOptions = () => DataSourceOptions;
|
||||
|
||||
const getTestDataSourceOptions: GetTestDataSourceOptions =
|
||||
(): DataSourceOptions => {
|
||||
// we use process.env values directly here because it can change during test runs and we need to get the latest values.
|
||||
return {
|
||||
type: DatabaseType.Postgres,
|
||||
host: process.env['DATABASE_HOST'] || 'localhost',
|
||||
port: parseInt(process.env['DATABASE_PORT']?.toString() || '5432'),
|
||||
username: process.env['DATABASE_USERNAME'] || 'postgres',
|
||||
password: process.env['DATABASE_PASSWORD'] || 'password',
|
||||
database: DatabaseName + Faker.randomNumbers(16),
|
||||
entities: Entities,
|
||||
synchronize: true
|
||||
};
|
||||
};
|
||||
|
||||
export default getTestDataSourceOptions;
|
||||
@@ -1,64 +0,0 @@
|
||||
import {
|
||||
DatabaseHost,
|
||||
DatabaseName,
|
||||
DatabasePassword,
|
||||
DatabasePort,
|
||||
DatabaseRejectUnauthorized,
|
||||
DatabaseSslCa,
|
||||
DatabaseSslCert,
|
||||
DatabaseSslKey,
|
||||
DatabaseUsername,
|
||||
Env,
|
||||
ShouldDatabaseSslEnable,
|
||||
} from '../EnvironmentConfig';
|
||||
import AppEnvironment from 'Common/Types/AppEnvironment';
|
||||
import DatabaseType from 'Common/Types/DatabaseType';
|
||||
import Faker from 'Common/Utils/Faker';
|
||||
import Migrations from 'Model/Migrations/Index';
|
||||
import Entities from 'Model/Models/Index';
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
|
||||
export const dataSourceOptions: DataSourceOptions = {
|
||||
type: DatabaseType.Postgres,
|
||||
host: DatabaseHost.toString(),
|
||||
port: DatabasePort.toNumber(),
|
||||
username: DatabaseUsername,
|
||||
password: DatabasePassword,
|
||||
database: DatabaseName,
|
||||
migrationsTableName: 'migrations',
|
||||
migrations: Migrations,
|
||||
entities: Entities,
|
||||
applicationName: 'oneuptime',
|
||||
ssl: ShouldDatabaseSslEnable
|
||||
? {
|
||||
rejectUnauthorized: DatabaseRejectUnauthorized,
|
||||
ca: DatabaseSslCa,
|
||||
key: DatabaseSslKey,
|
||||
cert: DatabaseSslCert,
|
||||
}
|
||||
: false,
|
||||
// logging: 'all',
|
||||
// synchronize: Env === AppEnvironment.Development,
|
||||
synchronize: true,
|
||||
};
|
||||
|
||||
export const datasource: DataSource = new DataSource(dataSourceOptions);
|
||||
|
||||
type GetTestDataSourceOptions = () => DataSourceOptions;
|
||||
|
||||
export const getTestDataSourceOptions: GetTestDataSourceOptions =
|
||||
(): DataSourceOptions => {
|
||||
// we use process.env values directly here because it can change during test runs and we need to get the latest values.
|
||||
return {
|
||||
type: DatabaseType.Postgres,
|
||||
host: process.env['DATABASE_HOST'] || 'localhost',
|
||||
port: parseInt(process.env['DATABASE_PORT']?.toString() || '5432'),
|
||||
username: process.env['DATABASE_USERNAME'] || 'postgres',
|
||||
password: process.env['DATABASE_PASSWORD'] || 'password',
|
||||
database: DatabaseName + Faker.randomNumbers(16),
|
||||
entities: Entities,
|
||||
synchronize:
|
||||
Env === AppEnvironment.Test ||
|
||||
Env === AppEnvironment.Development,
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
import logger from '../Utils/Logger';
|
||||
import { dataSourceOptions, getTestDataSourceOptions } from './PostgresConfig';
|
||||
import dataSourceOptions from './Postgres/DataSourceOptions';
|
||||
import Sleep from 'Common/Types/Sleep';
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
import getTestDataSourceOptions from './Postgres/TestDataSourceOptions';
|
||||
|
||||
export default class Database {
|
||||
private dataSource!: DataSource | null;
|
||||
|
||||
@@ -50,6 +50,18 @@ helm repo add oneuptime https://helm-chart.oneuptime.com/
|
||||
helm install my-oneuptime oneuptime/oneuptime -f values.yaml
|
||||
```
|
||||
|
||||
|
||||
## Upgrade Helm Chart
|
||||
|
||||
```console
|
||||
|
||||
# Update the chart repo
|
||||
helm repo update
|
||||
|
||||
# Upgrade the helm chart
|
||||
helm upgrade my-oneuptime oneuptime/oneuptime -f values.yaml
|
||||
```
|
||||
|
||||
## Uninstall Helm Chart
|
||||
|
||||
```console
|
||||
|
||||
@@ -274,7 +274,7 @@ externalPostgres:
|
||||
host:
|
||||
port:
|
||||
username:
|
||||
password:
|
||||
password:
|
||||
database:
|
||||
ssl:
|
||||
enabled: false
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export default [];
|
||||
@@ -71,7 +71,8 @@
|
||||
"run-probes": "export $(grep -v '^#' config.env | xargs) && docker compose up --remove-orphans -d probe-1 probe-2",
|
||||
"deploy-test": "kubectl config use-context oneuptime-test && helm upgrade oneuptime ./HelmChart/Public/oneuptime -f ./HelmChart/Public/oneuptime/values.yaml -f ./HelmChart/Values/test.values.yaml",
|
||||
"template-deploy-test": "kubectl config use-context oneuptime-test && helm template oneuptime ./HelmChart/Public/oneuptime -f ./HelmChart/Public/oneuptime/values.yaml -f ./HelmChart/Values/test.values.yaml --debug",
|
||||
"deploy-prod": "kubectl config use-context oneuptime-prod && helm upgrade oneuptime ./HelmChart/Public/oneuptime -f ./HelmChart/Public/oneuptime/values.yaml -f ./HelmChart/Values/prod.values.yaml"
|
||||
"deploy-prod": "kubectl config use-context oneuptime-prod && helm upgrade oneuptime ./HelmChart/Public/oneuptime -f ./HelmChart/Public/oneuptime/values.yaml -f ./HelmChart/Values/prod.values.yaml",
|
||||
"generate-postgres-migration": "export $(grep -v '^#' config.env | xargs) && node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate ./CommonServer/Infrastructure/Postgres/Migrations/. -d ./CommonServer/Infrastructure/Postgres/LocalMigrationGenerationDataSource.ts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user