migrate

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// WithGlobalUniqueID sets the universal ids options to the migration.
	// If this option is enabled, ent migration will allocate a 1<<32 range
	// for the ids of each entity (table).
	// Note that this option cannot be applied on tables that already exist.
	WithGlobalUniqueID = schema.WithGlobalUniqueID
	// WithDropColumn sets the drop column option to the migration.
	// If this option is enabled, ent migration will drop old columns
	// that were used for both fields and edges. This defaults to false.
	WithDropColumn = schema.WithDropColumn
	// WithDropIndex sets the drop index option to the migration.
	// If this option is enabled, ent migration will drop old indexes
	// that were defined in the schema. This defaults to false.
	// Note that unique constraints are defined using `UNIQUE INDEX`,
	// and therefore, it's recommended to enable this option to get more
	// flexibility in the schema changes.
	WithDropIndex = schema.WithDropIndex
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// AgentEventsColumns holds the columns for the "agent_events" table.
	AgentEventsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "event_type", Type: field.TypeString},
		{Name: "event_category", Type: field.TypeString, Default: "agent"},
		{Name: "agent_id", Type: field.TypeString, Nullable: true},
		{Name: "trace_id", Type: field.TypeString, Nullable: true},
		{Name: "span_id", Type: field.TypeString, Nullable: true},
		{Name: "severity", Type: field.TypeString, Default: "info"},
		{Name: "data", Type: field.TypeJSON, Nullable: true},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "tags", Type: field.TypeJSON, Nullable: true},
		{Name: "source", Type: field.TypeString, Nullable: true},
		{Name: "version", Type: field.TypeString, Default: "1.0"},
		{Name: "timestamp", Type: field.TypeTime},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "task_id", Type: field.TypeString, Nullable: true},
		{Name: "workflow_id", Type: field.TypeString, Nullable: true},
	}
	// AgentEventsTable holds the schema information for the "agent_events" table.
	AgentEventsTable = &schema.Table{
		Name:       "agent_events",
		Columns:    AgentEventsColumns,
		PrimaryKey: []*schema.Column{AgentEventsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "agent_events_agent_tasks_events",
				Columns:    []*schema.Column{AgentEventsColumns[14]},
				RefColumns: []*schema.Column{AgentTasksColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "agent_events_workflows_events",
				Columns:    []*schema.Column{AgentEventsColumns[15]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "agentevent_event_type",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[1]},
			},
			{
				Name:    "agentevent_event_category",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[2]},
			},
			{
				Name:    "agentevent_workflow_id",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[15]},
			},
			{
				Name:    "agentevent_task_id",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[14]},
			},
			{
				Name:    "agentevent_agent_id",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[3]},
			},
			{
				Name:    "agentevent_trace_id",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[4]},
			},
			{
				Name:    "agentevent_severity",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[6]},
			},
			{
				Name:    "agentevent_timestamp",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[12]},
			},
			{
				Name:    "agentevent_event_type_timestamp",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[1], AgentEventsColumns[12]},
			},
			{
				Name:    "agentevent_agent_id_event_type",
				Unique:  false,
				Columns: []*schema.Column{AgentEventsColumns[3], AgentEventsColumns[1]},
			},
		},
	}
	// AgentHandoffsColumns holds the columns for the "agent_handoffs" table.
	AgentHandoffsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "from_agent_id", Type: field.TypeString},
		{Name: "from_agent_type", Type: field.TypeString, Nullable: true},
		{Name: "to_agent_id", Type: field.TypeString},
		{Name: "to_agent_type", Type: field.TypeString, Nullable: true},
		{Name: "handoff_type", Type: field.TypeString, Default: "request"},
		{Name: "status", Type: field.TypeString, Default: "pending"},
		{Name: "trace_id", Type: field.TypeString, Nullable: true},
		{Name: "from_task_id", Type: field.TypeString, Nullable: true},
		{Name: "to_task_id", Type: field.TypeString, Nullable: true},
		{Name: "payload", Type: field.TypeJSON, Nullable: true},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "payload_size_bytes", Type: field.TypeInt, Default: 0},
		{Name: "latency_ms", Type: field.TypeInt64, Nullable: true},
		{Name: "error_message", Type: field.TypeString, Nullable: true},
		{Name: "initiated_at", Type: field.TypeTime},
		{Name: "accepted_at", Type: field.TypeTime, Nullable: true},
		{Name: "completed_at", Type: field.TypeTime, Nullable: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "workflow_id", Type: field.TypeString, Nullable: true},
	}
	// AgentHandoffsTable holds the schema information for the "agent_handoffs" table.
	AgentHandoffsTable = &schema.Table{
		Name:       "agent_handoffs",
		Columns:    AgentHandoffsColumns,
		PrimaryKey: []*schema.Column{AgentHandoffsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "agent_handoffs_workflows_handoffs",
				Columns:    []*schema.Column{AgentHandoffsColumns[20]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "agenthandoff_workflow_id",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[20]},
			},
			{
				Name:    "agenthandoff_from_agent_id",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[1]},
			},
			{
				Name:    "agenthandoff_to_agent_id",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[3]},
			},
			{
				Name:    "agenthandoff_handoff_type",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[5]},
			},
			{
				Name:    "agenthandoff_status",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[6]},
			},
			{
				Name:    "agenthandoff_trace_id",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[7]},
			},
			{
				Name:    "agenthandoff_initiated_at",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[15]},
			},
			{
				Name:    "agenthandoff_from_agent_id_to_agent_id",
				Unique:  false,
				Columns: []*schema.Column{AgentHandoffsColumns[1], AgentHandoffsColumns[3]},
			},
		},
	}
	// AgentTasksColumns holds the columns for the "agent_tasks" table.
	AgentTasksColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "agent_id", Type: field.TypeString},
		{Name: "agent_type", Type: field.TypeString, Nullable: true},
		{Name: "task_type", Type: field.TypeString},
		{Name: "name", Type: field.TypeString},
		{Name: "status", Type: field.TypeString, Default: "running"},
		{Name: "trace_id", Type: field.TypeString, Nullable: true},
		{Name: "span_id", Type: field.TypeString, Nullable: true},
		{Name: "parent_span_id", Type: field.TypeString, Nullable: true},
		{Name: "input", Type: field.TypeJSON, Nullable: true},
		{Name: "output", Type: field.TypeJSON, Nullable: true},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "llm_call_count", Type: field.TypeInt, Default: 0},
		{Name: "tool_call_count", Type: field.TypeInt, Default: 0},
		{Name: "retry_count", Type: field.TypeInt, Default: 0},
		{Name: "tokens_prompt", Type: field.TypeInt, Default: 0},
		{Name: "tokens_completion", Type: field.TypeInt, Default: 0},
		{Name: "tokens_total", Type: field.TypeInt, Default: 0},
		{Name: "cost_usd", Type: field.TypeFloat64, Default: 0},
		{Name: "duration_ms", Type: field.TypeInt64, Nullable: true},
		{Name: "error_type", Type: field.TypeString, Nullable: true},
		{Name: "error_message", Type: field.TypeString, Nullable: true},
		{Name: "started_at", Type: field.TypeTime},
		{Name: "ended_at", Type: field.TypeTime, Nullable: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "workflow_id", Type: field.TypeString, Nullable: true},
	}
	// AgentTasksTable holds the schema information for the "agent_tasks" table.
	AgentTasksTable = &schema.Table{
		Name:       "agent_tasks",
		Columns:    AgentTasksColumns,
		PrimaryKey: []*schema.Column{AgentTasksColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "agent_tasks_workflows_tasks",
				Columns:    []*schema.Column{AgentTasksColumns[26]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "agenttask_workflow_id",
				Unique:  false,
				Columns: []*schema.Column{AgentTasksColumns[26]},
			},
			{
				Name:    "agenttask_agent_id",
				Unique:  false,
				Columns: []*schema.Column{AgentTasksColumns[1]},
			},
			{
				Name:    "agenttask_agent_type",
				Unique:  false,
				Columns: []*schema.Column{AgentTasksColumns[2]},
			},
			{
				Name:    "agenttask_task_type",
				Unique:  false,
				Columns: []*schema.Column{AgentTasksColumns[3]},
			},
			{
				Name:    "agenttask_status",
				Unique:  false,
				Columns: []*schema.Column{AgentTasksColumns[5]},
			},
			{
				Name:    "agenttask_trace_id",
				Unique:  false,
				Columns: []*schema.Column{AgentTasksColumns[6]},
			},
			{
				Name:    "agenttask_started_at",
				Unique:  false,
				Columns: []*schema.Column{AgentTasksColumns[22]},
			},
		},
	}
	// ToolInvocationsColumns holds the columns for the "tool_invocations" table.
	ToolInvocationsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "agent_id", Type: field.TypeString},
		{Name: "tool_name", Type: field.TypeString},
		{Name: "tool_type", Type: field.TypeString, Nullable: true},
		{Name: "status", Type: field.TypeString, Default: "running"},
		{Name: "trace_id", Type: field.TypeString, Nullable: true},
		{Name: "span_id", Type: field.TypeString, Nullable: true},
		{Name: "input", Type: field.TypeJSON, Nullable: true},
		{Name: "output", Type: field.TypeJSON, Nullable: true},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "http_method", Type: field.TypeString, Nullable: true},
		{Name: "http_url", Type: field.TypeString, Nullable: true},
		{Name: "http_status_code", Type: field.TypeInt, Nullable: true},
		{Name: "duration_ms", Type: field.TypeInt64, Nullable: true},
		{Name: "request_size_bytes", Type: field.TypeInt, Default: 0},
		{Name: "response_size_bytes", Type: field.TypeInt, Default: 0},
		{Name: "retry_count", Type: field.TypeInt, Default: 0},
		{Name: "error_type", Type: field.TypeString, Nullable: true},
		{Name: "error_message", Type: field.TypeString, Nullable: true},
		{Name: "started_at", Type: field.TypeTime},
		{Name: "ended_at", Type: field.TypeTime, Nullable: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "task_id", Type: field.TypeString, Nullable: true},
	}
	// ToolInvocationsTable holds the schema information for the "tool_invocations" table.
	ToolInvocationsTable = &schema.Table{
		Name:       "tool_invocations",
		Columns:    ToolInvocationsColumns,
		PrimaryKey: []*schema.Column{ToolInvocationsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "tool_invocations_agent_tasks_tool_invocations",
				Columns:    []*schema.Column{ToolInvocationsColumns[23]},
				RefColumns: []*schema.Column{AgentTasksColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "toolinvocation_task_id",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[23]},
			},
			{
				Name:    "toolinvocation_agent_id",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[1]},
			},
			{
				Name:    "toolinvocation_tool_name",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[2]},
			},
			{
				Name:    "toolinvocation_tool_type",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[3]},
			},
			{
				Name:    "toolinvocation_status",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[4]},
			},
			{
				Name:    "toolinvocation_trace_id",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[5]},
			},
			{
				Name:    "toolinvocation_started_at",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[19]},
			},
			{
				Name:    "toolinvocation_http_url",
				Unique:  false,
				Columns: []*schema.Column{ToolInvocationsColumns[11]},
			},
		},
	}
	// WorkflowsColumns holds the columns for the "workflows" table.
	WorkflowsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "status", Type: field.TypeString, Default: "running"},
		{Name: "trace_id", Type: field.TypeString, Nullable: true},
		{Name: "parent_workflow_id", Type: field.TypeString, Nullable: true},
		{Name: "initiator", Type: field.TypeString, Nullable: true},
		{Name: "input", Type: field.TypeJSON, Nullable: true},
		{Name: "output", Type: field.TypeJSON, Nullable: true},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "task_count", Type: field.TypeInt, Default: 0},
		{Name: "completed_task_count", Type: field.TypeInt, Default: 0},
		{Name: "failed_task_count", Type: field.TypeInt, Default: 0},
		{Name: "total_cost_usd", Type: field.TypeFloat64, Default: 0},
		{Name: "total_tokens", Type: field.TypeInt, Default: 0},
		{Name: "duration_ms", Type: field.TypeInt64, Nullable: true},
		{Name: "error_message", Type: field.TypeString, Nullable: true},
		{Name: "started_at", Type: field.TypeTime},
		{Name: "ended_at", Type: field.TypeTime, Nullable: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
	}
	// WorkflowsTable holds the schema information for the "workflows" table.
	WorkflowsTable = &schema.Table{
		Name:       "workflows",
		Columns:    WorkflowsColumns,
		PrimaryKey: []*schema.Column{WorkflowsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "workflow_name",
				Unique:  false,
				Columns: []*schema.Column{WorkflowsColumns[1]},
			},
			{
				Name:    "workflow_status",
				Unique:  false,
				Columns: []*schema.Column{WorkflowsColumns[2]},
			},
			{
				Name:    "workflow_trace_id",
				Unique:  false,
				Columns: []*schema.Column{WorkflowsColumns[3]},
			},
			{
				Name:    "workflow_started_at",
				Unique:  false,
				Columns: []*schema.Column{WorkflowsColumns[16]},
			},
			{
				Name:    "workflow_initiator",
				Unique:  false,
				Columns: []*schema.Column{WorkflowsColumns[5]},
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AgentEventsTable,
		AgentHandoffsTable,
		AgentTasksTable,
		ToolInvocationsTable,
		WorkflowsTable,
	}
)

Functions

func Create

func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error

Create creates all table resources using the given schema driver.

Types

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema is the API for creating, migrating and dropping a schema.

func NewSchema

func NewSchema(drv dialect.Driver) *Schema

NewSchema creates a new schema client.

func (*Schema) Create

func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error

Create creates all schema resources.

func (*Schema) WriteTo

func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error

WriteTo writes the schema changes to w instead of running them against the database.

if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
	log.Fatal(err)
}

Jump to

Keyboard shortcuts

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