Skip to content

Commit

Permalink
build: 히스토리 테이블 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Choi-JJunho committed Jul 25, 2023
1 parent 5110fb0 commit e0853e3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
36 changes: 36 additions & 0 deletions backend/pium/src/main/java/com/official/pium/domain/History.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.official.pium.domain;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Entity
@Getter
@Table(name = "history")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class History extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pet_plant_id", nullable = false)
private PetPlant petPlant;

@NotNull
@Column(name = "water_date", nullable = false)
private LocalDate waterDate;

@Builder
private History(@NotNull PetPlant petPlant, @NotNull LocalDate waterDate) {
this.petPlant = petPlant;
this.waterDate = waterDate;
}
}
13 changes: 13 additions & 0 deletions backend/pium/src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,21 @@ CREATE TABLE IF NOT EXISTS pet_plant
CONSTRAINT pk_pet_plant PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS history
(
id BIGINT AUTO_INCREMENT NOT NULL,
pet_plant_id BIGINT NOT NULL,
water_date DATE NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
CONSTRAINT pk_history PRIMARY KEY (id)
);

ALTER TABLE pet_plant
ADD CONSTRAINT FK_PET_PLANT_ON_DICTIONARY_PLANT FOREIGN KEY (dictionary_plant_id) REFERENCES dictionary_plant (id);

ALTER TABLE pet_plant
ADD CONSTRAINT FK_PET_PLANT_ON_MEMBER FOREIGN KEY (member_id) REFERENCES member (id);

ALTER TABLE history
ADD CONSTRAINT FK_HISTORY_ON_PET_PLANT FOREIGN KEY (pet_plant_id) REFERENCES pet_plant (id);

0 comments on commit e0853e3

Please sign in to comment.