Skip to content

Commit

Permalink
Crunchy DB Implementation (#93)
Browse files Browse the repository at this point in the history
Signed-off-by: Sukanya Rath
  • Loading branch information
sukanya-rath authored Dec 12, 2023
1 parent 9acf395 commit 8ee6832
Show file tree
Hide file tree
Showing 16 changed files with 425 additions and 340 deletions.
9 changes: 6 additions & 3 deletions backend/src/v1/prisma/prisma-client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import {logger} from "../../logger";

let prisma: PrismaClient;
import {PrismaClient} from '@prisma/client';

const DB_HOST = process.env.POSTGRESQL_HOST || 'localhost';
const DB_USER = process.env.POSTGRESQL_USER || 'postgres';
const DB_PWD = process.env.POSTGRESQL_PASSWORD || 'postgres';
const DB_PWD = encodeURIComponent(process.env.POSTGRESQL_PASSWORD || 'postgres');
const DB_PORT = process.env.POSTGRESQL_PORT || 5432;
const DB_NAME = process.env.POSTGRESQL_DATABASE || 'postgres';
const DB_SCHEMA = process.env.DB_SCHEMA || 'pay_transparency';
if (!prisma) {
const datasourceUrl = `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5`;
logger.silly(`Connecting to ${datasourceUrl}`);
prisma = new PrismaClient({
log: ['query', 'info', "error", "warn"],
errorFormat: 'pretty',
datasourceUrl: `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5`

datasourceUrl: datasourceUrl
});
}

Expand Down
7 changes: 4 additions & 3 deletions charts/fin-pay-transparency/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ dependencies:
- name: database
condition: database.enabled
version: 0.1.0
- name: backup
condition: backup.enabled
version: 0.1.0
- name: crunchy-postgres
condition: crunchy.enabled
version: 0.5.1
alias: crunchy
keywords:
- fin-pay-transparency
- fin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,28 @@ spec:
- secretRef:
name: {{.Release.Name}}
env:
{{- if .Values.global.crunchyEnabled }}
#-- "crunchy" as a name is always added to the paths for secrets and pods , because the alias used in chart.yaml is crunchy, refer line #40 in Chart.yaml
- name: FLYWAY_URL
value: "jdbc:postgresql://{{.Release.Name}}-crunchy-primary.{{.Release.Namespace}}.svc:5432/{{ .Values.global.secrets.databaseName}}"
- name: FLYWAY_USER
value: {{ .Values.global.secrets.databaseUser }}
- name: FLYWAY_PASSWORD
valueFrom:
secretKeyRef:
name: {{.Release.Name}}-crunchy-pguser-{{ .Values.global.secrets.databaseUser }}
key: password
{{- else }}
- name: FLYWAY_URL
value: "jdbc:postgresql://{{.Release.Name}}-database:5432/{{ .Values.global.secrets.databaseName}}"
{{- end }}

- name: FLYWAY_BASELINE_ON_MIGRATE
value: "true"
- name: FLYWAY_DEFAULT_SCHEMA
value: "pay_transparency"
- name: FLYWAY_CONNECT_RETRIES
value: "10"
containers:
- name: {{ include "backend.fullname" . }}
securityContext:
Expand All @@ -57,6 +73,33 @@ spec:
- configMapRef:
name: {{.Release.Name}}
env:
{{- if .Values.global.crunchyEnabled }}
#-- "crunchy" as a name is always added to the paths for secrets and pods , because the alias used in chart.yaml is crunchy, refer line #40 in Chart.yaml
- name: POSTGRESQL_HOST
valueFrom:
secretKeyRef:
name: {{.Release.Name}}-crunchy-pguser-{{ .Values.global.secrets.databaseName }}
key: host
- name: POSTGRESQL_USER
valueFrom:
secretKeyRef:
name: {{.Release.Name}}-crunchy-pguser-{{ .Values.global.secrets.databaseName }}
key: user
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{.Release.Name}}-crunchy-pguser-{{ .Values.global.secrets.databaseName }}
key: password
- name: POSTGRESQL_DATABASE
valueFrom:
secretKeyRef:
name: {{.Release.Name}}-crunchy-pguser-{{ .Values.global.secrets.databaseName }}
key: dbname
{{- else }}
#-- here all the secrets are auto-mounted from the global secrets, when crunchy is not enabled. refer secret.yaml line#14.
- name: POSTGRESQL_HOST
value: {{.Release.Name}}-database
{{- end }}
- name: NODE_ENV
value: production
{{- if .Values.global.serverFrontend }}
Expand All @@ -76,8 +119,7 @@ spec:
value: {{ .Values.app.env.siteminderLogoutEndpoint }}
- name: SESSION_PATH
value: '/app/sessions'
- name: POSTGRESQL_HOST
value: {{.Release.Name}}-database

ports:
- name: http
containerPort: {{ .Values.service.targetPort }}
Expand Down
23 changes: 0 additions & 23 deletions charts/fin-pay-transparency/charts/backup/.helmignore

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions charts/fin-pay-transparency/charts/backup/templates/is.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions charts/fin-pay-transparency/charts/backup/templates/pvc.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
name: backup
name: crunchy-postgres
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
Expand All @@ -15,10 +15,12 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.5.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

# Crunchy Postgres Operator version
appVersion: "5.0.4"
Loading

0 comments on commit 8ee6832

Please sign in to comment.