Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] DDL FK 추가 #231

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions keewe-domain/src/main/resources/ddl/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ CREATE TABLE IF NOT EXISTS `block`

CREATE TABLE IF NOT EXISTS `favorite_interests`
(
user_id BIGINT(20) NOT NULL,
interest_name VARCHAR(255) NOT NULL,
user_id BIGINT(20) NOT NULL,
interest_name VARCHAR(255) NOT NULL,

FOREIGN KEY (user_id) REFERENCES `user`(user_id),
CONSTRAINT `favorite_activities_constraint` UNIQUE (user_id, interest_name)
Expand Down Expand Up @@ -100,8 +100,8 @@ CREATE TABLE IF NOT EXISTS `challenge`
(
challenge_id BIGINT NOT NULL AUTO_INCREMENT,
writer_id BIGINT NOT NULL,
interest_name VARCHAR(8) NOT NULL,
name VARCHAR(25) NOT NULL,
interest_name VARCHAR(8) NOT NULL,
name VARCHAR(25) NOT NULL,
introduction VARCHAR(150) NOT NULL,
deleted BIT NOT NULL,
created_at DATETIME(6) NOT NULL,
Expand All @@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS `challenge_participation`
challenge_participation_id BIGINT NOT NULL AUTO_INCREMENT,
challenger_id BIGINT NOT NULL,
challenge_id BIGINT NOT NULL,
my_topic VARCHAR(25) NOT NULL,
my_topic VARCHAR(25) NOT NULL,
insight_per_week INT NOT NULL,
duration INT NOT NULL,
deleted BIT NOT NULL,
Expand Down Expand Up @@ -160,7 +160,7 @@ CREATE TABLE IF NOT EXISTS `insight`
url VARCHAR(2000) NOT NULL,
deleted BIT NOT NULL,
valid BIT NOT NULL,
view BIGINT NOT NULL DEFAULT 0,
view BIGINT NOT NULL DEFAULT 0,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,

Expand All @@ -177,20 +177,23 @@ CREATE TABLE IF NOT EXISTS `reaction`
insight_id BIGINT NOT NULL,
reactor_id BIGINT NOT NULL,
reaction_type VARCHAR(15) NOT NULL,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,

FOREIGN KEY (insight_id) REFERENCES `insight`(insight_id),
FOREIGN KEY (reaction_id) REFERENCES `user`(user_id),
PRIMARY KEY (reaction_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `reaction_aggregation`
(
insight_id BIGINT NOT NULL ,
reaction_type VARCHAR(15) NOT NULL,
count BIGINT NOT NULL DEFAULT 0,
insight_id BIGINT NOT NULL,
reaction_type VARCHAR(15) NOT NULL,
count BIGINT NOT NULL DEFAULT 0,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,

FOREIGN KEY (insight_id) REFERENCES `insight`(insight_id),
PRIMARY KEY (insight_id, reaction_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Expand Down Expand Up @@ -234,7 +237,10 @@ CREATE TABLE IF NOT EXISTS `bookmark` (
insight_id BIGINT NOT NULL,
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,
PRIMARY KEY(user_id, insight_id)

FOREIGN KEY (user_id) REFERENCES `user`(user_id),
FOREIGN KEY (insight_id) REFERENCES `insight`(insight_id),
PRIMARY KEY (user_id, insight_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


Expand All @@ -249,7 +255,7 @@ CREATE TABLE IF NOT EXISTS `report`
created_at DATETIME(6) NOT NULL,
updated_at DATETIME(6) NOT NULL,

PRIMARY KEY(report_id),
FOREIGN KEY (reporter_id) REFERENCES `user`(user_id),
PRIMARY KEY (report_id),
FOREIGN KEY (reporter_id) REFERENCES `user`(user_id),
FOREIGN KEY (insight_id) REFERENCES `insight`(insight_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
10 changes: 10 additions & 0 deletions keewe-domain/src/main/resources/dml/issue-230_dml.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ALTER TABLE `reaction`
ADD CONSTRAINT FOREIGN KEY (insight_id) REFERENCES `insight`(insight_id),
ADD CONSTRAINT FOREIGN KEY (reaction_id) REFERENCES `user`(user_id);

ALTER TABLE `reaction_aggregation`
ADD CONSTRAINT FOREIGN KEY (insight_id) REFERENCES `insight`(insight_id);

ALTER TABLE `bookmark`
ADD CONSTRAINT FOREIGN KEY (user_id) REFERENCES `user`(user_id),
ADD CONSTRAINT FOREIGN KEY (insight_id) REFERENCES `insight`(insight_id);