diff --git a/docker-compose.yml b/docker-compose.yml index 44d70a2..c3c49d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,33 @@ services: + postgres: + image: postgres:16 + restart: unless-stopped + environment: + POSTGRES_DB: codenames + POSTGRES_USER: codenames_user + POSTGRES_PASSWORD: codenames_pass + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U codenames_user -d codenames"] + interval: 10s + timeout: 5s + retries: 5 + backend: image: ghcr.io/ss26-se2-codenames/backend:latest restart: unless-stopped ports: - "53213:8080" volumes: - - ./data:/app/data \ No newline at end of file + - ./data:/app/data + environment: # Inject datasource url into application.yml when containerized + SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/codenames + SPRING_DATASOURCE_USERNAME: codenames_user + SPRING_DATASOURCE_PASSWORD: codenames_pass + depends_on: + postgres: + condition: service_healthy + +volumes: + postgres_data: \ No newline at end of file diff --git a/pom.xml b/pom.xml index a553376..d20b2dc 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,24 @@ jspecify 1.0.0 + + org.postgresql + postgresql + runtime + + + org.flywaydb + flyway-core + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 67237b6..3a63f2d 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -2,5 +2,23 @@ spring: application: name: Codenames_Backend + datasource: + url: jdbc:postgresql://localhost:5432/codenames # When we containerize docker compose will change localhost -> postgresql + username: codenames_user + password: codenames_pass + driver-class-name: org.postgresql.Driver + + jpa: + hibernate: + ddl-auto: validate + show-sql: true + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.PostgreSQLDialect + + flyway: + enabled: true + app: allowed-origins: "http://localhost:8080,http://10.0.2.2:8080" \ No newline at end of file diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml new file mode 100644 index 0000000..310dc3a --- /dev/null +++ b/src/test/resources/application.yaml @@ -0,0 +1,11 @@ +spring: + datasource: + url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=PostgreSQL # create mock h2 DB in RAM that doesn't close until tests finish + driver-class-name: org.h2.Driver + username: sa + password: + jpa: + hibernate: + ddl-auto: create-drop # flyway disabled, hibernate needs to take over and drop tables after test + flyway: + enabled: false # H2 might not work with flyway \ No newline at end of file