Skip to content

Database Schema

HIMARPL uses two databases for different purposes:

  1. CockroachDB with Prisma ORM - For core projects and main infrastructure
  2. PostgreSQL (NeonDB) with Drizzle ORM - For the bot functionality

Core Database Structure

Core Database Class Diagram

Main Classes

1. User Management

  • Users

    • Core user profile information (name, email, bio, position)
    • Can belong to one department
    • Has role-based access (admin/member)
    • Tracks periods of involvement and login activity
  • Authentication

    • Accounts: Handles OAuth connections (e.g., Google login)
    • Sessions: Manages active user sessions
    • VerificationToken: For email verification

2. Content Management

  • Posts

    • Blog articles and content entries
    • Contains metadata (title, slug, image)
    • Tracks publishing status and dates
    • Each post has one author (User)
  • PostTags

    • Hierarchical content categorization
    • Can have parent-child relationships
    • Used to organize posts by topics

3. Organization Structure

  • Departments

    • Two main types: BE (Badan Eksekutif) and DP (Dewan Perwakilan)
    • Contains department info (name, acronym, description)
    • Tracks associated programs
    • Users can be assigned to departments
  • SocialMedia

    • Links users to their social media profiles
    • Stores platform name, username, and URL

Key Relationships

  1. Users & Content
  • Each post must have one author
  • Users can create multiple posts
  • Users can have multiple social media profiles
  1. Content Organization
  • Posts can have multiple tags
  • Tags can have parent-child relationships
  • Posts have unique slugs per author
  1. Organizational
  • Users can belong to one department
  • Departments can have multiple users
  • Each user has a specific role (admin/member)

Prisma Schema Design Principles

  • Type-safe with defined enums
  • Proper foreign key constraints
  • Scalable for future expansion
  • Clear hierarchical relationships

Prisma Schema Rules

  • Use PascalCase for all models
  • Use camelCase for all attributes

Bot Database Structure

The bot uses PostgreSQL (NeonDB) with Drizzle ORM for managing notifications and user interactions.

Main Classes

Main Table: notifications

  • Purpose: Tracks Telegram chat notifications and user preferences
  • Table Prefix: bot-himarpl_ (uses multi-project schema pattern)

Key Fields:

  • chatId: Unique identifier for Telegram chats (primary key)
  • firstName: User’s first name from Telegram
  • lastName: User’s last name from Telegram
  • username: Telegram username
  • createdAt: Timestamp of chat creation
  • notifying: Array of notification topics the user is subscribed to

Technical Details:

  • Uses PostgreSQL-specific types (bigserial, varchar, timestamp)
  • Includes indexing on chatId for faster lookups
  • Implements timezone-aware timestamps
  • Uses array type for notification preferences

Drizzle Schema Design Principles

  • Uses table prefix for multi-project isolation
  • Implements proper PostgreSQL types
  • Includes performance optimization through indexing
  • Follows Drizzle ORM best practices

Drizzle Schema Rules

  • Use camelCase for all models in the schema
  • Use camelCase for all attributes in the models
  • Use snake_case for all table names in the database
  • Use snake_case for all attribute names in the database