|
| 1 | +To achieve the separation of environments (stage and local) and to use H2 DB for the local environment, we need to make the following changes: |
| 2 | + |
| 3 | +1. Create a new `application-local.yml` configuration file for the local environment. |
| 4 | +2. Modify the existing `application.yml` to be used for the stage environment. |
| 5 | +3. Update the `run.sh` script to handle both environments. |
| 6 | + |
| 7 | +Let's start with the changes: |
| 8 | + |
| 9 | +### 1. Create `application-local.yml` for the local environment |
| 10 | + |
| 11 | +```diff |
| 12 | +--- /dev/null |
| 13 | ++++ src/main/resources/application-local.yml |
| 14 | +@@ -0,0 +1,13 @@ |
| 15 | ++spring: |
| 16 | ++ datasource: |
| 17 | ++ url: jdbc:h2:mem:testdb |
| 18 | ++ driver-class-name: org.h2.Driver |
| 19 | ++ username: sa |
| 20 | ++ password: password |
| 21 | ++ h2: |
| 22 | ++ console: |
| 23 | ++ enabled: true |
| 24 | ++ jpa: |
| 25 | ++ hibernate: |
| 26 | ++ ddl-auto: update |
| 27 | ++ show-sql: true |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Modify `application.yml` to be used for the stage environment |
| 31 | + |
| 32 | +```diff |
| 33 | +--- src/main/resources/application.yml |
| 34 | ++++ src/main/resources/application.yml |
| 35 | +@@ -1,13 +1,13 @@ |
| 36 | + spring: |
| 37 | + datasource: |
| 38 | +- url: jdbc:postgresql://<RDS_ENDPOINT>:5432/<DB_NAME> |
| 39 | +- username: <DB_USERNAME> |
| 40 | +- password: <DB_PASSWORD> |
| 41 | ++ url: jdbc:postgresql://stage-rds-endpoint:5432/stage_db |
| 42 | ++ username: stage_user |
| 43 | ++ password: stage_password |
| 44 | + driver-class-name: org.postgresql.Driver |
| 45 | + jpa: |
| 46 | + hibernate: |
| 47 | + ddl-auto: update |
| 48 | + show-sql: true |
| 49 | + properties: |
| 50 | + hibernate: |
| 51 | + format_sql: true |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +### 6. Update `application.yml` to include profile-specific configurations |
| 57 | + |
| 58 | +```diff |
| 59 | +--- src/main/resources/application.yml |
| 60 | ++++ src/main/resources/application.yml |
| 61 | +@@ -1,13 +1,15 @@ |
| 62 | + spring: |
| 63 | + profiles: |
| 64 | +- active: stage |
| 65 | ++ active: stage |
| 66 | + datasource: |
| 67 | +- url: jdbc:postgresql://<RDS_ENDPOINT>:5432/<DB_NAME> |
| 68 | +- username: <DB_USERNAME> |
| 69 | +- password: <DB_PASSWORD> |
| 70 | ++ url: jdbc:postgresql://stage-rds-endpoint:5432/stage_db |
| 71 | ++ username: stage_user |
| 72 | ++ password: stage_password |
| 73 | + driver-class-name: org.postgresql.Driver |
| 74 | + jpa: |
| 75 | + hibernate: |
| 76 | + ddl-auto: update |
| 77 | + show-sql: true |
| 78 | + properties: |
| 79 | + hibernate: |
| 80 | + format_sql: true |
| 81 | +``` |
| 82 | + |
| 83 | +### 7. Update `application-local.yml` to include profile-specific configurations |
| 84 | + |
| 85 | +```diff |
| 86 | +--- src/main/resources/application-local.yml |
| 87 | ++++ src/main/resources/application-local.yml |
| 88 | +@@ -1,13 +1,15 @@ |
| 89 | + spring: |
| 90 | + profiles: |
| 91 | +- active: local |
| 92 | ++ active: local |
| 93 | + datasource: |
| 94 | +- url: jdbc:h2:mem:testdb |
| 95 | +- driver-class-name: org.h2.Driver |
| 96 | +- username: sa |
| 97 | +- password: password |
| 98 | ++ url: jdbc:h2:mem:testdb |
| 99 | ++ driver-class-name: org.h2.Driver |
| 100 | ++ username: sa |
| 101 | ++ password: password |
| 102 | + h2: |
| 103 | + console: |
| 104 | + enabled: true |
| 105 | + jpa: |
| 106 | + hibernate: |
| 107 | + ddl-auto: update |
| 108 | + show-sql: true |
| 109 | +``` |
0 commit comments