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.
- package/dist/db.js +44 -19
- 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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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(
|
|
35
|
+
console.log(` š SSL enabled`);
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
|
-
console.log(
|
|
38
|
+
console.log(` š SSL disabled`);
|
|
37
39
|
}
|
|
38
|
-
//
|
|
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
|
-
|
|
51
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
sequelizeConfig.
|
|
57
|
-
|
|
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
|
-
|
|
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(
|
|
89
|
+
console.log(` ā
Database connected successfully!\n`);
|
|
65
90
|
return _sequelize;
|
|
66
91
|
}
|
|
67
92
|
catch (error) {
|
|
68
|
-
console.error(
|
|
93
|
+
console.error(` ā Database connection failed:`, error);
|
|
69
94
|
throw error;
|
|
70
95
|
}
|
|
71
96
|
}
|