vr-migrations 1.0.29 → 1.0.31

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.d.ts CHANGED
@@ -1,12 +1,22 @@
1
1
  import { Sequelize } from "sequelize";
2
- export declare function getSequelize(): Sequelize;
3
- export declare function initializeDatabase(config: {
4
- DB_HOST: string;
5
- DB_PORT: number;
6
- DB_USER: string;
7
- DB_PASSWORD: string;
8
- DB_NAME: string;
2
+ export interface DatabaseConfig {
3
+ DB_HOST?: string;
4
+ DB_PORT?: number;
5
+ DB_USER?: string;
6
+ DB_PASSWORD?: string;
7
+ DB_NAME?: string;
8
+ DATABASE_URL?: string;
9
9
  NODE_ENV?: string;
10
- }): Promise<Sequelize>;
10
+ pool?: {
11
+ max?: number;
12
+ min?: number;
13
+ acquire?: number;
14
+ idle?: number;
15
+ };
16
+ logging?: boolean | ((sql: string, timing?: number) => void);
17
+ dialectOptions?: any;
18
+ }
19
+ export declare function getSequelize(): Sequelize;
20
+ export declare function initializeDatabase(config: DatabaseConfig): Promise<Sequelize>;
11
21
  export declare function closeDatabase(): Promise<void>;
12
22
  export { Model, InferAttributes, InferCreationAttributes, DataTypes, CreationOptional, ModelStatic, ModelAttributes, NonAttribute, Op, } from "sequelize";
package/dist/db.js CHANGED
@@ -4,6 +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
+ // Updated vr-migrations/index.ts
7
8
  const sequelize_1 = require("sequelize");
8
9
  let _sequelize = null;
9
10
  let _isInitialized = false;
@@ -16,29 +17,67 @@ function getSequelize() {
16
17
  async function initializeDatabase(config) {
17
18
  if (_isInitialized)
18
19
  return _sequelize;
19
- _sequelize = new sequelize_1.Sequelize({
20
- dialect: "postgres",
21
- host: config.DB_HOST,
22
- port: config.DB_PORT,
23
- username: config.DB_USER,
24
- password: config.DB_PASSWORD,
25
- database: config.DB_NAME,
26
- logging: false,
27
- pool: {
28
- max: 20,
29
- min: 2,
30
- acquire: 120000,
31
- idle: 10000,
32
- },
33
- dialectOptions: config.NODE_ENV === "production"
34
- ? {
35
- ssl: { require: true, rejectUnauthorized: false },
36
- }
37
- : {},
38
- });
39
- await _sequelize.authenticate();
40
- _isInitialized = true;
41
- return _sequelize;
20
+ const isProduction = config.NODE_ENV === "production";
21
+ const isStaging = config.NODE_ENV === "staging";
22
+ // Determine if we should use SSL (Neon requires SSL)
23
+ const shouldUseSSL = isProduction || isStaging || config.DATABASE_URL?.includes("neon.tech");
24
+ // Default pool configuration
25
+ const poolConfig = config.pool || {
26
+ max: 20,
27
+ min: 2,
28
+ acquire: 120000,
29
+ idle: 10000,
30
+ };
31
+ // Default dialect options
32
+ let dialectOptions = config.dialectOptions || {};
33
+ // Add SSL for production/staging/Neon
34
+ if (shouldUseSSL) {
35
+ dialectOptions = {
36
+ ...dialectOptions,
37
+ ssl: {
38
+ require: true,
39
+ rejectUnauthorized: false, // Required for Neon
40
+ },
41
+ };
42
+ }
43
+ // Option 1: Use DATABASE_URL if provided
44
+ if (config.DATABASE_URL) {
45
+ console.log(`📊 Initializing database with connection URL for ${config.NODE_ENV || "default"} environment`);
46
+ _sequelize = new sequelize_1.Sequelize(config.DATABASE_URL, {
47
+ dialect: "postgres",
48
+ logging: config.logging !== undefined ? config.logging : false,
49
+ pool: poolConfig,
50
+ dialectOptions,
51
+ });
52
+ }
53
+ // Option 2: Use individual connection parameters
54
+ else if (config.DB_HOST && config.DB_USER && config.DB_NAME) {
55
+ console.log(`📊 Initializing database with connection parameters for ${config.NODE_ENV || "default"} environment`);
56
+ _sequelize = new sequelize_1.Sequelize({
57
+ dialect: "postgres",
58
+ host: config.DB_HOST,
59
+ port: config.DB_PORT || 5432,
60
+ username: config.DB_USER,
61
+ password: config.DB_PASSWORD,
62
+ database: config.DB_NAME,
63
+ logging: config.logging !== undefined ? config.logging : false,
64
+ pool: poolConfig,
65
+ dialectOptions,
66
+ });
67
+ }
68
+ else {
69
+ throw new Error("Invalid database configuration. Provide either DATABASE_URL or (DB_HOST, DB_USER, DB_NAME)");
70
+ }
71
+ try {
72
+ await _sequelize.authenticate();
73
+ console.log(`✅ Database connection established successfully`);
74
+ _isInitialized = true;
75
+ return _sequelize;
76
+ }
77
+ catch (error) {
78
+ console.error("❌ Database connection failed:", error);
79
+ throw error;
80
+ }
42
81
  }
43
82
  async function closeDatabase() {
44
83
  if (_sequelize) {
@@ -18,7 +18,7 @@ module.exports = {
18
18
  key: "id",
19
19
  },
20
20
  onUpdate: "CASCADE",
21
- onDelete: "CASCADE",
21
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
22
22
  },
23
23
  name: {
24
24
  type: Sequelize.STRING(100),
@@ -23,7 +23,7 @@ module.exports = {
23
23
  key: "id",
24
24
  },
25
25
  onUpdate: "CASCADE",
26
- onDelete: "CASCADE",
26
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
27
27
  },
28
28
  installmentNumber: {
29
29
  type: Sequelize.INTEGER,
@@ -24,7 +24,7 @@ module.exports = {
24
24
  key: "id",
25
25
  },
26
26
  onUpdate: "CASCADE",
27
- onDelete: "CASCADE",
27
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
28
28
  },
29
29
  adminId: {
30
30
  type: Sequelize.UUID,
@@ -34,7 +34,7 @@ module.exports = {
34
34
  key: "id",
35
35
  },
36
36
  onUpdate: "CASCADE",
37
- onDelete: "CASCADE",
37
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
38
38
  },
39
39
  reason: {
40
40
  type: Sequelize.TEXT,
@@ -24,7 +24,7 @@ module.exports = {
24
24
  key: "id",
25
25
  },
26
26
  onUpdate: "CASCADE",
27
- onDelete: "CASCADE",
27
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
28
28
  },
29
29
  adminId: {
30
30
  type: Sequelize.UUID,
@@ -34,7 +34,7 @@ module.exports = {
34
34
  key: "id",
35
35
  },
36
36
  onUpdate: "CASCADE",
37
- onDelete: "CASCADE",
37
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
38
38
  },
39
39
  reason: {
40
40
  type: Sequelize.TEXT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-migrations",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Database migration and seeding package for VR applications",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",