Skip to content

Commit

Permalink
updates to backend database from in-memory to mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
dieter.jordens committed Feb 22, 2021
1 parent 1df1ad8 commit f7d33b9
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 21 deletions.
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.8'
services:
mysqldb:
image: library/mysql:latest
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=user
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=db
volumes:
- mysql_data_container:/var/lib/mysql
networks:
- dj-website-backend-network

volumes:
mysql_data_container:

networks:
dj-website-backend-network:
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<version>2.4.0-SNAPSHOT</version>
<relativePath/>
</parent>
<groupId>dj.personal</groupId>
Expand All @@ -20,6 +20,11 @@
</properties>

<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand All @@ -45,18 +50,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/dj/personal/website/article/ArticleRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public ArticleRunner(ArticleRepository articleRepository) {

@Override
public void run(String... args) {
Collection<Article> articles = createArticles();
if(articleRepository.count() == 0){
Collection<Article> articles = createArticles();

int size = articles.size();
log.info(size + " articles have been saved to the database.");
int size = articles.size();
log.info(size + " articles have been saved to the database.");
}
}

private Collection<Article> createArticles() {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/dj/personal/website/book/BookRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public BookRunner(BookRepository bookRepository) {

@Override
public void run(String... args) {
Collection<Book> books = createBooks();
log.info(books.size() + " books have been saved to the database.");
if(bookRepository.count() == 0) {
Collection<Book> books = createBooks();
log.info(books.size() + " books have been saved to the database.");
}
}

private Collection<Book> createBooks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public CertificateRunner(CertificateRepository certificateRepository) {

@Override
public void run(String... args) {
Collection<Certificate> certificates = createCertificates();
if(certificateRepository.count() == 0) {
Collection<Certificate> certificates = createCertificates();

int size = certificates.size();
log.info(size + " certificates have been saved to the database.");
int size = certificates.size();
log.info(size + " certificates have been saved to the database.");
}
}

private Collection<Certificate> createCertificates() {
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/dj/personal/website/project/ProjectRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ public ProjectRunner(ProjectRepository projectRepository,

@Override
public void run(String... args) {
Collection<Project> projects = createProjects();
if(projectRepository.count() == 0){
Collection<Project> projects = createProjects();

log.info(projects.size() + " projects have been saved to the database.");
log.info(projects.size() + " projects have been saved to the database.");

Collection<Technology> technologies = technologyRepository.findAll();
log.info(technologies.size() + " technologies have been saved to the database.");
Collection<Technology> technologies = technologyRepository.findAll();
log.info(technologies.size() + " technologies have been saved to the database.");

Collection<Responsibility> responsibilities = responsibilityRepository.findAll();
log.info(responsibilities.size() + " responsibilities have been saved to the database.");
Collection<Responsibility> responsibilities = responsibilityRepository.findAll();
log.info(responsibilities.size() + " responsibilities have been saved to the database.");
}
}

private Collection<Project> createProjects() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ cors.allowedHeaders=*
cors.exposedHeaders=
cors.allowCredentials=
cors.maxAge=

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

0 comments on commit f7d33b9

Please sign in to comment.