Skip to content

[Schedules 1/8] Add Schedule and ScheduleRun database models #29

@sre-helmcode

Description

@sre-helmcode

Implementation Order: 1 of 8 (start here)

Feature: Schedules — Recurring automated tasks for AI agent teams

Summary

Add the database models for the Schedules feature. These are the foundation for all subsequent issues.

Models

Schedule

type Schedule struct {
    ID             string    `gorm:"primaryKey;size:36" json:"id"`
    Name           string    `gorm:"not null;size:255" json:"name"`
    TeamID         string    `gorm:"not null;size:36" json:"team_id"`
    Prompt         string    `gorm:"type:text;not null" json:"prompt"`
    CronExpression string    `gorm:"not null;size:100" json:"cron_expression"`
    Timezone       string    `gorm:"not null;size:50;default:'UTC'" json:"timezone"`
    Enabled        bool      `gorm:"default:true" json:"enabled"`
    LastRunAt      *time.Time `json:"last_run_at"`
    NextRunAt      *time.Time `json:"next_run_at"`
    Status         string    `gorm:"size:20;default:'idle'" json:"status"` // idle | running | error
    CreatedAt      time.Time `json:"created_at"`
    UpdatedAt      time.Time `json:"updated_at"`
}

ScheduleRun

type ScheduleRun struct {
    ID               string     `gorm:"primaryKey;size:36" json:"id"`
    ScheduleID       string     `gorm:"not null;index" json:"schedule_id"`
    TeamDeploymentID string     `gorm:"size:36" json:"team_deployment_id"` // links to the team instance for viewing conversation
    StartedAt        time.Time  `json:"started_at"`
    FinishedAt       *time.Time `json:"finished_at"`
    Status           string     `gorm:"size:20;default:'running'" json:"status"` // running | success | failed | timeout
    Error            string     `gorm:"type:text" json:"error"`
}

Acceptance Criteria

  • Both models added to internal/models/models.go
  • AutoMigrate includes both new models
  • Foreign key: ScheduleRun.ScheduleIDSchedule.ID
  • Foreign key: Schedule.TeamIDTeam.ID
  • Status enums documented in code comments
  • Unit tests for model creation and relationships

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions