combine sequelize config with constructor

This commit is contained in:
Tyler Shipe 2021-12-07 13:33:19 -05:00
parent 8078185936
commit bb566da3f5
4 changed files with 44 additions and 60 deletions

View File

@ -1,37 +0,0 @@
require('dotenv').config();
module.exports = {
development: {
use_env_variable: 'TIMESCALEDB_URL',
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
},
test: {
use_env_variable: 'TIMESCALEDB_URL',
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
},
production: {
use_env_variable: 'TIMESCALEDB_URL',
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
},
};

View File

@ -1,10 +1,30 @@
"use strict"
const Sequelize = require("sequelize")
const env = process.env.NODE_ENV || "development"
const config = require(__dirname + "/../config/config.js")[env]
const db = {}
const sequelize = new Sequelize(process.env[config.use_env_variable], config)
require("dotenv").config()
const Sequelize = require("sequelize")
const db = {}
var parse = require("pg-connection-string")
var readDBConfig = parse(process.env.TIMESCALEDB_URL_READ)
var writeDBConfig = parse(process.env.TIMESCALEDB_URL)
const sequelize = new Sequelize({
username: writeDBConfig.user,
password: writeDBConfig.password,
database: writeDBConfig.database,
port: parseInt(writeDBConfig.port),
replication: {
read: [{ host: readDBConfig.host }],
write: { host: writeDBConfig.host },
},
dialect: "postgres",
logging: false,
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
})
sequelize
.authenticate()

View File

@ -36,7 +36,7 @@
"node-cron": "^2.0.3",
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"sequelize": "^6.5.0",
"sequelize": "^6.11.0",
"ts-node": "^9.1.1"
}
}

View File

@ -1646,10 +1646,10 @@ indent-string@^2.1.0:
dependencies:
repeating "^2.0.0"
inflection@1.12.0:
version "1.12.0"
resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.12.0.tgz#a200935656d6f5f6bc4dc7502e1aecb703228416"
integrity sha1-ogCTVlbW9fa8TcdQLhrstwMihBY=
inflection@1.13.1:
version "1.13.1"
resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.13.1.tgz#c5cadd80888a90cf84c2e96e340d7edc85d5f0cb"
integrity sha512-dldYtl2WlN0QDkIDtg8+xFwOS2Tbmp12t1cHa5/YClU6ZQjTFm7B66UcVbh9NQB+HvT5BAd2t5+yKsBkw5pcqA==
inflight@^1.0.4:
version "1.0.6"
@ -2023,9 +2023,9 @@ mkdirp@^1.0.4:
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
moment-timezone@^0.5.31:
version "0.5.33"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.33.tgz#b252fd6bb57f341c9b59a5ab61a8e51a73bbd22c"
integrity sha512-PTc2vcT8K9J5/9rDEPe5czSIKgLoGsH8UNpA4qZTVw0Vd/Uz19geE9abbIOQKaAQFcnQ3v5YEXrbSc5BpshH+w==
version "0.5.34"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.34.tgz#a75938f7476b88f155d3504a9343f7519d9a405c"
integrity sha512-3zAEHh2hKUs3EXLESx/wsgw6IQdusOT8Bxm3D9UrHPQR7zlMmzwybC8zHEM1tQ4LJwP7fcxrWr8tuBg05fFCbg==
dependencies:
moment ">= 2.9.0"
@ -2630,23 +2630,24 @@ sequelize-pool@^6.0.0:
resolved "https://registry.yarnpkg.com/sequelize-pool/-/sequelize-pool-6.1.0.tgz#caaa0c1e324d3c2c3a399fed2c7998970925d668"
integrity sha512-4YwEw3ZgK/tY/so+GfnSgXkdwIJJ1I32uZJztIEgZeAO6HMgj64OzySbWLgxj+tXhZCJnzRfkY9gINw8Ft8ZMg==
sequelize@^6.5.0:
version "6.5.0"
resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-6.5.0.tgz#c968a03f6fbbcda40717f73edb39fadf27b85e96"
integrity sha512-owBt8fnzVy8E1OvyCyfCdVk7OOLyPVrBCMEf+CvRReC5oCyo+UqeXCtwaex9L6LM9ifZ1i3TG3sFeM5MgLK0CQ==
sequelize@^6.11.0:
version "6.11.0"
resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-6.11.0.tgz#11620b02ab2ca02af59ec652dd22bef7ccd348af"
integrity sha512-+j3N5lr+FR1eicMRGR3bRsGOl9HMY0UGb2PyB2i1yZ64XBgsz3xejMH0UD45LcUitj40soDGIa9CyvZG0dfzKg==
dependencies:
debug "^4.1.1"
dottie "^2.0.0"
inflection "1.12.0"
inflection "1.13.1"
lodash "^4.17.20"
moment "^2.26.0"
moment-timezone "^0.5.31"
pg-connection-string "^2.5.0"
retry-as-promised "^3.2.0"
semver "^7.3.2"
sequelize-pool "^6.0.0"
toposort-class "^1.0.1"
uuid "^8.1.0"
validator "^10.11.0"
validator "^13.7.0"
wkx "^0.5.0"
serve-static@1.14.1:
@ -3101,10 +3102,10 @@ validate-npm-package-license@^3.0.1:
spdx-correct "^3.0.0"
spdx-expression-parse "^3.0.0"
validator@^10.11.0:
version "10.11.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-10.11.0.tgz#003108ea6e9a9874d31ccc9e5006856ccd76b228"
integrity sha512-X/p3UZerAIsbBfN/IwahhYaBbY68EN/UQBWHtsbXGT5bfrH/p4NQzUCG1kF/rtKaNpnJ7jAu6NGTdSNtyNIXMw==
validator@^13.7.0:
version "13.7.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-13.7.0.tgz#4f9658ba13ba8f3d82ee881d3516489ea85c0857"
integrity sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==
vary@^1, vary@~1.1.2:
version "1.1.2"