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.
- package/dist/db.js +34 -84
- 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
|
|
23
|
-
console.log(`
|
|
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
|
|
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
|
-
//
|
|
54
|
-
if (config.DATABASE_URL) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
sequelizeConfig.
|
|
92
|
-
|
|
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
|
}
|