Skip to content

Commit

Permalink
Merge pull request #16 from deepredk/feature/13
Browse files Browse the repository at this point in the history
redis & mysql docker-compose.yml 작성
  • Loading branch information
deepredk authored Oct 17, 2023
2 parents 934aef4 + 8ef88e4 commit 90700c1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'
services:
mysql:
image: mysql:latest
container_name: mysql-container
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: "1234"
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql

redis:
image: redis:latest
container_name: redis-container
ports:
- "6380:6379"
18 changes: 18 additions & 0 deletions init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- hittracker 데이터베이스 생성
CREATE DATABASE IF NOT EXISTS hittracker;
USE hittracker;

-- Url 테이블 생성
CREATE TABLE IF NOT EXISTS Url (
url_id BIGINT AUTO_INCREMENT PRIMARY KEY,
url VARCHAR(255) NOT NULL UNIQUE
);

-- DailyHitLog 테이블 생성
CREATE TABLE IF NOT EXISTS DailyHitLog (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
date DATE NOT NULL,
dailyHit INT NOT NULL,
url_id BIGINT NOT NULL,
FOREIGN KEY (url_id) REFERENCES Url(url_id) ON DELETE CASCADE
);
4 changes: 3 additions & 1 deletion src/main/java/it/numble/hittracker/entity/DailyHitLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public class DailyHitLog {
private Long id;
@JsonSerialize(using = LocalDateSerializer.class)
@JsonDeserialize(using = LocalDateDeserializer.class)
@Column(nullable = false)
private LocalDate date;
@Column(nullable = false)
private int dailyHit;
@ManyToOne
@JoinColumn(name = "url_id")
@JoinColumn(name = "url_id", nullable = false)
private Url url;

public DailyHitLog(LocalDate date, int dailyHit, Url url) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/it/numble/hittracker/entity/Url.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package it.numble.hittracker.entity;

import it.numble.hittracker.common.exception.InvalidUrlException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import jakarta.persistence.*;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
Expand All @@ -25,6 +20,7 @@ public class Url {
@Column(name = "url_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false)
private String url;

public Url(String url) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:testdb
username: sa
password:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3307/hittracker
username: root
password: 1234
h2:
console:
enabled: true
jpa:
hibernate:
ddl-auto: update
ddl-auto: update
data:
redis:
port: 6380
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class TestRedisConfiguration {
private final RedisServer redisServer;

public TestRedisConfiguration() throws IOException {
this.redisServer = new RedisServer(6379);
this.redisServer = new RedisServer(6380);
}

@PostConstruct
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:testdb
username: sa
password:
data:
redis:
port: 6380

0 comments on commit 90700c1

Please sign in to comment.