Skip to content

Commit 2acf77c

Browse files
add club operations
1 parent 4a3a4c0 commit 2acf77c

File tree

9 files changed

+800
-43
lines changed

9 files changed

+800
-43
lines changed

internal/database/connection.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,14 @@ func Connect(cfg *config.Config) (*gorm.DB, error) {
6363
func autoMigrate(db *gorm.DB) error {
6464
return db.AutoMigrate(
6565
models.User{},
66+
models.Book{},
67+
models.Club{},
68+
models.ClubMembership{},
69+
models.Annotation{},
70+
models.AnnotationLike{},
71+
models.Comment{},
72+
models.CommentLike{},
73+
models.Post{},
74+
models.PostLike{},
6675
)
6776
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP TABLE IF EXISTS club_memberships;
2+
DROP TABLE IF EXISTS clubs;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CREATE TABLE IF NOT EXISTS clubs (
2+
id SERIAL PRIMARY KEY,
3+
name VARCHAR(100) NOT NULL UNIQUE,
4+
description TEXT,
5+
location VARCHAR(255),
6+
genre VARCHAR(100),
7+
cover_image_url TEXT,
8+
is_private BOOLEAN NOT NULL DEFAULT FALSE,
9+
max_members INT NOT NULL DEFAULT 100,
10+
members_count INT NOT NULL DEFAULT 0,
11+
rating REAL NOT NULL DEFAULT 0,
12+
tags TEXT[],
13+
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
14+
current_book JSONB,
15+
next_meeting JSONB,
16+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
17+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
18+
deleted_at TIMESTAMPTZ
19+
);
20+
21+
CREATE TABLE IF NOT EXISTS club_memberships (
22+
id SERIAL PRIMARY KEY,
23+
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
24+
club_id INTEGER NOT NULL REFERENCES clubs(id) ON DELETE CASCADE,
25+
role VARCHAR(20) NOT NULL DEFAULT 'member',
26+
is_approved BOOLEAN NOT NULL DEFAULT FALSE,
27+
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
28+
CONSTRAINT uq_club_user UNIQUE (club_id, user_id)
29+
);
30+
31+
CREATE UNIQUE INDEX IF NOT EXISTS uni_clubs_name ON clubs (name) WHERE deleted_at IS NULL;

0 commit comments

Comments
 (0)