Skip to content

Commit a0cc497

Browse files
add migrations for poll votes
1 parent e4b76fe commit a0cc497

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

internal/database/connection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func autoMigrate(db *gorm.DB) error {
9090
models.CommentLike{},
9191
models.Post{},
9292
models.PostLike{},
93+
models.PollVote{},
9394
models.UserBookProgress{},
9495
models.ClubBookAssignment{},
9596
models.ReadingLog{},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DROP INDEX IF EXISTS idx_poll_votes_option_id;
2+
DROP INDEX IF EXISTS idx_poll_votes_user_id;
3+
DROP INDEX IF EXISTS idx_poll_votes_post_id;
4+
DROP TABLE IF EXISTS poll_votes;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE poll_votes (
2+
id SERIAL PRIMARY KEY,
3+
post_id INTEGER NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
4+
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
5+
option_id VARCHAR(255) NOT NULL,
6+
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
7+
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
8+
UNIQUE(post_id, user_id, option_id)
9+
);
10+
11+
CREATE INDEX idx_poll_votes_post_id ON poll_votes(post_id);
12+
CREATE INDEX idx_poll_votes_user_id ON poll_votes(user_id);
13+
CREATE INDEX idx_poll_votes_option_id ON poll_votes(option_id);

0 commit comments

Comments
 (0)