vr-migrations 1.0.37 → 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 +34 -84
  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;
@@ -19,13 +19,12 @@ async function initializeDatabase(config) {
19
19
  return _sequelize;
20
20
  console.log("\nšŸ” [VR-MIGRATIONS] Database initialization started...");
21
21
  console.log(` NODE_ENV: ${config.NODE_ENV || "not set"}`);
22
- console.log(` DATABASE_URL provided: ${!!config.DATABASE_URL}`);
23
- console.log(` Individual params provided: ${!!config.DB_HOST}`);
22
+ console.log(` Using DATABASE_URL: ${!!config.DATABASE_URL}`);
23
+ console.log(` Using individual params: ${!!config.DB_HOST}`);
24
24
  // Determine if SSL should be used
25
25
  const sslEnvironments = ["prestaging", "staging", "production"];
26
26
  const shouldUseSSL = sslEnvironments.includes(config.NODE_ENV || "");
27
- const hasSSLParam = config.DATABASE_URL?.includes("sslmode=require") || false;
28
- const enableSSL = shouldUseSSL || hasSSLParam;
27
+ const enableSSL = shouldUseSSL;
29
28
  // Configure SSL
30
29
  const dialectOptions = {};
31
30
  if (enableSSL) {
@@ -38,9 +37,14 @@ async function initializeDatabase(config) {
38
37
  else {
39
38
  console.log(` šŸ”“ SSL disabled`);
40
39
  }
41
- // Build Sequelize configuration
40
+ // Build Sequelize configuration - PREFER INDIVIDUAL PARAMETERS
42
41
  let sequelizeConfig = {
43
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,
44
48
  logging: false,
45
49
  pool: {
46
50
  max: 20,
@@ -50,58 +54,33 @@ async function initializeDatabase(config) {
50
54
  },
51
55
  dialectOptions,
52
56
  };
53
- // Prefer DATABASE_URL over individual parameters
54
- if (config.DATABASE_URL) {
55
- // Ensure the URL has a valid password
56
- let url = config.DATABASE_URL;
57
- // Debug: Parse URL to check password
58
- try {
59
- const parsedUrl = new URL(url);
60
- console.log(` šŸ“ Parsed URL:`);
61
- console.log(` - Host: ${parsedUrl.hostname}`);
62
- console.log(` - Port: ${parsedUrl.port || "5432"}`);
63
- console.log(` - Username: ${parsedUrl.username}`);
64
- console.log(` - Password: ${parsedUrl.password ? "***" : "MISSING!"}`);
65
- console.log(` - Database: ${parsedUrl.pathname.slice(1)}`);
66
- // CRITICAL FIX: Ensure password is properly encoded in URL
67
- if (parsedUrl.password &&
68
- parsedUrl.password !== decodeURIComponent(parsedUrl.password)) {
69
- // Password has special characters, reconstruct URL with encoded password
70
- const encodedPassword = encodeURIComponent(parsedUrl.password);
71
- url = url.replace(parsedUrl.password, encodedPassword);
72
- console.log(` šŸ”§ Re-encoded password in URL`);
73
- }
74
- // CRITICAL FIX: If password is missing but we have individual password, add it
75
- if (!parsedUrl.password && config.DB_PASSWORD) {
76
- // Reconstruct URL with password
77
- const encodedPassword = encodeURIComponent(config.DB_PASSWORD);
78
- url = `postgresql://${parsedUrl.username}:${encodedPassword}@${parsedUrl.hostname}:${parsedUrl.port || "5432"}${parsedUrl.pathname}${parsedUrl.search}`;
79
- console.log(` šŸ”§ Added missing password to URL`);
80
- }
81
- }
82
- catch (error) {
83
- console.error(` āŒ Failed to parse DATABASE_URL:`, error);
84
- }
85
- sequelizeConfig.url = url;
86
- console.log(` āœ… Using DATABASE_URL connection`);
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}`);
87
77
  }
88
78
  else {
89
- // Use individual parameters
90
- sequelizeConfig.host = config.DB_HOST;
91
- sequelizeConfig.port = config.DB_PORT;
92
- sequelizeConfig.username = config.DB_USER;
93
- // CRITICAL FIX: Ensure password is a string
94
- sequelizeConfig.password = config.DB_PASSWORD
95
- ? String(config.DB_PASSWORD)
96
- : "";
97
- sequelizeConfig.database = config.DB_NAME;
98
- console.log(` āœ… Using individual connection parameters`);
99
- console.log(` - Host: ${sequelizeConfig.host}:${sequelizeConfig.port}`);
100
- console.log(` - User: ${sequelizeConfig.username}`);
101
- console.log(` - Password: ${sequelizeConfig.password ? "***" : "(empty)"}`);
102
- console.log(` - Database: ${sequelizeConfig.database}`);
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}`);
103
83
  }
104
- // Final debug before connection
105
84
  console.log(`\n šŸš€ Attempting database connection...`);
106
85
  try {
107
86
  _sequelize = new sequelize_1.Sequelize(sequelizeConfig);
@@ -112,35 +91,6 @@ async function initializeDatabase(config) {
112
91
  }
113
92
  catch (error) {
114
93
  console.error(` āŒ Database connection failed:`, error);
115
- // Helpful error messages
116
- if (error instanceof Error) {
117
- if (error.message.includes("password must be a string")) {
118
- console.error(`
119
- āš ļø PASSWORD ISSUE DETECTED!
120
-
121
- The password is not being passed correctly to the database.
122
-
123
- Possible solutions:
124
- 1. Check your .env file for special characters in passwords (@, #, $, etc.)
125
- 2. URL-encode special characters: @ -> %40, # -> %23, $ -> %24
126
- 3. Ensure DATABASE_URL format: postgresql://user:password@host:port/db
127
- 4. Try using individual DB_* variables instead of DATABASE_URL
128
-
129
- Current config:
130
- - Using DATABASE_URL: ${!!config.DATABASE_URL}
131
- - DB_PASSWORD provided: ${!!config.DB_PASSWORD}
132
- `);
133
- }
134
- else if (error.message.includes("does not support SSL")) {
135
- console.error(`
136
- āš ļø SSL ERROR DETECTED!
137
-
138
- You're trying to connect with SSL to a database that doesn't support it.
139
-
140
- Solution: Set NODE_ENV=development for local development
141
- `);
142
- }
143
- }
144
94
  throw error;
145
95
  }
146
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-migrations",
3
- "version": "1.0.37",
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",