Skip to content

Commit

Permalink
Merge pull request #2 from GeorgeApos/create-table-compose
Browse files Browse the repository at this point in the history
Add student table and compose
  • Loading branch information
nikosnikolaidis authored Jan 12, 2024
2 parents d0d5d07 + f5d4455 commit 5c96f50
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.3"

services:
backend:
build:
context: .
container_name: backend
depends_on:
- db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/test_db
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=root
ports:
- '8080:8080'

db:
image: postgres:14.7
container_name: db
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: test_db
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
ports:
- '5432:5432'

volumes:
postgresql:
postgresql_data:
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

</dependencies>

<build>
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/example/demo/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.demo;

import jakarta.persistence.*;;

@Entity
public class Student {

@Id
@GeneratedValue
private Long id;
private String name;

public Student(){

}

public Student(String name){
this.name = name;
}

public Long getId(){
return id;
}

public void setId(Long id){
this.id = id;
}

public String getName(){
return name;
}

public void setName(String name){
this.name = name;
}


}
7 changes: 6 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@

spring.datasource.url=jdbc:postgresql://localhost:5432/test_db
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
6 changes: 3 additions & 3 deletions src/test/java/com/example/demo/DemoApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@SpringBootTest
class DemoApplicationTests {

@Test
void contextLoads() {
}
// @Test
// void contextLoads() {
// }

}

0 comments on commit 5c96f50

Please sign in to comment.