migrate

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 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 (
	// WorkflowHistoryColumns holds the columns for the "workflow_history" table.
	WorkflowHistoryColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "from_state", Type: field.TypeString, Size: 64},
		{Name: "to_state", Type: field.TypeString, Size: 64},
		{Name: "uid", Type: field.TypeInt, Default: 0, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "comment", Type: field.TypeString, Size: 2147483647, SchemaType: map[string]string{"mysql": "text"}},
		{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
		{Name: "nid", Type: field.TypeInt, SchemaType: map[string]string{"mysql": "int unsigned"}},
	}
	// WorkflowHistoryTable holds the schema information for the "workflow_history" table.
	WorkflowHistoryTable = &schema.Table{
		Name:       "workflow_history",
		Columns:    WorkflowHistoryColumns,
		PrimaryKey: []*schema.Column{WorkflowHistoryColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_history_nodes_node",
				Columns:    []*schema.Column{WorkflowHistoryColumns[6]},
				RefColumns: []*schema.Column{NodesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "workflow_history_nid",
				Unique:  false,
				Columns: []*schema.Column{WorkflowHistoryColumns[6], WorkflowHistoryColumns[5]},
			},
		},
	}
	// WorkflowLocksColumns holds the columns for the "workflow_locks" table.
	WorkflowLocksColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "uid", Type: field.TypeInt, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "locked_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
		{Name: "touched_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
		{Name: "nid", Type: field.TypeInt, SchemaType: map[string]string{"mysql": "int unsigned"}},
	}
	// WorkflowLocksTable holds the schema information for the "workflow_locks" table.
	WorkflowLocksTable = &schema.Table{
		Name:       "workflow_locks",
		Columns:    WorkflowLocksColumns,
		PrimaryKey: []*schema.Column{WorkflowLocksColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_locks_nodes_node",
				Columns:    []*schema.Column{WorkflowLocksColumns[4]},
				RefColumns: []*schema.Column{NodesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "workflow_locks_nid",
				Unique:  true,
				Columns: []*schema.Column{WorkflowLocksColumns[4]},
			},
		},
	}
	// NodesColumns holds the columns for the "nodes" table.
	NodesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
	}
	// NodesTable holds the schema information for the "nodes" table.
	NodesTable = &schema.Table{
		Name:       "nodes",
		Columns:    NodesColumns,
		PrimaryKey: []*schema.Column{NodesColumns[0]},
	}
	// WorkflowNodeStatesColumns holds the columns for the "workflow_node_states" table.
	WorkflowNodeStatesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "state", Type: field.TypeString, Size: 64},
		{Name: "changed_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
		{Name: "changed_by", Type: field.TypeInt, Default: 0, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "nid", Type: field.TypeInt, SchemaType: map[string]string{"mysql": "int unsigned"}},
	}
	// WorkflowNodeStatesTable holds the schema information for the "workflow_node_states" table.
	WorkflowNodeStatesTable = &schema.Table{
		Name:       "workflow_node_states",
		Columns:    WorkflowNodeStatesColumns,
		PrimaryKey: []*schema.Column{WorkflowNodeStatesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_node_states_nodes_node",
				Columns:    []*schema.Column{WorkflowNodeStatesColumns[4]},
				RefColumns: []*schema.Column{NodesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "workflow_node_states_nid",
				Unique:  true,
				Columns: []*schema.Column{WorkflowNodeStatesColumns[4]},
			},
			{
				Name:    "workflow_node_states_state",
				Unique:  false,
				Columns: []*schema.Column{WorkflowNodeStatesColumns[1], WorkflowNodeStatesColumns[2]},
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
	}
	// WorkflowUserSettingsColumns holds the columns for the "workflow_user_settings" table.
	WorkflowUserSettingsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "mail", Type: field.TypeBool, Default: true},
		{Name: "user_id", Type: field.TypeInt, SchemaType: map[string]string{"mysql": "int unsigned"}},
	}
	// WorkflowUserSettingsTable holds the schema information for the "workflow_user_settings" table.
	WorkflowUserSettingsTable = &schema.Table{
		Name:       "workflow_user_settings",
		Columns:    WorkflowUserSettingsColumns,
		PrimaryKey: []*schema.Column{WorkflowUserSettingsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_user_settings_users_user",
				Columns:    []*schema.Column{WorkflowUserSettingsColumns[2]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "workflow_user_settings_user",
				Unique:  true,
				Columns: []*schema.Column{WorkflowUserSettingsColumns[2]},
			},
		},
	}
	// WorkflowSettingsColumns holds the columns for the "workflow_settings" table.
	WorkflowSettingsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "content_types", Type: field.TypeJSON, Nullable: true},
		{Name: "lock_minutes", Type: field.TypeInt, Default: 30},
	}
	// WorkflowSettingsTable holds the schema information for the "workflow_settings" table.
	WorkflowSettingsTable = &schema.Table{
		Name:       "workflow_settings",
		Columns:    WorkflowSettingsColumns,
		PrimaryKey: []*schema.Column{WorkflowSettingsColumns[0]},
	}
	// WorkflowStatesColumns holds the columns for the "workflow_states" table.
	WorkflowStatesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "machine_name", Type: field.TypeString, Size: 64},
		{Name: "label", Type: field.TypeString, Size: 128},
		{Name: "published", Type: field.TypeBool, Default: false},
		{Name: "color", Type: field.TypeString, Size: 16, Default: "gray"},
		{Name: "initial", Type: field.TypeBool, Default: false},
		{Name: "weight", Type: field.TypeInt, Default: 0},
	}
	// WorkflowStatesTable holds the schema information for the "workflow_states" table.
	WorkflowStatesTable = &schema.Table{
		Name:       "workflow_states",
		Columns:    WorkflowStatesColumns,
		PrimaryKey: []*schema.Column{WorkflowStatesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "workflow_states_machine_name",
				Unique:  true,
				Columns: []*schema.Column{WorkflowStatesColumns[1]},
			},
		},
	}
	// WorkflowTransitionsColumns holds the columns for the "workflow_transitions" table.
	WorkflowTransitionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"mysql": "int unsigned"}},
		{Name: "from_states", Type: field.TypeJSON},
		{Name: "to_state", Type: field.TypeString, Size: 64},
		{Name: "label", Type: field.TypeString, Size: 128},
		{Name: "roles", Type: field.TypeJSON},
		{Name: "comment", Type: field.TypeString, Size: 16, Default: "optional"},
		{Name: "weight", Type: field.TypeInt, Default: 0},
	}
	// WorkflowTransitionsTable holds the schema information for the "workflow_transitions" table.
	WorkflowTransitionsTable = &schema.Table{
		Name:       "workflow_transitions",
		Columns:    WorkflowTransitionsColumns,
		PrimaryKey: []*schema.Column{WorkflowTransitionsColumns[0]},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		WorkflowHistoryTable,
		WorkflowLocksTable,
		NodesTable,
		WorkflowNodeStatesTable,
		UsersTable,
		WorkflowUserSettingsTable,
		WorkflowSettingsTable,
		WorkflowStatesTable,
		WorkflowTransitionsTable,
	}
)

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