models

package
v0.0.0-...-716f63d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package models - hooks.go contains GORM lifecycle hooks for validation. These hooks replace PostgreSQL CHECK constraints and triggers to enable consistent validation across all supported databases.

Package models defines GORM models for the TMI database schema. These models support both PostgreSQL and Oracle databases through GORM's dialect abstraction.

Package models defines GORM models for the TMI database schema. This file contains models for the Survey API feature.

Package models defines GORM models for the TMI database schema.

Package models defines GORM models for the TMI database schema. This file contains models for the Teams and Projects feature.

Index

Constants

View Source
const (
	SystemSettingTypeString = "string"
	SystemSettingTypeInt    = "int"
	SystemSettingTypeBool   = "bool"
	SystemSettingTypeJSON   = "json"
)

SystemSettingType constants for the Type field

Variables

View Source
var UseUppercaseTableNames = false

UseUppercaseTableNames controls whether table names should be uppercase. Set to true for Oracle databases where unquoted identifiers are folded to uppercase. This must be set before any GORM operations occur.

Functions

func AllModels

func AllModels() []any

AllModels returns all GORM models for migration

Types

type Addon

type Addon struct {
	ID            string      `gorm:"primaryKey;type:varchar(36)"`
	CreatedAt     time.Time   `gorm:"not null;autoCreateTime"`
	Name          string      `gorm:"type:varchar(256);not null"`
	WebhookID     string      `gorm:"type:varchar(36);not null;index"`
	Description   *string     `gorm:"type:varchar(2048)"`
	Icon          *string     `gorm:"type:varchar(60)"`
	Objects       StringArray `gorm:""`
	ThreatModelID *string     `gorm:"type:varchar(36);index"`

	// Relationships
	Webhook     WebhookSubscription `gorm:"foreignKey:WebhookID"`
	ThreatModel *ThreatModel        `gorm:"foreignKey:ThreatModelID"`
}

Addon represents an addon configuration Note: Explicit column tags removed for Oracle compatibility

func (*Addon) BeforeCreate

func (a *Addon) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (Addon) TableName

func (Addon) TableName() string

TableName specifies the table name for Addon

type AddonInvocationQuota

type AddonInvocationQuota struct {
	OwnerInternalUUID     string    `gorm:"primaryKey;type:varchar(36)"`
	MaxActiveInvocations  int       `gorm:"default:1"`
	MaxInvocationsPerHour int       `gorm:"default:10"`
	CreatedAt             time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt            time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	Owner User `gorm:"foreignKey:OwnerInternalUUID;references:InternalUUID"`
}

AddonInvocationQuota represents per-user addon invocation quotas Note: Explicit column tags removed for Oracle compatibility

func (AddonInvocationQuota) TableName

func (AddonInvocationQuota) TableName() string

TableName specifies the table name for AddonInvocationQuota

type Asset

type Asset struct {
	ID              string      `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID   string      `` /* 131-byte string literal not displayed */
	Name            string      `gorm:"type:varchar(256);not null;index:idx_assets_name"`
	Description     *string     `gorm:"type:varchar(2048)"`
	Type            string      `gorm:"type:varchar(64);not null;index:idx_assets_type"`
	Criticality     *string     `gorm:"type:varchar(128)"`
	Classification  StringArray `gorm:""`
	Sensitivity     *string     `gorm:"type:varchar(128)"`
	IncludeInReport DBBool      `gorm:"default:1"`
	CreatedAt       time.Time   `gorm:"not null;autoCreateTime;index:idx_assets_created;index:idx_assets_tm_created,priority:2"`
	ModifiedAt      time.Time   `gorm:"not null;autoUpdateTime;index:idx_assets_modified;index:idx_assets_tm_modified,priority:2"`

	// Relationships
	ThreatModel ThreatModel `gorm:"foreignKey:ThreatModelID"`
}

Asset represents an asset within a threat model Note: Explicit column tags removed for Oracle compatibility

func (*Asset) BeforeCreate

func (a *Asset) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*Asset) BeforeSave

func (a *Asset) BeforeSave(tx *gorm.DB) error

BeforeSave validates Asset before create or update

func (Asset) TableName

func (Asset) TableName() string

TableName specifies the table name for Asset

type CVSSArray

type CVSSArray []CVSSScore

CVSSArray is a custom type that stores CVSS score arrays as JSON This outputs JSON array format [{"vector":"...","score":9.8}] which works for both PostgreSQL JSONB columns and Oracle JSON columns

func (CVSSArray) GormDBDataType

func (CVSSArray) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType implements the GormDBDataTypeInterface to return dialect-specific column types for cross-database compatibility

func (*CVSSArray) Scan

func (a *CVSSArray) Scan(value any) error

Scan implements the sql.Scanner interface for database reads

func (CVSSArray) Value

func (a CVSSArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database writes Outputs JSON array format: [{"vector":"...","score":9.8}]

type CVSSScore

type CVSSScore struct {
	Vector string  `json:"vector"`
	Score  float64 `json:"score"`
}

CVSSScore represents a CVSS vector and score pair for threat assessment

type ClientCredential

type ClientCredential struct {
	ID               string  `gorm:"primaryKey;type:varchar(36)"`
	OwnerUUID        string  `gorm:"type:varchar(36);not null;index"`
	ClientID         string  `gorm:"type:varchar(1000);not null;uniqueIndex"`
	ClientSecretHash DBText  `gorm:"not null"`
	Name             string  `gorm:"type:varchar(256);not null"`
	Description      *string `gorm:"type:varchar(1024)"`
	IsActive         DBBool  `gorm:"default:1"`
	LastUsedAt       *time.Time
	CreatedAt        time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt       time.Time `gorm:"not null;autoUpdateTime"`
	ExpiresAt        *time.Time

	// Relationships
	Owner User `gorm:"foreignKey:OwnerUUID;references:InternalUUID"`
}

ClientCredential represents OAuth 2.0 client credentials for machine-to-machine auth Note: Explicit column tags removed for Oracle compatibility

func (*ClientCredential) BeforeCreate

func (c *ClientCredential) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (ClientCredential) TableName

func (ClientCredential) TableName() string

TableName specifies the table name for ClientCredential

type CollaborationSession

type CollaborationSession struct {
	ID            string    `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID string    `gorm:"type:varchar(36);not null;index"`
	DiagramID     string    `gorm:"type:varchar(36);not null;index"`
	WebsocketURL  string    `gorm:"type:varchar(1024);not null"`
	CreatedAt     time.Time `gorm:"not null;autoCreateTime"`
	ExpiresAt     *time.Time

	// Relationships
	ThreatModel  ThreatModel          `gorm:"foreignKey:ThreatModelID"`
	Diagram      Diagram              `gorm:"foreignKey:DiagramID"`
	Participants []SessionParticipant `gorm:"foreignKey:SessionID"`
}

CollaborationSession represents a real-time collaboration session Note: Explicit column tags removed for Oracle compatibility

func (*CollaborationSession) BeforeCreate

func (c *CollaborationSession) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*CollaborationSession) BeforeSave

