|
24 | 24 | - [Max connections](#max-connections)
|
25 | 25 | - [Performance optimization (MongoDB + Mongoose)](#performance-optimization-mongodb--mongoose)
|
26 | 26 | - [Design schema](#design-schema)
|
| 27 | +- [Switch PostgreSQL to MySQL](#switch-postgresql-to-mysql) |
27 | 28 |
|
28 | 29 | ---
|
29 | 30 |
|
@@ -291,6 +292,108 @@ Designing schema for MongoDB is completely different from designing schema for r
|
291 | 292 | 1. [MongoDB Schema Design Anti-Patterns](https://www.mongodb.com/developer/products/mongodb/schema-design-anti-pattern-massive-arrays)
|
292 | 293 | 1. [MongoDB Schema Design Best Practices](https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/)
|
293 | 294 |
|
| 295 | +## Switch PostgreSQL to MySQL |
| 296 | +
|
| 297 | +If you want to use MySQL instead of `PostgreSQL`, you can make the changes after following the complete guide given [here](installing-and-running.md). |
| 298 | +
|
| 299 | +Once you have completed all the steps, you should have a running app. |
| 300 | + |
| 301 | +
|
| 302 | +If you've made it this far, it only requires a few changes to switch from `PostgreSQL` to `MySQL`. |
| 303 | +
|
| 304 | +**Change the `docker-compose.yml` to the following:** |
| 305 | +
|
| 306 | +`.env` |
| 307 | +
|
| 308 | +```env |
| 309 | +DATABASE_TYPE=mysql |
| 310 | +# set "localhost" if you are running app on local machine |
| 311 | +# set "mysql" if you are running app on docker |
| 312 | +DATABASE_HOST=localhost |
| 313 | +DATABASE_PORT=3306 |
| 314 | +DATABASE_USERNAME=root |
| 315 | +DATABASE_PASSWORD=secret |
| 316 | +DATABASE_NAME=app |
| 317 | +``` |
| 318 | +
|
| 319 | +`docker-compose.yml` |
| 320 | +
|
| 321 | +```yml |
| 322 | +services: |
| 323 | + mysql: |
| 324 | + image: mysql:9.2.0 |
| 325 | + ports: |
| 326 | + - ${DATABASE_PORT}:3306 |
| 327 | + volumes: |
| 328 | + - mysql-boilerplate-db:/var/lib/mysql |
| 329 | + environment: |
| 330 | + MYSQL_USER: ${DATABASE_USERNAME} |
| 331 | + MYSQL_PASSWORD: ${DATABASE_PASSWORD} |
| 332 | + MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} |
| 333 | + MYSQL_DATABASE: ${DATABASE_NAME} |
| 334 | +
|
| 335 | + # other services here... |
| 336 | +
|
| 337 | +volumes: |
| 338 | + # other volumes here... |
| 339 | + mysql-boilerplate-db: |
| 340 | +``` |
| 341 | +
|
| 342 | +After completing the above setup, run Docker with the following command: |
| 343 | +
|
| 344 | +```bash |
| 345 | +docker compose up -d mysql adminer maildev |
| 346 | +``` |
| 347 | +
|
| 348 | +All three services should be running as shown below: |
| 349 | +
|
| 350 | + |
| 351 | +
|
| 352 | +Once your services are up and running, you're almost halfway through. |
| 353 | +
|
| 354 | +Now install the MySQL client: |
| 355 | +
|
| 356 | +```bash |
| 357 | +npm i mysql2 --save |
| 358 | +``` |
| 359 | +
|
| 360 | +**Delete the existing migration file and generate a new one with the following script:** |
| 361 | +
|
| 362 | +```bash |
| 363 | +npm run migration:generate -- src/database/migrations/newMigration --pretty=true |
| 364 | +``` |
| 365 | +
|
| 366 | +Run migrations: |
| 367 | +
|
| 368 | +```bash |
| 369 | +npm run migration:run |
| 370 | +``` |
| 371 | +
|
| 372 | +Run seeds: |
| 373 | +
|
| 374 | +```bash |
| 375 | +npm run seed:run:relational |
| 376 | +``` |
| 377 | +
|
| 378 | +Run the app in dev mode: |
| 379 | +
|
| 380 | +```bash |
| 381 | +npm run start:dev |
| 382 | +``` |
| 383 | +
|
| 384 | +Open <http://localhost:3000> |
| 385 | +
|
| 386 | +To set up Adminer: |
| 387 | +
|
| 388 | +Open the running port in your browser. |
| 389 | +Open <http://localhost:8080> |
| 390 | +
|
| 391 | + |
| 392 | +
|
| 393 | +Running App: |
| 394 | + |
| 395 | + |
| 396 | +
|
294 | 397 | ---
|
295 | 398 |
|
296 | 399 | Previous: [Command Line Interface](cli.md)
|
|
0 commit comments