migrate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 6 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 (
	// RootCausesColumns holds the columns for the "root_causes" table.
	RootCausesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString},
		{Name: "title", Type: field.TypeString},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "status", Type: field.TypeString},
		{Name: "domain_name", Type: field.TypeString},
		{Name: "domain_subdomain", Type: field.TypeString, Nullable: true},
		{Name: "domain_team", Type: field.TypeString, Nullable: true},
		{Name: "severity", Type: field.TypeString},
		{Name: "symptom_patterns", Type: field.TypeJSON, Nullable: true},
		{Name: "impact_signal_count", Type: field.TypeInt, Default: 0},
		{Name: "impact_affected_customers", Type: field.TypeInt, Default: 0},
		{Name: "impact_affected_entities", Type: field.TypeJSON, Nullable: true},
		{Name: "impact_escalation_rate", Type: field.TypeFloat64, Default: 0},
		{Name: "impact_estimated_revenue_loss", Type: field.TypeFloat64, Default: 0},
		{Name: "trend_direction", Type: field.TypeString, Nullable: true},
		{Name: "trend_velocity", Type: field.TypeFloat64, Default: 0},
		{Name: "trend_period_start", Type: field.TypeTime, Nullable: true},
		{Name: "trend_period_end", Type: field.TypeTime, Nullable: true},
		{Name: "priority_score", Type: field.TypeInt, Default: 0},
		{Name: "first_seen", Type: field.TypeTime},
		{Name: "last_seen", Type: field.TypeTime},
		{Name: "owner_team", Type: field.TypeString, Nullable: true},
		{Name: "remediation_id", Type: field.TypeString, Nullable: true},
		{Name: "recurrence_count", Type: field.TypeInt, Default: 0},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "tags", Type: field.TypeJSON, Nullable: true},
	}
	// RootCausesTable holds the schema information for the "root_causes" table.
	RootCausesTable = &schema.Table{
		Name:       "root_causes",
		Columns:    RootCausesColumns,
		PrimaryKey: []*schema.Column{RootCausesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "rootcause_status",
				Unique:  false,
				Columns: []*schema.Column{RootCausesColumns[3]},
			},
			{
				Name:    "rootcause_domain_name",
				Unique:  false,
				Columns: []*schema.Column{RootCausesColumns[4]},
			},
			{
				Name:    "rootcause_first_seen",
				Unique:  false,
				Columns: []*schema.Column{RootCausesColumns[19]},
			},
			{
				Name:    "rootcause_status_first_seen",
				Unique:  false,
				Columns: []*schema.Column{RootCausesColumns[3], RootCausesColumns[19]},
			},
		},
	}
	// SignalsColumns holds the columns for the "signals" table.
	SignalsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString},
		{Name: "type", Type: field.TypeString},
		{Name: "status", Type: field.TypeString},
		{Name: "source_type", Type: field.TypeString},
		{Name: "source_name", Type: field.TypeString},
		{Name: "source_external_id", Type: field.TypeString, Nullable: true},
		{Name: "source_url", Type: field.TypeString, Nullable: true},
		{Name: "domain_name", Type: field.TypeString},
		{Name: "domain_subdomain", Type: field.TypeString, Nullable: true},
		{Name: "domain_team", Type: field.TypeString, Nullable: true},
		{Name: "severity", Type: field.TypeString},
		{Name: "summary", Type: field.TypeString},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "entities", Type: field.TypeJSON, Nullable: true},
		{Name: "observed_at", Type: field.TypeTime},
		{Name: "received_at", Type: field.TypeTime},
		{Name: "fingerprint", Type: field.TypeString, Nullable: true},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "derived", Type: field.TypeJSON, Nullable: true},
		{Name: "tags", Type: field.TypeJSON, Nullable: true},
	}
	// SignalsTable holds the schema information for the "signals" table.
	SignalsTable = &schema.Table{
		Name:       "signals",
		Columns:    SignalsColumns,
		PrimaryKey: []*schema.Column{SignalsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "signal_fingerprint",
				Unique:  true,
				Columns: []*schema.Column{SignalsColumns[16]},
			},
			{
				Name:    "signal_status",
				Unique:  false,
				Columns: []*schema.Column{SignalsColumns[2]},
			},
			{
				Name:    "signal_domain_name",
				Unique:  false,
				Columns: []*schema.Column{SignalsColumns[7]},
			},
			{
				Name:    "signal_received_at",
				Unique:  false,
				Columns: []*schema.Column{SignalsColumns[15]},
			},
			{
				Name:    "signal_status_domain_name",
				Unique:  false,
				Columns: []*schema.Column{SignalsColumns[2], SignalsColumns[7]},
			},
		},
	}
	// SignalRootCauseLinksColumns holds the columns for the "signal_root_cause_links" table.
	SignalRootCauseLinksColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "signal_id", Type: field.TypeString},
		{Name: "root_cause_id", Type: field.TypeString},
		{Name: "linked_at", Type: field.TypeTime},
	}
	// SignalRootCauseLinksTable holds the schema information for the "signal_root_cause_links" table.
	SignalRootCauseLinksTable = &schema.Table{
		Name:       "signal_root_cause_links",
		Columns:    SignalRootCauseLinksColumns,
		PrimaryKey: []*schema.Column{SignalRootCauseLinksColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "signalrootcauselink_signal_id",
				Unique:  true,
				Columns: []*schema.Column{SignalRootCauseLinksColumns[1]},
			},
			{
				Name:    "signalrootcauselink_root_cause_id",
				Unique:  false,
				Columns: []*schema.Column{SignalRootCauseLinksColumns[2]},
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		RootCausesTable,
		SignalsTable,
		SignalRootCauseLinksTable,
	}
)

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