migrate

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: Apache-2.0 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
	// WithFixture sets the foreign-key renaming option to the migration when upgrading
	// ent from v0.1.0 (issue-#285). Defaults to false.
	WithFixture = schema.WithFixture
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// CloudEventsColumns holds the columns for the "cloud_events" table.
	CloudEventsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "namespace", Type: field.TypeString},
		{Name: "event", Type: field.TypeJSON},
		{Name: "fire", Type: field.TypeTime},
		{Name: "created", Type: field.TypeTime},
		{Name: "processed", Type: field.TypeBool},
	}
	// CloudEventsTable holds the schema information for the "cloud_events" table.
	CloudEventsTable = &schema.Table{
		Name:       "cloud_events",
		Columns:    CloudEventsColumns,
		PrimaryKey: []*schema.Column{CloudEventsColumns[0]},
	}
	// NamespacesColumns holds the columns for the "namespaces" table.
	NamespacesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true, Size: 64},
		{Name: "created", Type: field.TypeTime},
	}
	// NamespacesTable holds the schema information for the "namespaces" table.
	NamespacesTable = &schema.Table{
		Name:       "namespaces",
		Columns:    NamespacesColumns,
		PrimaryKey: []*schema.Column{NamespacesColumns[0]},
	}
	// ServicesColumns holds the columns for the "services" table.
	ServicesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "data", Type: field.TypeString},
	}
	// ServicesTable holds the schema information for the "services" table.
	ServicesTable = &schema.Table{
		Name:       "services",
		Columns:    ServicesColumns,
		PrimaryKey: []*schema.Column{ServicesColumns[0]},
	}
	// WorkflowsColumns holds the columns for the "workflows" table.
	WorkflowsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "name", Type: field.TypeString},
		{Name: "created", Type: field.TypeTime},
		{Name: "description", Type: field.TypeString, Nullable: true, Size: 1024, Default: ""},
		{Name: "active", Type: field.TypeBool, Default: true},
		{Name: "revision", Type: field.TypeInt, Default: 0},
		{Name: "workflow", Type: field.TypeBytes},
		{Name: "log_to_events", Type: field.TypeString, Nullable: true},
		{Name: "namespace_workflows", Type: field.TypeString, Nullable: true, Size: 64},
	}
	// WorkflowsTable holds the schema information for the "workflows" table.
	WorkflowsTable = &schema.Table{
		Name:       "workflows",
		Columns:    WorkflowsColumns,
		PrimaryKey: []*schema.Column{WorkflowsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflows_namespaces_workflows",
				Columns:    []*schema.Column{WorkflowsColumns[8]},
				RefColumns: []*schema.Column{NamespacesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "workflow_name_namespace_workflows",
				Unique:  true,
				Columns: []*schema.Column{WorkflowsColumns[1], WorkflowsColumns[8]},
			},
		},
	}
	// WorkflowEventsColumns holds the columns for the "workflow_events" table.
	WorkflowEventsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "events", Type: field.TypeJSON},
		{Name: "correlations", Type: field.TypeJSON},
		{Name: "signature", Type: field.TypeBytes, Nullable: true},
		{Name: "count", Type: field.TypeInt},
		{Name: "workflow_wfevents", Type: field.TypeUUID, Nullable: true},
		{Name: "workflow_instance_instance", Type: field.TypeInt, Nullable: true},
	}
	// WorkflowEventsTable holds the schema information for the "workflow_events" table.
	WorkflowEventsTable = &schema.Table{
		Name:       "workflow_events",
		Columns:    WorkflowEventsColumns,
		PrimaryKey: []*schema.Column{WorkflowEventsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_events_workflows_wfevents",
				Columns:    []*schema.Column{WorkflowEventsColumns[5]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "workflow_events_workflow_instances_instance",
				Columns:    []*schema.Column{WorkflowEventsColumns[6]},
				RefColumns: []*schema.Column{WorkflowInstancesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// WorkflowEventsWaitsColumns holds the columns for the "workflow_events_waits" table.
	WorkflowEventsWaitsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "events", Type: field.TypeJSON},
		{Name: "workflow_events_wfeventswait", Type: field.TypeInt, Nullable: true},
	}
	// WorkflowEventsWaitsTable holds the schema information for the "workflow_events_waits" table.
	WorkflowEventsWaitsTable = &schema.Table{
		Name:       "workflow_events_waits",
		Columns:    WorkflowEventsWaitsColumns,
		PrimaryKey: []*schema.Column{WorkflowEventsWaitsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_events_waits_workflow_events_wfeventswait",
				Columns:    []*schema.Column{WorkflowEventsWaitsColumns[2]},
				RefColumns: []*schema.Column{WorkflowEventsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// WorkflowInstancesColumns holds the columns for the "workflow_instances" table.
	WorkflowInstancesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "instance_id", Type: field.TypeString, Unique: true},
		{Name: "invoked_by", Type: field.TypeString},
		{Name: "status", Type: field.TypeString},
		{Name: "revision", Type: field.TypeInt},
		{Name: "begin_time", Type: field.TypeTime},
		{Name: "end_time", Type: field.TypeTime, Nullable: true},
		{Name: "flow", Type: field.TypeJSON, Nullable: true},
		{Name: "input", Type: field.TypeString},
		{Name: "output", Type: field.TypeString, Nullable: true},
		{Name: "state_data", Type: field.TypeString, Nullable: true},
		{Name: "memory", Type: field.TypeString, Nullable: true},
		{Name: "deadline", Type: field.TypeTime, Nullable: true},
		{Name: "attempts", Type: field.TypeInt, Nullable: true},
		{Name: "error_code", Type: field.TypeString, Nullable: true},
		{Name: "error_message", Type: field.TypeString, Nullable: true},
		{Name: "state_begin_time", Type: field.TypeTime, Nullable: true},
		{Name: "controller", Type: field.TypeString, Nullable: true},
		{Name: "workflow_instances", Type: field.TypeUUID, Nullable: true},
	}
	// WorkflowInstancesTable holds the schema information for the "workflow_instances" table.
	WorkflowInstancesTable = &schema.Table{
		Name:       "workflow_instances",
		Columns:    WorkflowInstancesColumns,
		PrimaryKey: []*schema.Column{WorkflowInstancesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_instances_workflows_instances",
				Columns:    []*schema.Column{WorkflowInstancesColumns[18]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		CloudEventsTable,
		NamespacesTable,
		ServicesTable,
		WorkflowsTable,
		WorkflowEventsTable,
		WorkflowEventsWaitsTable,
		WorkflowInstancesTable,
	}
)

Functions

This section is empty.

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