func (c *CollaborationSession) BeforeSave(tx *gorm.DB) error

BeforeSave validates CollaborationSession before create or update

func (CollaborationSession) TableName

func (CollaborationSession) TableName() string

TableName specifies the table name for CollaborationSession

type DBBool

type DBBool bool

DBBool is a cross-database boolean type that handles different database representations of booleans. Oracle uses NUMBER(1), MySQL uses TINYINT(1), SQL Server uses BIT, while PostgreSQL and SQLite have native boolean support. This type implements sql.Scanner and driver.Valuer to handle the conversion for all supported databases.

func (DBBool) Bool

func (b DBBool) Bool() bool

Bool returns the underlying bool value.

func (DBBool) GormDBDataType

func (DBBool) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType implements the GormDBDataTypeInterface to return dialect-specific column types for cross-database compatibility

func (*DBBool) Scan

func (b *DBBool) Scan(value any) error

Scan implements the sql.Scanner interface for DBBool. It handles: - bool (PostgreSQL native boolean) - int64/int/int32 (numeric representation) - godror.Number (Oracle's numeric type, implements fmt.Stringer) - nil (NULL values)

func (DBBool) Value

func (b DBBool) Value() (driver.Value, error)

Value implements the driver.Valuer interface for DBBool. It returns the boolean as a native Go bool for cross-database compatibility. PostgreSQL expects bool for boolean columns, and Oracle's godror driver can handle Go bool and convert it to NUMBER(1) appropriately.

type DBText

type DBText string

DBText is a cross-database large text type. Uses TEXT on PostgreSQL, CLOB on Oracle, LONGTEXT on MySQL, NVARCHAR(MAX) on SQL Server, and TEXT on SQLite.

func (DBText) GormDBDataType

func (DBText) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType implements the GormDBDataTypeInterface to return dialect-specific column types for cross-database compatibility

func (*DBText) Scan

func (t *DBText) Scan(value any) error

Scan implements the sql.Scanner interface for database reads

func (DBText) String

func (t DBText) String() string

String returns the underlying string value

func (DBText) Value

func (t DBText) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database writes

type Diagram

type Diagram struct {
	ID                string         `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID     string         `gorm:"type:varchar(36);not null;index:idx_diagrams_tm;index:idx_diagrams_tm_type,priority:1"`
	Name              string         `gorm:"type:varchar(256);not null"`
	Description       *string        `gorm:"type:varchar(2048)"`
	Type              *string        `gorm:"type:varchar(64);index:idx_diagrams_type;index:idx_diagrams_tm_type,priority:2"`
	Content           NullableDBText `gorm:""`
	Cells             JSONRaw        `gorm:""`
	SVGImage          NullableDBText `gorm:""`
	ImageUpdateVector *int64
	UpdateVector      int64     `gorm:"default:0"`
	IncludeInReport   DBBool    `gorm:"default:1"`
	CreatedAt         time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt        time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	ThreatModel ThreatModel `gorm:"foreignKey:ThreatModelID"`
}

Diagram represents a diagram within a threat model Note: Explicit column tags removed for Oracle compatibility

func (*Diagram) BeforeCreate

func (d *Diagram) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*Diagram) BeforeUpdate

func (d *Diagram) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate validates Diagram before update

func (Diagram) TableName

func (Diagram) TableName() string

TableName specifies the table name for Diagram

type Document

type Document struct {
	ID              string    `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID   string    `gorm:"type:varchar(36);not null;index:idx_docs_tm;index:idx_docs_tm_created,priority:1;index:idx_docs_tm_modified,priority:1"`
	Name            string    `gorm:"type:varchar(256);not null;index:idx_docs_name"`
	URI             string    `gorm:"type:varchar(1000);not null"`
	Description     *string   `gorm:"type:varchar(2048)"`
	IncludeInReport DBBool    `gorm:"default:1"`
	CreatedAt       time.Time `gorm:"not null;autoCreateTime;index:idx_docs_created;index:idx_docs_tm_created,priority:2"`
	ModifiedAt      time.Time `gorm:"not null;autoUpdateTime;index:idx_docs_modified;index:idx_docs_tm_modified,priority:2"`

	// Relationships
	ThreatModel ThreatModel `gorm:"foreignKey:ThreatModelID"`
}

Document represents a document attached to a threat model Note: Explicit column tags removed for Oracle compatibility

func (*Document) BeforeCreate

func (d *Document) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*Document) BeforeSave

func (d *Document) BeforeSave(tx *gorm.DB) error

BeforeSave validates Document before create or update

func (Document) TableName

func (Document) TableName() string

TableName specifies the table name for Document

type Group

type Group struct {
	InternalUUID string    `gorm:"primaryKey;type:varchar(36)"`
	Provider     string    `gorm:"type:varchar(100);not null;index:idx_groups_provider"`
	GroupName    string    `gorm:"type:varchar(500);not null;index:idx_groups_group_name"`
	Name         *string   `gorm:"type:varchar(256)"`
	Description  *string   `gorm:"type:varchar(2048)"`
	FirstUsed    time.Time `gorm:"not null;autoCreateTime"`
	LastUsed     time.Time `gorm:"not null;autoUpdateTime;index:idx_groups_last_used"`
	UsageCount   int       `gorm:"default:1"`
}

Group represents an identity provider group Note: Explicit column tags removed for Oracle compatibility

func (*Group) BeforeCreate

func (g *Group) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*Group) BeforeDelete

func (g *Group) BeforeDelete(tx *gorm.DB) error

BeforeDelete prevents deletion of built-in groups (everyone, security-reviewers, administrators)

func (*Group) BeforeUpdate

func (g *Group) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate prevents renaming or changing the description of built-in groups

func (Group) TableName

func (Group) TableName() string

TableName specifies the table name for Group

type GroupMember

