Skip to content

[PBI] Notification data model and database schema #434

Description

@cjlapao

Description

Define and implement the core Notification struct and its per-user database schema using GORM. This is the foundational data layer all other PBIs depend on — nothing else can be built until the model and schema are in place and reviewed.

User Story

As a backend engineer, I want a well-defined, GORM-annotated notification model persisted to the database, so that all other components in the notification system have a stable, tested data contract to build against.

Acceptance Criteria

  • Model defined: A Notification struct is created with all required fields: id (UUID), user_id, type (enum: alert, warning, info, success), title, message, host_id (nullable), record_id (nullable), correlation_id (nullable), actions (serialised JSON), meta (serialised as []map[string]string), is_read (bool, default false), created_at.
  • Action sub-type defined: An Action struct is created with fields: label, type (enum: navigate, api_call), target, method (nullable), payload (nullable map[string]string). Actions are stored as a JSON column on the notification row.
  • GORM annotations correct: All fields carry appropriate GORM tags. actions and meta are stored as serialised JSON columns. Indexes are defined on user_id, is_read, correlation_id, and created_at.
  • Auto-migrate verified: Running db.AutoMigrate against a fresh database produces the correct schema for both SQLite and PostgreSQL.
  • Type enum validated: The type field is validated against the allowed enum values on creation; invalid values return a descriptive error.
  • Unit tests: Tests cover model creation, JSON serialisation/deserialisation of actions and meta, and enum validation.

Definition of Done

  • Code implemented following best practices.
  • Unit tests written and passing.
  • Code reviewed and approved.
  • Merged into the main branch.
  • Documentation updated (if applicable).
  • Deployed to staging/production environment.

Assumptions and Constraints

  • Assumption: The project is using GORM as established in the database migration feature. This PBI builds directly on that foundation.
  • Constraint: actions and meta must survive a round-trip through both SQLite (TEXT column) and PostgreSQL (JSONB column) without data loss.

Dependencies

No response

Additional Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pbiProduct Backlog ItemtriageSelected for triage

    Type

    Projects

    Status
    📋 Awaiting Triage

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions