vr-migrations 1.0.35 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/db.js +26 -17
  2. package/package.json +1 -1
package/dist/db.js CHANGED
@@ -17,30 +17,27 @@ function getSequelize() {
17
17
  async function initializeDatabase(config) {
18
18
  if (_isInitialized)
19
19
  return _sequelize;
20
- // Detect if we need SSL (Neon or production/staging)
21
- const isNeon = config.DATABASE_URL?.includes("neon.tech") ||
22
- config.DB_HOST?.includes("neon.tech");
23
- const isProduction = config.NODE_ENV === "production" ||
24
- config.NODE_ENV === "staging" ||
25
- config.NODE_ENV === "dev";
26
- const shouldUseSSL = isNeon || isProduction;
20
+ // SSL only for prestaging, staging, and production (Neon databases)
21
+ const sslEnvironments = ["prestaging", "staging", "production"];
22
+ const shouldUseSSL = sslEnvironments.includes(config.NODE_ENV || "");
23
+ // Also check if DATABASE_URL explicitly contains sslmode=require
24
+ const hasSSLParam = config.DATABASE_URL?.includes("sslmode=require") || false;
25
+ const enableSSL = shouldUseSSL || hasSSLParam;
27
26
  // Configure dialect options for SSL
28
27
  const dialectOptions = {};
29
- if (shouldUseSSL) {
28
+ if (enableSSL) {
30
29
  dialectOptions.ssl = {
31
30
  require: true,
32
31
  rejectUnauthorized: false,
33
32
  };
34
- console.log("🔒 SSL enabled for database connection");
35
- console.log("connecting to DATABASE_URL:", process.env.DATABASE_URL);
33
+ console.log(`🔒 SSL enabled for ${config.NODE_ENV} environment`);
36
34
  }
37
- _sequelize = new sequelize_1.Sequelize({
35
+ else {
36
+ console.log(`🔓 SSL disabled for ${config.NODE_ENV} environment (local database)`);
37
+ }
38
+ // Use DATABASE_URL if provided, otherwise use individual components
39
+ let sequelizeConfig = {
38
40
  dialect: "postgres",
39
- host: config.DB_HOST,
40
- port: config.DB_PORT,
41
- username: config.DB_USER,
42
- password: config.DB_PASSWORD,
43
- database: config.DB_NAME,
44
41
  logging: false,
45
42
  pool: {
46
43
  max: 20,
@@ -49,10 +46,22 @@ async function initializeDatabase(config) {
49
46
  idle: 10000,
50
47
  },
51
48
  dialectOptions,
52
- });
49
+ };
50
+ if (config.DATABASE_URL) {
51
+ sequelizeConfig.url = config.DATABASE_URL;
52
+ }
53
+ else {
54
+ sequelizeConfig.host = config.DB_HOST;
55
+ sequelizeConfig.port = config.DB_PORT;
56
+ sequelizeConfig.username = config.DB_USER;
57
+ sequelizeConfig.password = config.DB_PASSWORD;
58
+ sequelizeConfig.database = config.DB_NAME;
59
+ }
60
+ _sequelize = new sequelize_1.Sequelize(sequelizeConfig);
53
61
  try {
54
62
  await _sequelize.authenticate();
55
63
  _isInitialized = true;
64
+ console.log(`✅ Database connected successfully (SSL: ${enableSSL ? "ON" : "OFF"})`);
56
65
  return _sequelize;
57
66
  }
58
67
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-migrations",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "description": "Database migration and seeding package for VR applications",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",