11 lines
415 B
SQL
11 lines
415 B
SQL
CREATE TABLE IF NOT EXISTS post_votes (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
post_id INT NOT NULL,
|
|
vote_type ENUM('like', 'dislike') NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY user_post_vote (user_id, post_id),
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE
|
|
);
|