type GroupMember struct {
	ID                      string    `gorm:"primaryKey;type:varchar(36)"`
	GroupInternalUUID       string    `gorm:"type:varchar(36);not null;index;uniqueIndex:idx_gm_group_user_type,priority:1"`
	UserInternalUUID        *string   `gorm:"type:varchar(36);index;uniqueIndex:idx_gm_group_user_type,priority:2"`
	MemberGroupInternalUUID *string   `gorm:"type:varchar(36);index"`
	SubjectType             string    `gorm:"type:varchar(10);not null;default:user;uniqueIndex:idx_gm_group_user_type,priority:3"`
	AddedByInternalUUID     *string   `gorm:"type:varchar(36)"`
	AddedAt                 time.Time `gorm:"not null;autoCreateTime"`
	Notes                   *string   `gorm:"type:varchar(2048)"`

	// Relationships
	Group       Group  `gorm:"foreignKey:GroupInternalUUID;references:InternalUUID"`
	User        *User  `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
	MemberGroup *Group `gorm:"foreignKey:MemberGroupInternalUUID;references:InternalUUID"`
	AddedBy     *User  `gorm:"foreignKey:AddedByInternalUUID;references:InternalUUID"`
}

GroupMember represents a user's or group's membership in a group. Supports one level of group-in-group nesting: an external IdP group can be a member of a built-in group (e.g., Administrators), enabling all members of the external group to inherit the built-in group's privileges. Note: Explicit column tags removed for Oracle compatibility

func (*GroupMember) BeforeCreate

func (g *GroupMember) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*GroupMember) BeforeSave

func (gm *GroupMember) BeforeSave(tx *gorm.DB) error

BeforeSave validates GroupMember and prevents adding to "everyone" group

func (GroupMember) TableName

func (GroupMember) TableName() string

TableName specifies the table name for GroupMember

type JSONMap

type JSONMap map[string]any

JSONMap is a custom type that stores JSON objects This works across both PostgreSQL JSONB and Oracle JSON

func (JSONMap) GormDBDataType

func (JSONMap) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType implements the GormDBDataTypeInterface to return dialect-specific column types for cross-database compatibility

func (*JSONMap) Scan

func (m *JSONMap) Scan(value any) error

Scan implements the sql.Scanner interface for database reads

func (JSONMap) Value

func (m JSONMap) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database writes Returns string (not []byte) for Oracle CLOB compatibility

type JSONRaw

type JSONRaw json.RawMessage

JSONRaw is a custom type for storing raw JSON (like cells in diagrams)

func (JSONRaw) GormDBDataType

func (JSONRaw) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType implements the GormDBDataTypeInterface to return dialect-specific column types for cross-database compatibility

func (JSONRaw) MarshalJSON

func (j JSONRaw) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*JSONRaw) Scan

func (j *JSONRaw) Scan(value any) error

Scan implements the sql.Scanner interface for database reads

func (*JSONRaw) UnmarshalJSON

func (j *JSONRaw) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (JSONRaw) Value

func (j JSONRaw) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database writes Returns string (not []byte) for Oracle CLOB compatibility

type Metadata

type Metadata struct {
	ID         string    `gorm:"primaryKey;type:varchar(36)"`
	EntityType string    `` /* 212-byte string literal not displayed */
	EntityID   string    `` /* 183-byte string literal not displayed */
	Key        string    `` /* 133-byte string literal not displayed */
	Value      string    `gorm:"type:varchar(1024);not null;index:idx_metadata_key_value,priority:3"`
	CreatedAt  time.Time `gorm:"not null;autoCreateTime;index:idx_metadata_created;index:idx_metadata_entity_created,priority:2"`
	ModifiedAt time.Time `gorm:"not null;autoUpdateTime;index:idx_metadata_modified;index:idx_metadata_entity_modified,priority:2"`
}

Metadata represents key-value metadata for entities Note: Explicit column tags removed for Oracle compatibility

func (*Metadata) BeforeCreate

func (m *Metadata) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*Metadata) BeforeSave

func (m *Metadata) BeforeSave(tx *gorm.DB) error

BeforeSave validates Metadata before create or update

func (Metadata) TableName

func (Metadata) TableName() string

TableName specifies the table name for Metadata

type Note

type Note struct {
	ID              string    `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID   string    `` /* 128-byte string literal not displayed */
	Name            string    `gorm:"type:varchar(256);not null;index:idx_notes_name"`
	Content         DBText    `gorm:"not null"`
	Description     *string   `gorm:"type:varchar(2048)"`
	IncludeInReport DBBool    `gorm:"default:1"`
	CreatedAt       time.Time `gorm:"not null;autoCreateTime;index:idx_notes_created;index:idx_notes_tm_created,priority:2"`
	ModifiedAt      time.Time `gorm:"not null;autoUpdateTime;index:idx_notes_modified;index:idx_notes_tm_modified,priority:2"`

	// Relationships
	ThreatModel ThreatModel `gorm:"foreignKey:ThreatModelID"`
}

Note represents a note attached to a threat model Note: Explicit column tags removed for Oracle compatibility

func (*Note) BeforeCreate

func (n *Note) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set and validates required fields. Note: Required field validation is intentionally in BeforeCreate (not BeforeSave) because the Update path uses map-based GORM Updates() on an empty model struct. BeforeSave would validate the empty struct's zero-value fields, causing false "cannot be empty" errors. Update-time validation is handled by the API layer.

func (Note) TableName

func (Note) TableName() string

TableName specifies the table name for Note

type NullableDBText

type NullableDBText struct {
	String string
	Valid  bool
}

NullableDBText is a nullable cross-database large text type. Wraps a string with a Valid flag for NULL handling. Uses TEXT on PostgreSQL, CLOB on Oracle, LONGTEXT on MySQL, NVARCHAR(MAX) on SQL Server, and TEXT on SQLite.

func NewNullableDBText

func NewNullableDBText(s *string) NullableDBText

NewNullableDBText creates a NullableDBText from a string pointer

func (NullableDBText) GormDBDataType

func (NullableDBText) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType implements the GormDBDataTypeInterface to return dialect-specific column types for cross-database compatibility

func (NullableDBText) Ptr

func (t NullableDBText) Ptr() *string

Ptr returns a pointer to the string, or nil if not valid

func (*NullableDBText) Scan

func (t *NullableDBText) Scan(value any) error

Scan implements the sql.Scanner interface for database reads

func (NullableDBText) Value

func (t NullableDBText) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database writes

type OracleBool deprecated

type OracleBool = DBBool

OracleBool is an alias for DBBool for backward compatibility.

Deprecated: Use DBBool instead.

type ProjectRecord

type ProjectRecord struct {
	ID                     string     `gorm:"primaryKey;type:varchar(36)"`
	Name                   string     `gorm:"type:varchar(256);not null;index:idx_proj_name"`
	Description            *string    `gorm:"type:varchar(2048)"`
	TeamID                 string     `gorm:"type:varchar(36);not null;index:idx_proj_team"`
	URI                    *string    `gorm:"type:varchar(1000)"`
	Status                 *string    `gorm:"type:varchar(128);index:idx_proj_status"`
	CreatedByInternalUUID  string     `gorm:"type:varchar(36);not null"`
	ModifiedByInternalUUID *string    `gorm:"type:varchar(36)"`
	ReviewedByInternalUUID *string    `gorm:"type:varchar(36)"`
	ReviewedAt             *time.Time `gorm:"index:idx_proj_reviewed_at"`
	CreatedAt              time.Time  `gorm:"not null;autoCreateTime;index:idx_proj_created_at"`
	ModifiedAt             time.Time  `gorm:"not null;autoUpdateTime"`

	// Relationships
	Team       TeamRecord `gorm:"foreignKey:TeamID"`
	CreatedBy  User       `gorm:"foreignKey:CreatedByInternalUUID;references:InternalUUID"`
	ModifiedBy *User      `gorm:"foreignKey:ModifiedByInternalUUID;references:InternalUUID"`
	ReviewedBy *User      `gorm:"foreignKey:ReviewedByInternalUUID;references:InternalUUID"`
}

ProjectRecord represents a project in the system

func (*ProjectRecord) BeforeCreate

