Club manager database schema

The tables behind the club manager, as SQL, as an ER diagram and as a Prisma schema.

The database schema

Written by the free Database Schema Generator from a one-paragraph brief of the app.

The model centres on member, which belongs to a membership_type that carries the annual fee; one fee row per member and year records what is owed and whether it is paid. Events have a sign-up list through an explicit join table, announcements are club-wide, and app accounts are kept separate from members so the first sign-up can be the board.

Tables

  • app_user: one login account; the first one to sign up gets the board role, later ones are member.
  • membership_type: one kind of membership (e.g. Vollmitglied, Jugend) with its annual fee in cents.
  • member: one person in the club, with contact details, membership type, joining date and optionally the account they log in with.
  • fee: one annual fee owed by one member for one year, with its amount and the date it was marked as paid (empty while open).
  • event: one club event with title, date, place and optional description and capacity.
  • event_signup: one member's sign-up for one event.
  • announcement: one message from the board to all members.

SQL (PostgreSQL)

CREATE TABLE app_user (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  email text NOT NULL UNIQUE,
  password_hash text NOT NULL,
  role text NOT NULL DEFAULT 'member' CHECK (role IN ('board', 'member')),
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE membership_type (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  name text NOT NULL UNIQUE,
  description text,
  annual_fee_cents integer NOT NULL CHECK (annual_fee_cents >= 0),
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE member (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id uuid UNIQUE REFERENCES app_user(id) ON DELETE SET NULL, -- is the login of
  membership_type_id uuid NOT NULL REFERENCES membership_type(id) ON DELETE RESTRICT, -- classifies
  first_name text NOT NULL,
  last_name text NOT NULL,
  email text,
  phone text,
  street text,
  postal_code text,
  city text,
  joined_on date NOT NULL DEFAULT current_date,
  left_on date,
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE fee (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  member_id uuid NOT NULL REFERENCES member(id) ON DELETE CASCADE, -- owes
  year integer NOT NULL CHECK (year >= 2000),
  amount_cents integer NOT NULL CHECK (amount_cents >= 0),
  due_on date NOT NULL,
  paid_on date,
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now(),
  UNIQUE (member_id, year)
);

CREATE TABLE event (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  title text NOT NULL,
  description text,
  starts_at timestamptz NOT NULL,
  location text NOT NULL,
  max_participants integer CHECK (max_participants > 0),
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE event_signup (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  event_id uuid NOT NULL REFERENCES event(id) ON DELETE CASCADE, -- has sign-ups
  member_id uuid NOT NULL REFERENCES member(id) ON DELETE CASCADE, -- signs up for
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now(),
  UNIQUE (event_id, member_id)
);

CREATE TABLE announcement (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  author_id uuid REFERENCES app_user(id) ON DELETE SET NULL, -- writes
  title text NOT NULL,
  body text NOT NULL,
  published_at timestamptz NOT NULL DEFAULT now(),
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX member_membership_type_idx ON member (membership_type_id);
CREATE INDEX fee_open_idx ON fee (due_on) WHERE paid_on IS NULL;
CREATE INDEX event_starts_at_idx ON event (starts_at);
CREATE INDEX announcement_published_idx ON announcement (published_at DESC);

ERD

erDiagram
    app_user {
        uuid id PK
        text email
        text password_hash
        text role
        timestamptz created_at
        timestamptz updated_at
    }
    membership_type {
        uuid id PK
        text name
        text description
        integer annual_fee_cents
        timestamptz created_at
        timestamptz updated_at
    }
    member {
        uuid id PK
        uuid user_id FK
        uuid membership_type_id FK
        text first_name
        text last_name
        text email
        text phone
        text street
        text postal_code
        text city
        date joined_on
        date left_on
        timestamptz created_at
        timestamptz updated_at
    }
    fee {
        uuid id PK
        uuid member_id FK
        integer year
        integer amount_cents
        date due_on
        date paid_on
        timestamptz created_at
        timestamptz updated_at
    }
    event {
        uuid id PK
        text title
        text description
        timestamptz starts_at
        text location
        integer max_participants
        timestamptz created_at
        timestamptz updated_at
    }
    event_signup {
        uuid id PK
        uuid event_id FK
        uuid member_id FK
        timestamptz created_at
        timestamptz updated_at
    }
    announcement {
        uuid id PK
        uuid author_id FK
        text title
        text body
        timestamptz published_at
        timestamptz created_at
        timestamptz updated_at
    }
    app_user |o--o| member : "is the login of"
    membership_type ||--o{ member : "classifies"
    member ||--o{ fee : "owes"
    event ||--o{ event_signup : "has sign-ups"
    member ||--o{ event_signup : "signs up for"
    app_user |o--o{ announcement : "writes"

Prisma

model AppUser {
  id            String         @id @default(uuid()) @db.Uuid
  email         String         @unique
  passwordHash  String         @map("password_hash")
  role          String         @default("member")
  createdAt     DateTime       @default(now()) @map("created_at") @db.Timestamptz
  updatedAt     DateTime       @updatedAt @map("updated_at") @db.Timestamptz
  member        Member?
  announcements Announcement[]

  @@map("app_user")
}

model MembershipType {
  id             String   @id @default(uuid()) @db.Uuid
  name           String   @unique
  description    String?
  annualFeeCents Int      @map("annual_fee_cents")
  createdAt      DateTime @default(now()) @map("created_at") @db.Timestamptz
  updatedAt      DateTime @updatedAt @map("updated_at") @db.Timestamptz
  members        Member[]

  @@map("membership_type")
}

model Member {
  id               String         @id @default(uuid()) @db.Uuid
  userId           String?        @unique @map("user_id") @db.Uuid
  membershipTypeId String         @map("membership_type_id") @db.Uuid
  firstName        String         @map("first_name")
  lastName         String         @map("last_name")
  email            String?
  phone            String?
  street           String?
  postalCode       String?        @map("postal_code")
  city             String?
  joinedOn         DateTime       @default(now()) @map("joined_on") @db.Date
  leftOn           DateTime?      @map("left_on") @db.Date
  createdAt        DateTime       @default(now()) @map("created_at") @db.Timestamptz
  updatedAt        DateTime       @updatedAt @map("updated_at") @db.Timestamptz
  user             AppUser?       @relation(fields: [userId], references: [id], onDelete: SetNull)
  membershipType   MembershipType @relation(fields: [membershipTypeId], references: [id], onDelete: Restrict)
  fees             Fee[]
  signups          EventSignup[]

  @@index([membershipTypeId])
  @@map("member")
}

model Fee {
  id          String    @id @default(uuid()) @db.Uuid
  memberId    String    @map("member_id") @db.Uuid
  year        Int
  amountCents Int       @map("amount_cents")
  dueOn       DateTime  @map("due_on") @db.Date
  paidOn      DateTime? @map("paid_on") @db.Date
  createdAt   DateTime  @default(now()) @map("created_at") @db.Timestamptz
  updatedAt   DateTime  @updatedAt @map("updated_at") @db.Timestamptz
  member      Member    @relation(fields: [memberId], references: [id], onDelete: Cascade)

  @@unique([memberId, year])
  @@map("fee")
}

model Event {
  id              String        @id @default(uuid()) @db.Uuid
  title           String
  description     String?
  startsAt        DateTime      @map("starts_at") @db.Timestamptz
  location        String
  maxParticipants Int?          @map("max_participants")
  createdAt       DateTime      @default(now()) @map("created_at") @db.Timestamptz
  updatedAt       DateTime      @updatedAt @map("updated_at") @db.Timestamptz
  signups         EventSignup[]

  @@index([startsAt])
  @@map("event")
}

model EventSignup {
  id        String   @id @default(uuid()) @db.Uuid
  eventId   String   @map("event_id") @db.Uuid
  memberId  String   @map("member_id") @db.Uuid
  createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
  updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
  event     Event    @relation(fields: [eventId], references: [id], onDelete: Cascade)
  member    Member   @relation(fields: [memberId], references: [id], onDelete: Cascade)

  @@unique([eventId, memberId])
  @@map("event_signup")
}

model Announcement {
  id          String   @id @default(uuid()) @db.Uuid
  authorId    String?  @map("author_id") @db.Uuid
  title       String
  body        String
  publishedAt DateTime @default(now()) @map("published_at") @db.Timestamptz
  createdAt   DateTime @default(now()) @map("created_at") @db.Timestamptz
  updatedAt   DateTime @updatedAt @map("updated_at") @db.Timestamptz
  author      AppUser? @relation(fields: [authorId], references: [id], onDelete: SetNull)

  @@index([publishedAt(sort: Desc)])
  @@map("announcement")
}
MCP

Build this with your AI assistant

Connect Claude Code, Cursor, Codex or ChatGPT to Chattee and let your assistant create, deploy and publish this app while you approve the plan.

See the MCP server