({ runMigrations = true } = {})
| 192 | } |
| 193 | |
| 194 | async initializeDatabase({ runMigrations = true } = {}) { |
| 195 | const dbDialect = process.env.CB_DB_DIALECT_DEV || "mysql"; |
| 196 | |
| 197 | const sequelizeOptions = { |
| 198 | host: "localhost", |
| 199 | port: this.port, |
| 200 | dialect: dbDialect, |
| 201 | logging: false, |
| 202 | pool: { |
| 203 | max: 5, |
| 204 | min: 0, |
| 205 | acquire: 30000, |
| 206 | idle: 10000 |
| 207 | }, |
| 208 | }; |
| 209 | |
| 210 | if (dbDialect === "mysql") { |
| 211 | sequelizeOptions.define = { |
| 212 | charset: "utf8mb4", |
| 213 | collate: "utf8mb4_general_ci", |
| 214 | }; |
| 215 | sequelizeOptions.dialectOptions = { |
| 216 | charset: "utf8mb4", |
| 217 | }; |
| 218 | } |
| 219 | |
| 220 | this.sequelize = new Sequelize( |
| 221 | this.database, |
| 222 | this.username, |
| 223 | this.password, |
| 224 | sequelizeOptions |
| 225 | ); |
| 226 | |
| 227 | await this.authenticateWithRetry(); |
| 228 | console.log("✅ Database connection established successfully"); |
| 229 | if (runMigrations) { |
| 230 | await this.runMigrations(); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | async authenticateWithRetry(maxRetries = 5, delay = 1000) { |
| 235 | for (let attempt = 1; attempt <= maxRetries; attempt++) { |
no test coverage detected