migrate

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 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 (
	// AgentsColumns holds the columns for the "agents" table.
	AgentsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "peer_id", Type: field.TypeString, Unique: true},
		{Name: "active", Type: field.TypeBool, Default: true},
		{Name: "last_update_time", Type: field.TypeTime},
	}
	// AgentsTable holds the schema information for the "agents" table.
	AgentsTable = &schema.Table{
		Name:       "agents",
		Columns:    AgentsColumns,
		PrimaryKey: []*schema.Column{AgentsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "agent_id",
				Unique:  true,
				Columns: []*schema.Column{AgentsColumns[0]},
			},
		},
	}
	// ComputeImagesColumns holds the columns for the "compute_images" table.
	ComputeImagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt32, Increment: true},
		{Name: "name", Type: field.TypeString},
		{Name: "image", Type: field.TypeString},
		{Name: "tag", Type: field.TypeString},
		{Name: "port", Type: field.TypeInt32},
		{Name: "command", Type: field.TypeString},
	}
	// ComputeImagesTable holds the schema information for the "compute_images" table.
	ComputeImagesTable = &schema.Table{
		Name:       "compute_images",
		Columns:    ComputeImagesColumns,
		PrimaryKey: []*schema.Column{ComputeImagesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "computeimage_id",
				Unique:  true,
				Columns: []*schema.Column{ComputeImagesColumns[0]},
			},
		},
	}
	// ComputeInstancesColumns holds the columns for the "compute_instances" table.
	ComputeInstancesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "owner", Type: field.TypeString},
		{Name: "name", Type: field.TypeString},
		{Name: "core", Type: field.TypeString},
		{Name: "memory", Type: field.TypeString},
		{Name: "image", Type: field.TypeString},
		{Name: "port", Type: field.TypeString, Nullable: true},
		{Name: "expiration_time", Type: field.TypeTime},
		{Name: "status", Type: field.TypeInt8},
		{Name: "container_id", Type: field.TypeString, Nullable: true},
		{Name: "peer_id", Type: field.TypeString, Nullable: true},
		{Name: "command", Type: field.TypeString, Nullable: true},
	}
	// ComputeInstancesTable holds the schema information for the "compute_instances" table.
	ComputeInstancesTable = &schema.Table{
		Name:       "compute_instances",
		Columns:    ComputeInstancesColumns,
		PrimaryKey: []*schema.Column{ComputeInstancesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "computeinstance_id",
				Unique:  true,
				Columns: []*schema.Column{ComputeInstancesColumns[0]},
			},
			{
				Name:    "computeinstance_owner",
				Unique:  false,
				Columns: []*schema.Column{ComputeInstancesColumns[1]},
			},
		},
	}
	// ComputeSpecsColumns holds the columns for the "compute_specs" table.
	ComputeSpecsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt32, Increment: true},
		{Name: "core", Type: field.TypeString},
		{Name: "memory", Type: field.TypeString},
	}
	// ComputeSpecsTable holds the schema information for the "compute_specs" table.
	ComputeSpecsTable = &schema.Table{
		Name:       "compute_specs",
		Columns:    ComputeSpecsColumns,
		PrimaryKey: []*schema.Column{ComputeSpecsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "computespec_id",
				Unique:  true,
				Columns: []*schema.Column{ComputeSpecsColumns[0]},
			},
		},
	}
	// EmployeesColumns holds the columns for the "employees" table.
	EmployeesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "name", Type: field.TypeString},
		{Name: "age", Type: field.TypeInt32, Nullable: true},
	}
	// EmployeesTable holds the schema information for the "employees" table.
	EmployeesTable = &schema.Table{
		Name:       "employees",
		Columns:    EmployeesColumns,
		PrimaryKey: []*schema.Column{EmployeesColumns[0]},
	}
	// ScriptsColumns holds the columns for the "scripts" table.
	ScriptsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt32, Increment: true},
		{Name: "user_id", Type: field.TypeString},
		{Name: "task_number", Type: field.TypeInt32},
		{Name: "script_name", Type: field.TypeString},
		{Name: "file_address", Type: field.TypeString},
		{Name: "script_content", Type: field.TypeString, Size: 2147483647},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
	}
	// ScriptsTable holds the schema information for the "scripts" table.
	ScriptsTable = &schema.Table{
		Name:       "scripts",
		Columns:    ScriptsColumns,
		PrimaryKey: []*schema.Column{ScriptsColumns[0]},
	}
	// ScriptExecutionRecordsColumns holds the columns for the "script_execution_records" table.
	ScriptExecutionRecordsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt32, Increment: true},
		{Name: "user_id", Type: field.TypeString},
		{Name: "fk_script_id", Type: field.TypeInt32},
		{Name: "script_content", Type: field.TypeString, Size: 2147483647},
		{Name: "task_number", Type: field.TypeInt32},
		{Name: "script_name", Type: field.TypeString},
		{Name: "file_address", Type: field.TypeString},
		{Name: "execute_state", Type: field.TypeInt32},
		{Name: "execute_result", Type: field.TypeString, Size: 2147483647},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "script_script_execution_records", Type: field.TypeInt32, Nullable: true},
	}
	// ScriptExecutionRecordsTable holds the schema information for the "script_execution_records" table.
	ScriptExecutionRecordsTable = &schema.Table{
		Name:       "script_execution_records",
		Columns:    ScriptExecutionRecordsColumns,
		PrimaryKey: []*schema.Column{ScriptExecutionRecordsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "script_execution_records_scripts_scriptExecutionRecords",
				Columns:    []*schema.Column{ScriptExecutionRecordsColumns[11]},
				RefColumns: []*schema.Column{ScriptsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// StoragesColumns holds the columns for the "storages" table.
	StoragesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "owner", Type: field.TypeString, Size: 50},
		{Name: "type", Type: field.TypeInt32, Default: 0},
		{Name: "name", Type: field.TypeString, Size: 50},
		{Name: "cid", Type: field.TypeString, Size: 80},
		{Name: "size", Type: field.TypeInt32},
		{Name: "last_modify", Type: field.TypeTime},
		{Name: "parent_id", Type: field.TypeString, Size: 80},
	}
	// StoragesTable holds the schema information for the "storages" table.
	StoragesTable = &schema.Table{
		Name:       "storages",
		Columns:    StoragesColumns,
		PrimaryKey: []*schema.Column{StoragesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "storage_owner",
				Unique:  false,
				Columns: []*schema.Column{StoragesColumns[1]},
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "country_call_coding", Type: field.TypeString, Size: 8},
		{Name: "telephone_number", Type: field.TypeString, Size: 50},
		{Name: "password", Type: field.TypeString},
		{Name: "create_date", Type: field.TypeTime},
		{Name: "last_login_date", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "icon", Type: field.TypeString},
		{Name: "pwd_config", Type: field.TypeBool, Default: false},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "user_id",
				Unique:  true,
				Columns: []*schema.Column{UsersColumns[0]},
			},
			{
				Name:    "user_country_call_coding_telephone_number",
				Unique:  true,
				Columns: []*schema.Column{UsersColumns[1], UsersColumns[2]},
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AgentsTable,
		ComputeImagesTable,
		ComputeInstancesTable,
		ComputeSpecsTable,
		EmployeesTable,
		ScriptsTable,
		ScriptExecutionRecordsTable,
		StoragesTable,
		UsersTable,
	}
)

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