vr-migrations 1.0.34 → 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.
- package/dist/db.js +26 -17
- package/dist/migrations/004-create-pricing.js +10 -0
- 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
|
-
//
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 (
|
|
28
|
+
if (enableSSL) {
|
|
30
29
|
dialectOptions.ssl = {
|
|
31
30
|
require: true,
|
|
32
31
|
rejectUnauthorized: false,
|
|
33
32
|
};
|
|
34
|
-
console.log(
|
|
35
|
-
console.log("connecting to DATABASE_URL:", process.env.DATABASE_URL);
|
|
33
|
+
console.log(`🔒 SSL enabled for ${config.NODE_ENV} environment`);
|
|
36
34
|
}
|
|
37
|
-
|
|
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) {
|
|
@@ -28,6 +28,16 @@ module.exports = {
|
|
|
28
28
|
type: Sequelize.ENUM("HIRE_PURCHASE", "FULL_PAYMENT"),
|
|
29
29
|
allowNull: false,
|
|
30
30
|
},
|
|
31
|
+
minOrderQuantity: {
|
|
32
|
+
type: Sequelize.INTEGER,
|
|
33
|
+
allowNull: false,
|
|
34
|
+
defaultValue: 1,
|
|
35
|
+
},
|
|
36
|
+
maxOrderQuantity: {
|
|
37
|
+
type: Sequelize.INTEGER,
|
|
38
|
+
allowNull: false,
|
|
39
|
+
defaultValue: 1,
|
|
40
|
+
},
|
|
31
41
|
totalAmount: {
|
|
32
42
|
type: Sequelize.DECIMAL(10, 2),
|
|
33
43
|
allowNull: true,
|