Skip to content

Commit

Permalink
Revert "BHBC-1188: Timezone bug fix (#435)"
Browse files Browse the repository at this point in the history
This reverts commit a284eee.
  • Loading branch information
anissa-agahchen authored Aug 4, 2021
1 parent a284eee commit a5f8d19
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 53 deletions.
4 changes: 0 additions & 4 deletions .config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
"prod": "prod"
},
"version": "1.0.0",
"timezone": {
"db": "America/Vancouver",
"api": "America/Vancouver"
},
"module": {
"db": "biohubbc-db",
"api": "biohubbc-api",
Expand Down
4 changes: 0 additions & 4 deletions api/.pipeline/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const phases = {
version: `${version}-${changeId}`,
tag: tag,
env: 'build',
tz: config.timezone.api,
branch: branch,
logLevel: 'debug'
},
Expand All @@ -76,7 +75,6 @@ const phases = {
(isStaticDeployment && (staticUrlsAPI.dev || defaultHost)) ||
`${name}-${changeId}-af2668-dev.apps.silver.devops.gov.bc.ca`,
env: 'dev',
tz: config.timezone.api,
certificateURL: config.certificateURL.dev,
replicas: 1,
maxReplicas: 2,
Expand All @@ -94,7 +92,6 @@ const phases = {
tag: `test-${version}`,
host: staticUrlsAPI.test,
env: 'test',
tz: config.timezone.api,
certificateURL: config.certificateURL.test,
replicas: 3,
maxReplicas: 5,
Expand All @@ -112,7 +109,6 @@ const phases = {
tag: `prod-${version}`,
host: staticUrlsAPI.prod,
env: 'prod',
tz: config.timezone.api,
certificateURL: config.certificateURL.prod,
replicas: 3,
maxReplicas: 6,
Expand Down
1 change: 0 additions & 1 deletion api/.pipeline/lib/api.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = (settings) => {
HOST: phases[phase].host,
CHANGE_ID: phases.build.changeId || changeId,
NODE_ENV: phases[phase].env || 'dev',
TZ: phases[phase].tz,
DB_SERVICE_NAME: `${phases[phase].dbName}-postgresql${phases[phase].suffix}`,
CERTIFICATE_URL: phases[phase].certificateURL,
REPLICAS: phases[phase].replicas || 1,
Expand Down
6 changes: 0 additions & 6 deletions api/openshift/api.dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ parameters:
description: Application Environment type variable
required: true
value: 'dev'
- name: TZ
description: Application timezone
required: false
value: 'America/Vancouver'
- name: CERTIFICATE_URL
description: Authentication certificate urls
required: true
Expand Down Expand Up @@ -139,8 +135,6 @@ objects:
value: ${CHANGE_ID}
- name: NODE_ENV
value: ${NODE_ENV}
- name: TZ
value: ${TZ}
- name: VERSION
value: ${VERSION}
- name: OBJECT_STORE_URL
Expand Down
23 changes: 7 additions & 16 deletions api/src/database/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as pg from 'pg';
import { Pool, PoolClient, PoolConfig, QueryResult } from 'pg';
import { HTTP400, HTTP500 } from '../errors/CustomError';
import { setSystemUserContextSQL } from '../queries/user-context-queries';
import { getUserIdentifier, getUserIdentitySource } from '../utils/keycloak-utils';
Expand All @@ -16,7 +16,7 @@ const DB_POOL_SIZE: number = Number(process.env.DB_POOL_SIZE) || 20;
const DB_CONNECTION_TIMEOUT: number = Number(process.env.DB_CONNECTION_TIMEOUT) || 0;
const DB_IDLE_TIMEOUT: number = Number(process.env.DB_IDLE_TIMEOUT) || 10000;

const poolConfig: pg.PoolConfig = {
const poolConfig: PoolConfig = {
user: DB_USERNAME,
password: DB_PASSWORD,
database: DB_DATABASE,
Expand All @@ -29,19 +29,10 @@ const poolConfig: pg.PoolConfig = {

defaultLog.debug({ label: 'create db pool', message: 'pool config', poolConfig });

// Custom type handler for psq `DATE` type to prevent local time/zone information from being added.
// Why? By default, node-postgres assumes local time/zone for any psql `DATE` or `TIME` types that don't have timezone information.
// This Can lead to unexpected behaviour when the original psql `DATE` value was intentionally omitting time/zone information.
// PSQL date types: https://www.postgresql.org/docs/12/datatype-datetime.html
// node-postgres type handling (see bottom of page): https://node-postgres.com/features/types
pg.types.setTypeParser(pg.types.builtins.DATE, (stringValue: string) => {
return stringValue; // 1082 for `DATE` type
});

let pool: pg.Pool;
let pool: Pool;

try {
pool = new pg.Pool(poolConfig);
pool = new Pool(poolConfig);
} catch (error) {
defaultLog.error({ label: 'create db pool', message: 'failed to create pool', error, poolConfig });
process.exit(1);
Expand Down Expand Up @@ -88,7 +79,7 @@ export interface IDBConnection {
* @throws If the connection is not open.
* @memberof IDBConnection
*/
query: (text: string, values?: any[]) => Promise<pg.QueryResult<any> | void>;
query: (text: string, values?: any[]) => Promise<QueryResult<any> | void>;
/**
* Get the ID of the system user in context.
*
Expand Down Expand Up @@ -120,7 +111,7 @@ export interface IDBConnection {
* @return {*} {IDBConnection}
*/
export const getDBConnection = function (keycloakToken: object): IDBConnection {
let _client: pg.PoolClient;
let _client: PoolClient;

let _isOpen = false;
let _isReleased = false;
Expand Down Expand Up @@ -198,7 +189,7 @@ export const getDBConnection = function (keycloakToken: object): IDBConnection {
* @param {any[]} [values] SQL values array (optional)
* @return {*} {(Promise<QueryResult<any> | void>)}
*/
const _query = async (text: string, values?: any[]): Promise<pg.QueryResult<any> | void> => {
const _query = async (text: string, values?: any[]): Promise<QueryResult<any> | void> => {
if (!_client || !_isOpen) {
throw Error('DBConnection is not open');
}
Expand Down
3 changes: 1 addition & 2 deletions api/src/paths/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ function getVersionInformation(): RequestHandler {
return (req, res) => {
const versionInfo = {
version: process.env.VERSION,
environment: process.env.NODE_ENV,
timezone: process.env.TZ
environment: process.env.NODE_ENV
};

res.status(200).json(versionInfo);
Expand Down
6 changes: 2 additions & 4 deletions database/.docker/db/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
FROM postgres:12.5

# read env variables
ARG TZ=America/Vancouver

# set env variables
# set variables
ENV POSTGISV 3
ENV TZ America/Vancouver
ENV PORT 5432

# install postgis packages
Expand Down
4 changes: 0 additions & 4 deletions database/.pipeline/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const phases = {
version: `${version}-${changeId}`,
tag: tag,
env: 'build',
tz: config.timezone.db,
branch: branch,
dbSetupDockerfilePath: dbSetupDockerfilePath
},
Expand All @@ -72,7 +71,6 @@ const phases = {
version: `${deployChangeId}-${changeId}`,
tag: `dev-${version}-${deployChangeId}`,
env: 'dev',
tz: config.timezone.db,
dbSetupDockerfilePath: dbSetupDockerfilePath
},
test: {
Expand All @@ -85,7 +83,6 @@ const phases = {
version: `${version}`,
tag: `test-${version}`,
env: 'test',
tz: config.timezone.db,
dbSetupDockerfilePath: dbSetupDockerfilePath
},
prod: {
Expand All @@ -98,7 +95,6 @@ const phases = {
version: `${version}`,
tag: `prod-${version}`,
env: 'prod',
tz: config.timezone.db,
dbSetupDockerfilePath: dbSetupDockerfilePath
}
};
Expand Down
1 change: 0 additions & 1 deletion database/.pipeline/lib/db.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = (settings) => {
IMAGE_STREAM_NAME: name,
IMAGE_STREAM_VERSION: phases.build.tag,
POSTGRESQL_DATABASE: 'biohubbc',
TZ: phases[phase].tz,
IMAGE_STREAM_NAMESPACE: phases.build.namespace,
VOLUME_CAPACITY:
`${name}-postgresql${phases[phase].suffix}` === `${name}-postgresql-dev-deploy` ? '20Gi' : '3Gi'
Expand Down
6 changes: 0 additions & 6 deletions database/openshift/db.dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ parameters:
name: POSTGRESQL_DATABASE
required: true
value: 'biohubbc'
- name: TZ
description: Database timezone
required: false
value: 'America/Vancouver'
- description: Volume space available for data, e.g. 512Mi, 2Gi.
displayName: Volume Capacity
name: VOLUME_CAPACITY
Expand Down Expand Up @@ -186,8 +182,6 @@ objects:
value: 'N'
- name: PGOPTIONS
value: '-c maintenance_work_mem=128MB'
- name: PGTZ
value: '${TZ}'
image: ' '
imagePullPolicy: IfNotPresent
livenessProbe:
Expand Down
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ services:
build:
context: ./database/.docker/db
dockerfile: Dockerfile
args:
- TZ=${DB_TZ}
ports:
- ${DB_PORT}:${DB_PORT}
healthcheck:
Expand Down Expand Up @@ -39,7 +37,6 @@ services:
- ${API_PORT}:${API_PORT}
environment:
- NODE_ENV=${NODE_ENV}
- TZ=${API_TZ}
- API_HOST=${API_HOST}
- API_PORT=${API_PORT}
- DB_HOST=${DB_HOST}
Expand Down
2 changes: 0 additions & 2 deletions env_config/env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ SITEMINDER_LOGOUT_URL=https://logontest.gov.bc.ca/clp-cgi/logoff.cgi
# ------------------------------------------------------------------------------
API_HOST=localhost
API_PORT=6100
API_TZ=America/Vancouver

# See `api/utils/logger.ts` for details on LOG_LEVEL
LOG_LEVEL=debug
Expand All @@ -32,7 +31,6 @@ DB_PORT=5432
DB_DATABASE=biohubbc
DB_SCHEMA=biohub
DB_SCHEMA_DAPI_V1=biohub_dapi_v1
DB_TZ=America/Vancouver

# ------------------------------------------------------------------------------
# KeyClock URLS
Expand Down

0 comments on commit a5f8d19

Please sign in to comment.