Skip to content

Conversation

@peresvetjke
Copy link

Model Layer Implementation: Before & After

Before

  • No models for Repository, UserRepository, Chat, Message, or ChatUser (except User).
  • No database tables or migrations for these entities.
  • No unread message tracking logic.
  • No model-level tests or associations for chat/message functionality.
  • Database schema included some fields and tables that were not strictly necessary for MVP (e.g., unread_messages table, private field in repositories).

After

Models & Migrations

  • Repository

    • Added model, migration, and tests.
    • Fields: github_repo_id, name, url, timestamps.
    • Associations: has_many :user_repositories, has_many :users, through: :user_repositories.
    • Removed unnecessary private field; added url for GitHub linking.
  • UserRepository

    • Added model, migration, and tests.
    • Fields: user_id, repository_id, timestamps.
    • Associations: belongs_to :user, belongs_to :repository.
    • Unique index on [user_id, repository_id].
  • Chat

    • Added model, migration, and tests.
    • Fields: chat_type (private/group), repository_id (nullable), timestamps.
    • Associations: belongs_to :repository, optional: true.
    • Only essential fields for MVP.
  • Message

    • Added model, migration, and tests.
    • Fields: chat_id, user_id, content (max 400), timestamps.
    • Associations: belongs_to :chat, belongs_to :user.
    • Index on [chat_id, created_at] for efficient chat history queries.
  • ChatUser

    • Added model, migration, and tests.
    • Fields: chat_id, user_id, last_read_message_id (nullable), timestamps.
    • Associations: belongs_to :chat, belongs_to :user, belongs_to :last_read_message, class_name: 'Message', optional: true.
    • Unique index on [chat_id, user_id].
    • Unread tracking implemented via last_read_message_id (not a separate table).

Testing

  • All models are fully covered by unit tests (validations and associations).
  • TDD process followed for each model.

Schema Simplification

  • Removed unnecessary fields and tables (e.g., unread_messages, private in repositories, joined_at/left_at in chat_users).
  • All models and tables now contain only fields required for MVP.

Documentation

  • Memory bank and schema diagrams updated to reflect the new, minimal, and focused design.

Summary Table

Model Before After (Fields/Associations/Indexes)
Repository None github_repo_id, name, url, users, user_repositories
UserRepository None user_id, repository_id, unique index
Chat None chat_type, repository_id (nullable), repository
Message None chat_id, user_id, content (max 400), chat, user
ChatUser None chat_id, user_id, last_read_message_id, unique idx

This PR introduces a clean, minimal, and fully tested model layer for the chat application, ready for further business logic and feature development.

Copy link
Collaborator

@madmatvey madmatvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 👍 👍 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants