vr-migrations 1.0.36 → 1.0.38

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 +44 -19
  2. package/package.json +1 -1
package/dist/db.js CHANGED
@@ -4,7 +4,7 @@ exports.Op = exports.DataTypes = exports.Model = void 0;
4
4
  exports.getSequelize = getSequelize;
5
5
  exports.initializeDatabase = initializeDatabase;
6
6
  exports.closeDatabase = closeDatabase;
7
- // vr-migrations/src/db.ts
7
+ // vr-migrations/src/db.ts - Updated to prefer individual parameters
8
8
  const sequelize_1 = require("sequelize");
9
9
  let _sequelize = null;
10
10
  let _isInitialized = false;
@@ -17,27 +17,34 @@ function getSequelize() {
17
17
  async function initializeDatabase(config) {
18
18
  if (_isInitialized)
19
19
  return _sequelize;
20
- // SSL only for prestaging, staging, and production (Neon databases)
20
+ console.log("\nšŸ” [VR-MIGRATIONS] Database initialization started...");
21
+ console.log(` NODE_ENV: ${config.NODE_ENV || "not set"}`);
22
+ console.log(` Using DATABASE_URL: ${!!config.DATABASE_URL}`);
23
+ console.log(` Using individual params: ${!!config.DB_HOST}`);
24
+ // Determine if SSL should be used
21
25
  const sslEnvironments = ["prestaging", "staging", "production"];
22
26
  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;
26
- // Configure dialect options for SSL
27
+ const enableSSL = shouldUseSSL;
28
+ // Configure SSL
27
29
  const dialectOptions = {};
28
30
  if (enableSSL) {
29
31
  dialectOptions.ssl = {
30
32
  require: true,
31
33
  rejectUnauthorized: false,
32
34
  };
33
- console.log(`šŸ”’ SSL enabled for ${config.NODE_ENV} environment`);
35
+ console.log(` šŸ”’ SSL enabled`);
34
36
  }
35
37
  else {
36
- console.log(`šŸ”“ SSL disabled for ${config.NODE_ENV} environment (local database)`);
38
+ console.log(` šŸ”“ SSL disabled`);
37
39
  }
38
- // Use DATABASE_URL if provided, otherwise use individual components
40
+ // Build Sequelize configuration - PREFER INDIVIDUAL PARAMETERS
39
41
  let sequelizeConfig = {
40
42
  dialect: "postgres",
43
+ host: config.DB_HOST,
44
+ port: config.DB_PORT,
45
+ username: config.DB_USER,
46
+ password: config.DB_PASSWORD ? String(config.DB_PASSWORD) : "",
47
+ database: config.DB_NAME,
41
48
  logging: false,
42
49
  pool: {
43
50
  max: 20,
@@ -47,25 +54,43 @@ async function initializeDatabase(config) {
47
54
  },
48
55
  dialectOptions,
49
56
  };
50
- if (config.DATABASE_URL) {
51
- sequelizeConfig.url = config.DATABASE_URL;
57
+ // Only use DATABASE_URL if individual params are missing
58
+ if (!config.DB_HOST && config.DATABASE_URL) {
59
+ console.log(` āš ļø Falling back to DATABASE_URL (individual params missing)`);
60
+ sequelizeConfig = {
61
+ dialect: "postgres",
62
+ url: config.DATABASE_URL,
63
+ logging: false,
64
+ pool: {
65
+ max: 20,
66
+ min: 2,
67
+ acquire: 120000,
68
+ idle: 10000,
69
+ },
70
+ dialectOptions,
71
+ };
72
+ }
73
+ console.log(`\n šŸ“ Connection config:`);
74
+ if (sequelizeConfig.url) {
75
+ const maskedUrl = sequelizeConfig.url.replace(/\/\/[^:]+:[^@]+@/, "//***:***@");
76
+ console.log(` URL: ${maskedUrl}`);
52
77
  }
53
78
  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;
79
+ console.log(` Host: ${sequelizeConfig.host}:${sequelizeConfig.port}`);
80
+ console.log(` User: ${sequelizeConfig.username}`);
81
+ console.log(` Password: ${sequelizeConfig.password ? "***" : "(empty)"}`);
82
+ console.log(` Database: ${sequelizeConfig.database}`);
59
83
  }
60
- _sequelize = new sequelize_1.Sequelize(sequelizeConfig);
84
+ console.log(`\n šŸš€ Attempting database connection...`);
61
85
  try {
86
+ _sequelize = new sequelize_1.Sequelize(sequelizeConfig);
62
87
  await _sequelize.authenticate();
63
88
  _isInitialized = true;
64
- console.log(`āœ… Database connected successfully (SSL: ${enableSSL ? "ON" : "OFF"})`);
89
+ console.log(` āœ… Database connected successfully!\n`);
65
90
  return _sequelize;
66
91
  }
67
92
  catch (error) {
68
- console.error("āŒ Database authentication failed:", error);
93
+ console.error(` āŒ Database connection failed:`, error);
69
94
  throw error;
70
95
  }
71
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-migrations",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "description": "Database migration and seeding package for VR applications",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",