func (p *ProjectRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (ProjectRecord) TableName

func (ProjectRecord) TableName() string

TableName specifies the table name for ProjectRecord

type ProjectRelationshipRecord

type ProjectRelationshipRecord struct {
	ID                 string    `gorm:"primaryKey;type:varchar(36)"`
	ProjectID          string    `gorm:"type:varchar(36);not null;index:idx_prel_project;uniqueIndex:idx_prel_project_related,priority:1"`
	RelatedProjectID   string    `gorm:"type:varchar(36);not null;index:idx_prel_related;uniqueIndex:idx_prel_project_related,priority:2"`
	Relationship       string    `gorm:"type:varchar(64);not null"`
	CustomRelationship *string   `gorm:"type:varchar(128)"`
	CreatedAt          time.Time `gorm:"not null;autoCreateTime"`

	// Relationships
	Project        ProjectRecord `gorm:"foreignKey:ProjectID"`
	RelatedProject ProjectRecord `gorm:"foreignKey:RelatedProjectID"`
}

ProjectRelationshipRecord represents a relationship between two projects

func (*ProjectRelationshipRecord) BeforeCreate

func (p *ProjectRelationshipRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (ProjectRelationshipRecord) TableName

func (ProjectRelationshipRecord) TableName() string

TableName specifies the table name for ProjectRelationshipRecord

type ProjectResponsiblePartyRecord

type ProjectResponsiblePartyRecord struct {
	ID               string    `gorm:"primaryKey;type:varchar(36)"`
	ProjectID        string    `gorm:"type:varchar(36);not null;index:idx_prp_project;uniqueIndex:idx_prp_project_user,priority:1"`
	UserInternalUUID string    `gorm:"type:varchar(36);not null;index:idx_prp_user;uniqueIndex:idx_prp_project_user,priority:2"`
	Role             string    `gorm:"type:varchar(64);not null"`
	CustomRole       *string   `gorm:"type:varchar(128)"`
	CreatedAt        time.Time `gorm:"not null;autoCreateTime"`

	// Relationships
	Project ProjectRecord `gorm:"foreignKey:ProjectID"`
	User    User          `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
}

ProjectResponsiblePartyRecord represents a responsible party for a project

func (*ProjectResponsiblePartyRecord) BeforeCreate

func (p *ProjectResponsiblePartyRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (ProjectResponsiblePartyRecord) TableName

TableName specifies the table name for ProjectResponsiblePartyRecord

type RefreshTokenRecord

type RefreshTokenRecord struct {
	ID               string    `gorm:"primaryKey;type:varchar(36)"`
	UserInternalUUID string    `gorm:"type:varchar(36);not null;index"`
	Token            string    `gorm:"type:varchar(4000);not null;uniqueIndex"` // varchar(4000) for Oracle compatibility (CLOB cannot have unique index)
	ExpiresAt        time.Time `gorm:"not null"`
	CreatedAt        time.Time `gorm:"not null;autoCreateTime"`

	// Relationships
	User User `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
}

RefreshTokenRecord represents a refresh token for a user Note: Explicit column tags removed for Oracle compatibility

func (*RefreshTokenRecord) BeforeCreate

func (r *RefreshTokenRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (RefreshTokenRecord) TableName

func (RefreshTokenRecord) TableName() string

TableName specifies the table name for RefreshTokenRecord

type Repository

type Repository struct {
	ID              string    `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID   string    `` /* 128-byte string literal not displayed */
	Name            *string   `gorm:"type:varchar(256);index:idx_repos_name"`
	URI             string    `gorm:"type:varchar(1000);not null"`
	Description     *string   `gorm:"type:varchar(2048)"`
	Type            *string   `gorm:"type:varchar(64);index:idx_repos_type"`
	Parameters      JSONMap   `gorm:""`
	IncludeInReport DBBool    `gorm:"default:1"`
	CreatedAt       time.Time `gorm:"not null;autoCreateTime;index:idx_repos_created;index:idx_repos_tm_created,priority:2"`
	ModifiedAt      time.Time `gorm:"not null;autoUpdateTime;index:idx_repos_modified;index:idx_repos_tm_modified,priority:2"`

	// Relationships
	ThreatModel ThreatModel `gorm:"foreignKey:ThreatModelID"`
}

Repository represents a repository attached to a threat model Note: Explicit column tags removed for Oracle compatibility

func (*Repository) BeforeCreate

func (r *Repository) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*Repository) BeforeSave

func (r *Repository) BeforeSave(tx *gorm.DB) error

BeforeSave validates Repository before create or update

func (Repository) TableName

func (Repository) TableName() string

TableName specifies the table name for Repository

type SessionParticipant

type SessionParticipant struct {
	ID               string    `gorm:"primaryKey;type:varchar(36)"`
	SessionID        string    `gorm:"type:varchar(36);not null;index"`
	UserInternalUUID string    `gorm:"type:varchar(36);not null;index"`
	JoinedAt         time.Time `gorm:"not null;autoCreateTime"`
	LeftAt           *time.Time

	// Relationships
	Session CollaborationSession `gorm:"foreignKey:SessionID"`
	User    User                 `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
}

SessionParticipant represents a participant in a collaboration session Note: Explicit column tags removed for Oracle compatibility

func (*SessionParticipant) BeforeCreate

func (s *SessionParticipant) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (SessionParticipant) TableName

func (SessionParticipant) TableName() string

TableName specifies the table name for SessionParticipant

type StringArray

type StringArray []string

StringArray is a custom type that stores string arrays as JSON This outputs JSON array format ["val1","val2"] which works for both PostgreSQL JSONB columns and Oracle JSON columns

func (StringArray) GormDBDataType

func (StringArray) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType implements the GormDBDataTypeInterface to return dialect-specific column types for cross-database compatibility

func (*StringArray) Scan

func (a *StringArray) Scan(value any) error

Scan implements the sql.Scanner interface for database reads

func (StringArray) Value

func (a StringArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database writes Outputs JSON array format: ["val1","val2","val3"]

type SurveyResponse

type SurveyResponse struct {
	ID                     string     `gorm:"primaryKey;type:varchar(36)"`
	TemplateID             string     `gorm:"type:varchar(36);not null;index:idx_sr_template;index:idx_sr_template_status,priority:1"`
	TemplateVersion        string     `gorm:"type:varchar(64);not null"` // Captured at creation, immutable
	Status                 string     `gorm:"type:varchar(30);not null;default:draft;index:idx_sr_status;index:idx_sr_template_status,priority:2"`
	IsConfidential         DBBool     `gorm:"default:0"`          // If true, Security Reviewers group not auto-added
	Answers                JSONRaw    `gorm:""`                   // Question answers keyed by question name
	UIState                JSONRaw    `gorm:"column:ui_state"`    // Client-managed UI state for draft resumption
	SurveyJSON             JSONRaw    `gorm:"column:survey_json"` // Snapshot of template survey_json at creation
	LinkedThreatModelID    *string    `gorm:"type:varchar(36);index:idx_sr_linked_tm"`
	CreatedThreatModelID   *string    `gorm:"type:varchar(36);index:idx_sr_created_tm"`
	RevisionNotes          *string    `gorm:"type:varchar(4096)"` // Notes from reviewer when returning for revision
	OwnerInternalUUID      *string    `gorm:"type:varchar(36);index:idx_sr_owner"`
	CreatedAt              time.Time  `gorm:"not null;autoCreateTime;index:idx_sr_created_at"`
	ModifiedAt             time.Time  `gorm:"not null;autoUpdateTime"`
	SubmittedAt            *time.Time `gorm:"index:idx_sr_submitted_at"`
	ReviewedAt             *time.Time
	ReviewedByInternalUUID *string `gorm:"type:varchar(36)"`
	ProjectID              *string `gorm:"type:varchar(36);index:idx_sr_project"`

	// Relationships
	Template           SurveyTemplate `gorm:"foreignKey:TemplateID"`
	Owner              *User          `gorm:"foreignKey:OwnerInternalUUID;references:InternalUUID"`
	ReviewedBy         *User          `gorm:"foreignKey:ReviewedByInternalUUID;references:InternalUUID"`
	LinkedThreatModel  *ThreatModel   `gorm:"foreignKey:LinkedThreatModelID"`
	CreatedThreatModel *ThreatModel   `gorm:"foreignKey:CreatedThreatModelID"`
	Project            *ProjectRecord `gorm:"foreignKey:ProjectID"`
}

SurveyResponse represents a user's response to a survey template

func (*SurveyResponse) BeforeCreate

func (s *SurveyResponse) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (SurveyResponse) TableName

func (SurveyResponse) TableName() string

TableName specifies the table name for SurveyResponse

type SurveyResponseAccess

type SurveyResponseAccess struct {
	ID                    string    `gorm:"primaryKey;type:varchar(36)"`
	SurveyResponseID      string    `gorm:"type:varchar(36);not null;index:idx_sra_sr;index:idx_sra_perf,priority:1"`
	UserInternalUUID      *string   `gorm:"type:varchar(36);index:idx_sra_user;index:idx_sra_perf,priority:3"`
	GroupInternalUUID     *string   `gorm:"type:varchar(36);index:idx_sra_group;index:idx_sra_perf,priority:4"`
	SubjectType           string    `gorm:"type:varchar(10);not null;index:idx_sra_subject_type;index:idx_sra_perf,priority:2"`
	Role                  string    `gorm:"type:varchar(6);not null;index:idx_sra_role"`
	GrantedByInternalUUID *string   `gorm:"type:varchar(36)"`
	CreatedAt             time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt            time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	SurveyResponse SurveyResponse `gorm:"foreignKey:SurveyResponseID"`
	User           *User          `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
	Group          *Group         `gorm:"foreignKey:GroupInternalUUID;references:InternalUUID"`
	GrantedBy      *User          `gorm:"foreignKey:GrantedByInternalUUID;references:InternalUUID"`
}

SurveyResponseAccess represents access control for a survey response Mirrors the ThreatModelAccess pattern for consistency

func (*SurveyResponseAccess) BeforeCreate

func (s *SurveyResponseAccess) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (SurveyResponseAccess) TableName

func (SurveyResponseAccess) TableName() string

TableName specifies the table name for SurveyResponseAccess

type SurveyTemplate

type SurveyTemplate struct {
	ID                    string    `gorm:"primaryKey;type:varchar(36)"`
	Name                  string    `gorm:"type:varchar(256);not null;index:idx_st_name"`
	Description           *string   `gorm:"type:varchar(2048)"`
	Version               string    `gorm:"type:varchar(64);not null;index:idx_st_version;uniqueIndex:idx_st_name_version,priority:2"`
	Status                string    `gorm:"type:varchar(20);not null;default:inactive;index:idx_st_status"`
	SurveyJSON            JSONRaw   `gorm:"column:survey_json"` // Complete SurveyJS JSON definition (opaque blob)
	Settings              JSONRaw   `gorm:""`                   // Template settings (allow_threat_model_linking, etc.)
	CreatedByInternalUUID string    `gorm:"type:varchar(36);not null;index:idx_st_created_by"`
	CreatedAt             time.Time `gorm:"not null;autoCreateTime;index:idx_st_created_at"`
	ModifiedAt            time.Time `gorm:"not null;autoUpdateTime"`
	// contains filtered or unexported fields
}

SurveyTemplate represents a survey template for security review intake

func (*SurveyTemplate) BeforeCreate

func (s *SurveyTemplate) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (SurveyTemplate) TableName

func (SurveyTemplate) TableName() string

TableName specifies the table name for SurveyTemplate

type SurveyTemplateVersion

type SurveyTemplateVersion struct {
	ID                    string    `gorm:"primaryKey;type:varchar(36)"`
	TemplateID            string    `gorm:"type:varchar(36);not null;index:idx_stv_template;uniqueIndex:idx_stv_template_version,priority:1"`
	Version               string    `gorm:"type:varchar(64);not null;uniqueIndex:idx_stv_template_version,priority:2"`
	SurveyJSON            JSONRaw   `gorm:"column:survey_json"`
	CreatedByInternalUUID string    `gorm:"type:varchar(36);not null"`
	CreatedAt             time.Time `gorm:"not null;autoCreateTime"`

	// Relationships
	Template SurveyTemplate `gorm:"foreignKey:TemplateID"`
}

SurveyTemplateVersion represents a versioned snapshot of a survey template definition

func (*SurveyTemplateVersion) BeforeCreate

func (s *SurveyTemplateVersion) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (SurveyTemplateVersion) TableName

func (SurveyTemplateVersion) TableName() string

TableName specifies the table name for SurveyTemplateVersion

type SystemSetting

type SystemSetting struct {
	// SettingKey is the unique identifier for this setting (e.g., "rate_limit.requests_per_minute")
	// Named SettingKey instead of Key to avoid Oracle reserved word conflict
	SettingKey string `gorm:"column:setting_key;primaryKey;type:varchar(256)" json:"key"`
	Value      string `gorm:"type:varchar(4000);not null" json:"value"`
	// SettingType stores the value type: "string", "int", "bool", "json"
	// Note: default tag removed for Oracle compatibility (unquoted string defaults cause syntax errors)
	SettingType string    `gorm:"column:setting_type;type:varchar(50);not null" json:"type"`
	Description *string   `gorm:"type:varchar(2048)" json:"description,omitempty"`
	ModifiedAt  time.Time `gorm:"not null;autoUpdateTime" json:"modified_at"`
	ModifiedBy  *string   `gorm:"type:varchar(36)" json:"modified_by,omitempty"` // User InternalUUID

}

SystemSetting represents a system-wide configuration setting stored in the database. These settings can be modified at runtime without requiring server restart. Settings are cached with short TTL for performance.

func DefaultSystemSettings

func DefaultSystemSettings() []SystemSetting

DefaultSystemSettings returns the default system settings that should be seeded when the database is initialized. These provide sensible defaults that can be overridden by administrators.

func (SystemSetting) TableName

func (SystemSetting) TableName() string

TableName specifies the table name for SystemSetting

type TeamMemberRecord

type TeamMemberRecord struct {
	ID               string    `gorm:"primaryKey;type:varchar(36)"`
	TeamID           string    `gorm:"type:varchar(36);not null;index:idx_tmem_team;uniqueIndex:idx_tmem_team_user,priority:1"`
	UserInternalUUID string    `gorm:"type:varchar(36);not null;index:idx_tmem_user;uniqueIndex:idx_tmem_team_user,priority:2"`
	Role             string    `gorm:"type:varchar(64);not null;default:engineer"`
	CustomRole       *string   `gorm:"type:varchar(128)"`
	CreatedAt        time.Time `gorm:"not null;autoCreateTime"`

	// Relationships
	Team TeamRecord `gorm:"foreignKey:TeamID"`
	User User       `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
}

TeamMemberRecord represents a user's membership in a team

func (*TeamMemberRecord) BeforeCreate

func (t *TeamMemberRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (TeamMemberRecord) TableName

func (TeamMemberRecord) TableName() string

TableName specifies the table name for TeamMemberRecord

type TeamRecord

type TeamRecord struct {
	ID                     string     `gorm:"primaryKey;type:varchar(36)"`
	Name                   string     `gorm:"type:varchar(256);not null;index:idx_team_name"`
	Description            *string    `gorm:"type:varchar(2048)"`
	URI                    *string    `gorm:"type:varchar(1000)"`
	EmailAddress           *string    `gorm:"type:varchar(320)"`
	Status                 *string    `gorm:"type:varchar(128);index:idx_team_status"`
	CreatedByInternalUUID  string     `gorm:"type:varchar(36);not null"`
	ModifiedByInternalUUID *string    `gorm:"type:varchar(36)"`
	ReviewedByInternalUUID *string    `gorm:"type:varchar(36)"`
	ReviewedAt             *time.Time `gorm:"index:idx_team_reviewed_at"`
	CreatedAt              time.Time  `gorm:"not null;autoCreateTime;index:idx_team_created_at"`
	ModifiedAt             time.Time  `gorm:"not null;autoUpdateTime"`

	// Relationships
	CreatedBy  User  `gorm:"foreignKey:CreatedByInternalUUID;references:InternalUUID"`
	ModifiedBy *User `gorm:"foreignKey:ModifiedByInternalUUID;references:InternalUUID"`
	ReviewedBy *User `gorm:"foreignKey:ReviewedByInternalUUID;references:InternalUUID"`
}

TeamRecord represents a team in the system

func (*TeamRecord) BeforeCreate

func (t *TeamRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (TeamRecord) TableName

func (TeamRecord) TableName() string

TableName specifies the table name for TeamRecord

type TeamRelationshipRecord

type TeamRelationshipRecord struct {
	ID                 string    `gorm:"primaryKey;type:varchar(36)"`
	TeamID             string    `gorm:"type:varchar(36);not null;index:idx_trel_team;uniqueIndex:idx_trel_team_related,priority:1"`
	RelatedTeamID      string    `gorm:"type:varchar(36);not null;index:idx_trel_related;uniqueIndex:idx_trel_team_related,priority:2"`
	Relationship       string    `gorm:"type:varchar(64);not null"`
	CustomRelationship *string   `gorm:"type:varchar(128)"`
	CreatedAt          time.Time `gorm:"not null;autoCreateTime"`

	// Relationships
	Team        TeamRecord `gorm:"foreignKey:TeamID"`
	RelatedTeam TeamRecord `gorm:"foreignKey:RelatedTeamID"`
}

TeamRelationshipRecord represents a relationship between two teams

func (*TeamRelationshipRecord) BeforeCreate

func (t *TeamRelationshipRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (TeamRelationshipRecord) TableName

func (TeamRelationshipRecord) TableName() string

TableName specifies the table name for TeamRelationshipRecord

type TeamResponsiblePartyRecord

type TeamResponsiblePartyRecord struct {
	ID               string    `gorm:"primaryKey;type:varchar(36)"`
	TeamID           string    `gorm:"type:varchar(36);not null;index:idx_trp_team;uniqueIndex:idx_trp_team_user,priority:1"`
	UserInternalUUID string    `gorm:"type:varchar(36);not null;index:idx_trp_user;uniqueIndex:idx_trp_team_user,priority:2"`
	Role             string    `gorm:"type:varchar(64);not null"`
	CustomRole       *string   `gorm:"type:varchar(128)"`
	CreatedAt        time.Time `gorm:"not null;autoCreateTime"`

	// Relationships
	Team TeamRecord `gorm:"foreignKey:TeamID"`
	User User       `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
}

TeamResponsiblePartyRecord represents a responsible party for a team

func (*TeamResponsiblePartyRecord) BeforeCreate

func (t *TeamResponsiblePartyRecord) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (TeamResponsiblePartyRecord) TableName

func (TeamResponsiblePartyRecord) TableName() string

TableName specifies the table name for TeamResponsiblePartyRecord

type Threat

type Threat struct {
	ID              string      `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID   string      `` /* 134-byte string literal not displayed */
	DiagramID       *string     `gorm:"type:varchar(36);index:idx_threats_diagram"`
	CellID          *string     `gorm:"type:varchar(36);index:idx_threats_cell"`
	AssetID         *string     `gorm:"type:varchar(36);index:idx_threats_asset"`
	Name            string      `gorm:"type:varchar(256);not null;index:idx_threats_name"`
	Description     *string     `gorm:"type:varchar(2048)"`
	Severity        *string     `gorm:"type:varchar(50);index:idx_threats_severity"`
	Likelihood      *string     `gorm:"type:varchar(50)"`
	RiskLevel       *string     `gorm:"type:varchar(50);index:idx_threats_risk_level"`
	Score           *float64    `gorm:"type:decimal(3,1);index:idx_threats_score"`
	Priority        *string     `gorm:"type:varchar(256);index:idx_threats_priority"`
	Mitigated       DBBool      `gorm:"index:idx_threats_mitigated"`
	IncludeInReport DBBool      `gorm:"default:1"`
	Status          *string     `gorm:"type:varchar(128);index:idx_threats_status"`
	ThreatType      StringArray `gorm:"not null"`
	CweID           StringArray `gorm:"column:cwe_id"` // CWE identifiers (e.g., CWE-89)
	Cvss            CVSSArray   `gorm:"column:cvss"`   // CVSS vector and score pairs
	Mitigation      *string     `gorm:"type:varchar(1024)"`
	IssueURI        *string     `gorm:"type:varchar(1000)"`
	// Note: autoCreateTime/autoUpdateTime tags removed for Oracle compatibility.
	// Timestamps are set explicitly in the store layer (toGormModelForCreate).
	CreatedAt  time.Time `gorm:"not null;index:idx_threats_tm_created,priority:2"`
	ModifiedAt time.Time `gorm:"not null;index:idx_threats_modified;index:idx_threats_tm_modified,priority:2"`

	// Relationships
	ThreatModel ThreatModel `gorm:"foreignKey:ThreatModelID"`
	Diagram     *Diagram    `gorm:"foreignKey:DiagramID"`
	Asset       *Asset      `gorm:"foreignKey:AssetID"`
}

Threat represents a threat within a threat model Note: Explicit column tags removed for Oracle compatibility

func (*Threat) BeforeCreate

func (t *Threat) BeforeCreate(tx *gorm.DB) error

BeforeCreate ensures the ID is set before insert This is required for Oracle compatibility where the driver may not properly handle IDs set after struct initialization

func (*Threat) BeforeSave

func (t *Threat) BeforeSave(tx *gorm.DB) error

BeforeSave validates Threat before create or update

func (Threat) TableName

func (Threat) TableName() string

TableName specifies the table name for Threat

type ThreatModel

type ThreatModel struct {
	ID                           string      `gorm:"primaryKey;type:varchar(36)"`
	OwnerInternalUUID            string      `gorm:"type:varchar(36);not null;index:idx_tm_owner;index:idx_tm_owner_created,priority:1"`
	Name                         string      `gorm:"type:varchar(256);not null"`
	Description                  *string     `gorm:"type:varchar(2048)"`
	CreatedByInternalUUID        string      `gorm:"type:varchar(36);not null;index:idx_tm_created_by"`
	ThreatModelFramework         string      `gorm:"type:varchar(30);default:STRIDE;index:idx_tm_framework"`
	IssueURI                     *string     `gorm:"type:varchar(1000)"`
	Status                       *string     `gorm:"type:varchar(128);index:idx_tm_status"`
	StatusUpdated                *time.Time  `gorm:"index:idx_tm_status_updated"`
	Alias                        StringArray `gorm:"column:alias"` // Alternative names/identifiers
	IsConfidential               DBBool      `gorm:"default:0"`    // Immutable after creation
	SecurityReviewerInternalUUID *string     `gorm:"type:varchar(36);index:idx_tm_security_reviewer"`
	ProjectID                    *string     `gorm:"type:varchar(36);index:idx_tm_project"`
	CreatedAt                    time.Time   `gorm:"not null;autoCreateTime;index:idx_tm_owner_created,priority:2"`
	ModifiedAt                   time.Time   `gorm:"not null;autoUpdateTime"`

	// Relationships
	Project          *ProjectRecord `gorm:"foreignKey:ProjectID"`
	Owner            User           `gorm:"foreignKey:OwnerInternalUUID;references:InternalUUID"`
	CreatedBy        User           `gorm:"foreignKey:CreatedByInternalUUID;references:InternalUUID"`
	SecurityReviewer *User          `gorm:"foreignKey:SecurityReviewerInternalUUID;references:InternalUUID"`
	Diagrams         []Diagram      `gorm:"foreignKey:ThreatModelID"`
	Threats          []Threat       `gorm:"foreignKey:ThreatModelID"`
	Assets           []Asset        `gorm:"foreignKey:ThreatModelID"`
}

ThreatModel represents a threat model in the system Note: Explicit column tags removed for Oracle compatibility (Oracle stores column names as UPPERCASE, and the Oracle GORM driver doesn't handle case-insensitive matching with explicit column tags)

func (*ThreatModel) BeforeCreate

func (t *ThreatModel) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*ThreatModel) BeforeUpdate

func (t *ThreatModel) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate validates ThreatModel before update

func (ThreatModel) TableName

func (ThreatModel) TableName() string

TableName specifies the table name for ThreatModel

type ThreatModelAccess

type ThreatModelAccess struct {
	ID                    string    `gorm:"primaryKey;type:varchar(36)"`
	ThreatModelID         string    `gorm:"type:varchar(36);not null;index:idx_tma_tm;index:idx_tma_perf,priority:1"`
	UserInternalUUID      *string   `gorm:"type:varchar(36);index:idx_tma_user;index:idx_tma_perf,priority:3"`
	GroupInternalUUID     *string   `gorm:"type:varchar(36);index:idx_tma_group;index:idx_tma_perf,priority:4"`
	SubjectType           string    `gorm:"type:varchar(10);not null;index:idx_tma_subject_type;index:idx_tma_perf,priority:2"`
	Role                  string    `gorm:"type:varchar(6);not null;index:idx_tma_role"`
	GrantedByInternalUUID *string   `gorm:"type:varchar(36)"`
	CreatedAt             time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt            time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	ThreatModel ThreatModel `gorm:"foreignKey:ThreatModelID"`
	User        *User       `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
	Group       *Group      `gorm:"foreignKey:GroupInternalUUID;references:InternalUUID"`
	GrantedBy   *User       `gorm:"foreignKey:GrantedByInternalUUID;references:InternalUUID"`
}

ThreatModelAccess represents access control for threat models Note: Explicit column tags removed for Oracle compatibility (Oracle stores column names as UPPERCASE, and the Oracle GORM driver doesn't handle case-insensitive matching with explicit column tags)

func (*ThreatModelAccess) BeforeCreate

func (t *ThreatModelAccess) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*ThreatModelAccess) BeforeSave

func (t *ThreatModelAccess) BeforeSave(tx *gorm.DB) error

BeforeSave validates ThreatModelAccess before create or update

func (ThreatModelAccess) TableName

func (ThreatModelAccess) TableName() string

TableName specifies the table name for ThreatModelAccess

type TriageNote

type TriageNote struct {
	SurveyResponseID       string    `gorm:"primaryKey;type:varchar(36);index:idx_tn_sr"`
	ID                     int       `gorm:"primaryKey;autoIncrement:false"`
	Name                   string    `gorm:"type:varchar(256);not null"`
	Content                DBText    `gorm:"not null"`
	CreatedByInternalUUID  *string   `gorm:"type:varchar(36)"`
	ModifiedByInternalUUID *string   `gorm:"type:varchar(36)"`
	CreatedAt              time.Time `gorm:"not null;autoCreateTime;index:idx_tn_created"`
	ModifiedAt             time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	SurveyResponse SurveyResponse `gorm:"foreignKey:SurveyResponseID"`
	CreatedBy      *User          `gorm:"foreignKey:CreatedByInternalUUID;references:InternalUUID"`
	ModifiedBy     *User          `gorm:"foreignKey:ModifiedByInternalUUID;references:InternalUUID"`
}

TriageNote represents a triage note attached to a survey response Uses a composite primary key (SurveyResponseID, ID) where ID is a per-response monotonically increasing integer.

func (*TriageNote) BeforeCreate

func (t *TriageNote) BeforeCreate(tx *gorm.DB) error

BeforeCreate assigns the next sequential ID for the survey response

func (TriageNote) TableName

func (TriageNote) TableName() string

TableName specifies the table name for TriageNote

type User

type User struct {
	InternalUUID   string         `gorm:"primaryKey;type:varchar(36)"`
	Provider       string         `gorm:"type:varchar(100);not null;index:idx_users_provider;index:idx_users_provider_lookup,priority:1"`
	ProviderUserID *string        `gorm:"type:varchar(500);index:idx_users_provider_lookup,priority:2"`
	Email          string         `gorm:"type:varchar(320);not null;index:idx_users_email"`
	Name           string         `gorm:"type:varchar(256);not null"`
	EmailVerified  DBBool         `gorm:"default:0"`
	AccessToken    NullableDBText `gorm:""`
	RefreshToken   NullableDBText `gorm:""`
	TokenExpiry    *time.Time
	CreatedAt      time.Time  `gorm:"not null;autoCreateTime"`
	ModifiedAt     time.Time  `gorm:"not null;autoUpdateTime"`
	LastLogin      *time.Time `gorm:"index:idx_users_last_login"`
}

User represents an authenticated user in the system Note: Column names are intentionally not specified to allow GORM's NamingStrategy to handle database-specific casing (lowercase for PostgreSQL, UPPERCASE for Oracle)

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (User) TableName

func (User) TableName() string

TableName specifies the table name for User

type UserAPIQuota

type UserAPIQuota struct {
	UserInternalUUID     string `gorm:"primaryKey;type:varchar(36)"`
	MaxRequestsPerMinute int    `gorm:"default:100"`
	MaxRequestsPerHour   *int
	CreatedAt            time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt           time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	User User `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
}

UserAPIQuota represents per-user API rate limits Note: Explicit column tags removed for Oracle compatibility

func (UserAPIQuota) TableName

func (UserAPIQuota) TableName() string

TableName specifies the table name for UserAPIQuota

type UserPreference

type UserPreference struct {
	ID               string    `gorm:"primaryKey;type:varchar(36)"`
	UserInternalUUID string    `gorm:"type:varchar(36);not null;uniqueIndex"`
	Preferences      JSONRaw   `gorm:"not null"`
	CreatedAt        time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt       time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	User User `gorm:"foreignKey:UserInternalUUID;references:InternalUUID"`
}

UserPreference stores user preferences as JSON Preferences are keyed by client application identifier (e.g., "tmi-ux", "tmi-cli") Maximum total size: 1KB, maximum 20 client entries

func (*UserPreference) BeforeCreate

func (u *UserPreference) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (UserPreference) TableName

func (UserPreference) TableName() string

TableName specifies the table name for UserPreference

type WebhookDelivery

type WebhookDelivery struct {
	ID             string  `gorm:"primaryKey;type:varchar(36)"`
	SubscriptionID string  `gorm:"type:varchar(36);not null;index"`
	EventType      string  `gorm:"type:varchar(1000);not null"`
	Payload        JSONRaw `gorm:"not null"`
	Status         string  `gorm:"type:varchar(128);default:pending"`
	Attempts       int     `gorm:"default:0"`
	NextRetryAt    *time.Time
	LastError      *string   `gorm:"type:varchar(1000)"`
	CreatedAt      time.Time `gorm:"not null;autoCreateTime"`
	DeliveredAt    *time.Time

	// Relationships
	Subscription WebhookSubscription `gorm:"foreignKey:SubscriptionID"`
}

WebhookDelivery represents a webhook delivery attempt Note: Explicit column tags removed for Oracle compatibility

func (*WebhookDelivery) BeforeCreate

func (w *WebhookDelivery) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*WebhookDelivery) BeforeSave

func (w *WebhookDelivery) BeforeSave(tx *gorm.DB) error

BeforeSave validates WebhookDelivery before create or update

func (WebhookDelivery) TableName

func (WebhookDelivery) TableName() string

TableName specifies the table name for WebhookDelivery

type WebhookQuota

type WebhookQuota struct {
	OwnerID                          string    `gorm:"primaryKey;type:varchar(36)"`
	MaxSubscriptions                 int       `gorm:"default:10"`
	MaxEventsPerMinute               int       `gorm:"default:12"`
	MaxSubscriptionRequestsPerMinute int       `gorm:"default:10"`
	MaxSubscriptionRequestsPerDay    int       `gorm:"default:20"`
	CreatedAt                        time.Time `gorm:"not null;autoCreateTime"`
	ModifiedAt                       time.Time `gorm:"not null;autoUpdateTime"`

	// Relationships
	Owner User `gorm:"foreignKey:OwnerID;references:InternalUUID"`
}

WebhookQuota represents per-user webhook quotas Note: Explicit column tags removed for Oracle compatibility

func (WebhookQuota) TableName

func (WebhookQuota) TableName() string

TableName specifies the table name for WebhookQuota

type WebhookSubscription

type WebhookSubscription struct {
	ID                  string      `gorm:"primaryKey;type:varchar(36)"`
	OwnerInternalUUID   string      `gorm:"type:varchar(36);not null;index"`
	ThreatModelID       *string     `gorm:"type:varchar(36);index"`
	Name                string      `gorm:"type:varchar(256);not null"`
	URL                 string      `gorm:"type:varchar(1024);not null"`
	Events              StringArray `gorm:"not null"`
	Secret              *string     `gorm:"type:varchar(128)"` //nolint:gosec // G117 - webhook HMAC signing secret
	Status              string      `gorm:"type:varchar(128);default:pending_verification"`
	Challenge           *string     `gorm:"type:varchar(1000)"`
	ChallengesSent      int         `gorm:"default:0"`
	TimeoutCount        int         `gorm:"default:0"`
	CreatedAt           time.Time   `gorm:"not null;autoCreateTime"`
	ModifiedAt          time.Time   `gorm:"not null;autoUpdateTime"`
	LastSuccessfulUse   *time.Time
	PublicationFailures int `gorm:"default:0"`

	// Relationships
	Owner       User         `gorm:"foreignKey:OwnerInternalUUID;references:InternalUUID"`
	ThreatModel *ThreatModel `gorm:"foreignKey:ThreatModelID"`
}

WebhookSubscription represents a webhook subscription Note: Explicit column tags removed for Oracle compatibility

func (*WebhookSubscription) BeforeCreate

func (w *WebhookSubscription) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*WebhookSubscription) BeforeSave

func (w *WebhookSubscription) BeforeSave(tx *gorm.DB) error

BeforeSave validates WebhookSubscription before create or update

func (WebhookSubscription) TableName

func (WebhookSubscription) TableName() string

TableName specifies the table name for WebhookSubscription

type WebhookURLDenyList

type WebhookURLDenyList struct {
	ID          string    `gorm:"primaryKey;type:varchar(36)"`
	Pattern     string    `gorm:"type:varchar(256);not null"`
	PatternType string    `gorm:"type:varchar(64);not null"`
	Description *string   `gorm:"type:varchar(2048)"`
	CreatedAt   time.Time `gorm:"not null;autoCreateTime"`
}

WebhookURLDenyList represents URL patterns blocked for webhooks Note: Explicit column tags removed for Oracle compatibility

func (*WebhookURLDenyList) BeforeCreate

func (w *WebhookURLDenyList) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID if not set

func (*WebhookURLDenyList) BeforeSave

func (w *WebhookURLDenyList) BeforeSave(tx *gorm.DB) error

BeforeSave validates WebhookURLDenyList before create or update

func (WebhookURLDenyList) TableName

func (WebhookURLDenyList) TableName() string

TableName specifies the table name for WebhookURLDenyList

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL