package model import ( "encoding/json" "time" ) type User struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement"` Username string `gorm:"column:username;size:64;not null;uniqueIndex:uq_users_username"` Email string `gorm:"column:email;size:320;uniqueIndex:uq_users_email"` PasswordHash string `gorm:"column:password_hash;size:255;not null"` DisplayName string `gorm:"column:display_name;size:120;not null"` Status string `gorm:"column:status;size:16;not null"` CreatedAt time.Time `gorm:"column:created_at;not null"` UpdatedAt time.Time `gorm:"column:updated_at;not null"` } func (User) TableName() string { return "users" } type Provider struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement"` Slug string `gorm:"column:slug;size:80;not null;uniqueIndex:uq_providers_slug"` Name string `gorm:"column:name;size:120;not null"` BaseURL string `gorm:"column:base_url;size:2048;not null"` AuthType string `gorm:"column:auth_type;size:16;not null"` APIKeyEnc json.RawMessage `gorm:"column:api_key_enc;type:json"` Enabled bool `gorm:"column:enabled;not null"` CreatedAt time.Time `gorm:"column:created_at;not null"` UpdatedAt time.Time `gorm:"column:updated_at;not null"` } func (Provider) TableName() string { return "providers" } type ProviderModel struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement"` ProviderID uint64 `gorm:"column:provider_id;not null;uniqueIndex:uq_provider_models_binding,priority:1"` Name string `gorm:"column:name;size:120;not null"` ModelID string `gorm:"column:model_id;size:191;not null;uniqueIndex:uq_provider_models_binding,priority:2"` APIType APIType `gorm:"column:api_type;size:32;not null;uniqueIndex:uq_provider_models_binding,priority:3"` Kind GenerationKind `gorm:"column:kind;size:16;not null"` ExtraBody json.RawMessage `gorm:"column:extra_body;type:json;not null"` TimeoutMS uint32 `gorm:"column:timeout_ms;not null"` Weight uint32 `gorm:"column:weight;not null"` Enabled bool `gorm:"column:enabled;not null"` CreatedAt time.Time `gorm:"column:created_at;not null"` UpdatedAt time.Time `gorm:"column:updated_at;not null"` } func (ProviderModel) TableName() string { return "provider_models" } type PromptTemplate struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement"` TemplateKey string `gorm:"column:template_key;size:120;not null;uniqueIndex:uq_prompt_templates_key"` Kind GenerationKind `gorm:"column:kind;size:16;not null"` APIType APIType `gorm:"column:api_type;size:32;not null"` Capability Capability `gorm:"column:capability;size:32;not null"` Name string `gorm:"column:name;size:120;not null"` Version uint32 `gorm:"column:version;not null"` TemplateText string `gorm:"column:template_text;type:text;not null"` DefaultRoleRule string `gorm:"column:default_role_rule;type:text;not null"` Enabled bool `gorm:"column:enabled;not null"` CreatedAt time.Time `gorm:"column:created_at;not null"` UpdatedAt time.Time `gorm:"column:updated_at;not null"` } func (PromptTemplate) TableName() string { return "prompt_templates" } type Generation struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement"` UserID uint64 `gorm:"column:user_id;not null;uniqueIndex:uq_generations_user_idempotency,priority:1"` ProviderModelID *uint64 `gorm:"column:provider_model_id"` RoutePoolID *uint64 `gorm:"column:route_pool_id"` RoutePoolVersion *uint32 `gorm:"column:route_pool_version"` PromptTemplateID *uint64 `gorm:"column:prompt_template_id"` RouteSnapshot json.RawMessage `gorm:"column:route_snapshot;type:json"` RoleRule *string `gorm:"column:role_rule;type:text"` ProviderAttemptCount uint32 `gorm:"column:provider_attempt_count;not null"` Kind GenerationKind `gorm:"column:kind;size:16;not null"` Status GenerationStatus `gorm:"column:status;size:16;not null"` IdempotencyKey string `gorm:"column:idempotency_key;size:128;not null;uniqueIndex:uq_generations_user_idempotency,priority:2"` UserPrompt string `gorm:"column:user_prompt;type:text;not null"` RenderedPrompt string `gorm:"column:rendered_prompt;type:text;not null"` Attempts json.RawMessage `gorm:"column:attempts;type:json;not null"` AttemptCount uint32 `gorm:"column:attempt_count;not null"` ErrorCode *string `gorm:"column:error_code;size:64"` ErrorMessage *string `gorm:"column:error_message;size:1024"` LeaseOwner *string `gorm:"column:lease_owner;size:128"` LeaseToken *string `gorm:"column:lease_token;size:36"` LeaseUntil *time.Time `gorm:"column:lease_until"` AvailableAt time.Time `gorm:"column:available_at;not null;default:CURRENT_TIMESTAMP(6)"` StartedAt *time.Time `gorm:"column:started_at"` CompletedAt *time.Time `gorm:"column:completed_at"` CreatedAt time.Time `gorm:"column:created_at;not null"` UpdatedAt time.Time `gorm:"column:updated_at;not null"` } func (Generation) TableName() string { return "generations" } type GenerationInput struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement"` GenerationID uint64 `gorm:"column:generation_id;not null;uniqueIndex:uq_generation_inputs_position,priority:1"` Position uint32 `gorm:"column:position;not null;uniqueIndex:uq_generation_inputs_position,priority:2"` Role InputRole `gorm:"column:role;size:16;not null"` Note *string `gorm:"column:note;size:500"` OriginalName string `gorm:"column:original_name;size:255;not null"` MIMEType string `gorm:"column:mime_type;size:120;not null"` StorageKey string `gorm:"column:storage_key;size:512;not null"` SizeBytes uint64 `gorm:"column:size_bytes;not null"` Width *uint32 `gorm:"column:width"` Height *uint32 `gorm:"column:height"` CreatedAt time.Time `gorm:"column:created_at;not null"` } func (GenerationInput) TableName() string { return "generation_inputs" } type GenerationOutput struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement"` GenerationID uint64 `gorm:"column:generation_id;not null"` Kind GenerationKind `gorm:"column:kind;size:16;not null"` TextContent *string `gorm:"column:text_content;type:mediumtext"` StorageKey *string `gorm:"column:storage_key;size:512"` ThumbnailStorageKey *string `gorm:"column:thumbnail_storage_key;size:512"` MIMEType *string `gorm:"column:mime_type;size:120"` SizeBytes *uint64 `gorm:"column:size_bytes"` Width *uint32 `gorm:"column:width"` Height *uint32 `gorm:"column:height"` CreatedAt time.Time `gorm:"column:created_at;not null"` } func (GenerationOutput) TableName() string { return "generation_outputs" } type Attempt struct { Type string `json:"type,omitempty"` RouteMemberID uint64 `json:"route_member_id,omitempty"` ProviderModelID uint64 `json:"provider_model_id,omitempty"` ProviderOrdinal uint32 `json:"provider_ordinal,omitempty"` Retryable *bool `json:"retryable,omitempty"` ErrorCode string `json:"error_code,omitempty"` ErrorMessage string `json:"error_message,omitempty"` LatencyMS int64 `json:"latency_ms,omitempty"` StartedAt *time.Time `json:"started_at,omitempty"` FinishedAt *time.Time `json:"finished_at,omitempty"` DeferredUntil *time.Time `json:"deferred_until,omitempty"` }