migrate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 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 (
	// CasbinPoliciesColumns holds the columns for the "casbin_policies" table.
	CasbinPoliciesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "ptype", Type: field.TypeString, Size: 10},
		{Name: "v0", Type: field.TypeString, Nullable: true},
		{Name: "v1", Type: field.TypeString, Nullable: true},
		{Name: "v2", Type: field.TypeString, Nullable: true},
		{Name: "v3", Type: field.TypeString, Nullable: true},
		{Name: "v4", Type: field.TypeString, Nullable: true},
		{Name: "v5", Type: field.TypeString, Nullable: true},
	}
	// CasbinPoliciesTable holds the schema information for the "casbin_policies" table.
	CasbinPoliciesTable = &schema.Table{
		Name:       "casbin_policies",
		Columns:    CasbinPoliciesColumns,
		PrimaryKey: []*schema.Column{CasbinPoliciesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "casbinpolicy_ptype",
				Unique:  false,
				Columns: []*schema.Column{CasbinPoliciesColumns[1]},
			},
			{
				Name:    "casbinpolicy_ptype_v0_v1_v2_v3_v4_v5",
				Unique:  false,
				Columns: []*schema.Column{CasbinPoliciesColumns[1], CasbinPoliciesColumns[2], CasbinPoliciesColumns[3], CasbinPoliciesColumns[4], CasbinPoliciesColumns[5], CasbinPoliciesColumns[6], CasbinPoliciesColumns[7]},
			},
		},
	}
	// MediaColumns holds the columns for the "media" table.
	MediaColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "tenant_id", Type: field.TypeString, Default: "default"},
		{Name: "created_by_id", Type: field.TypeUUID, Nullable: true, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "created_at", Type: field.TypeTime, Nullable: true},
		{Name: "updated_by_id", Type: field.TypeUUID, Nullable: true, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "updated_at", Type: field.TypeTime, Nullable: true},
		{Name: "deleted_by_id", Type: field.TypeUUID, Nullable: true, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "published_at", Type: field.TypeTime, Nullable: true},
		{Name: "archived_at", Type: field.TypeTime, Nullable: true},
		{Name: "name", Type: field.TypeString},
		{Name: "alternative_text", Type: field.TypeString, Nullable: true},
		{Name: "caption", Type: field.TypeString, Nullable: true},
		{Name: "width", Type: field.TypeInt, Nullable: true},
		{Name: "height", Type: field.TypeInt, Nullable: true},
		{Name: "hash", Type: field.TypeString, Nullable: true},
		{Name: "ext", Type: field.TypeString, Nullable: true},
		{Name: "mime", Type: field.TypeString, Nullable: true},
		{Name: "size", Type: field.TypeFloat64, Nullable: true},
		{Name: "url", Type: field.TypeString},
		{Name: "preview_url", Type: field.TypeString, Nullable: true},
		{Name: "provider", Type: field.TypeString, Nullable: true},
		{Name: "provider_metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "folder_path", Type: field.TypeString, Nullable: true},
		{Name: "locale", Type: field.TypeString, Nullable: true},
		{Name: "is_url_signed", Type: field.TypeBool, Nullable: true},
	}
	// MediaTable holds the schema information for the "media" table.
	MediaTable = &schema.Table{
		Name:       "media",
		Columns:    MediaColumns,
		PrimaryKey: []*schema.Column{MediaColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "media_id",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[0]},
			},
			{
				Name:    "media_tenant_id",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[1]},
			},
			{
				Name:    "media_deleted_at",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[7]},
			},
			{
				Name:    "media_created_at",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[3]},
			},
			{
				Name:    "media_updated_at",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[5]},
			},
			{
				Name:    "media_published_at",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[8]},
			},
			{
				Name:    "media_hash",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[15]},
			},
			{
				Name:    "media_folder_path",
				Unique:  false,
				Columns: []*schema.Column{MediaColumns[23]},
			},
		},
	}
	// MediaFormatsColumns holds the columns for the "media_formats" table.
	MediaFormatsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "tenant_id", Type: field.TypeString, Default: "default"},
		{Name: "created_by_id", Type: field.TypeUUID, Nullable: true, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "created_at", Type: field.TypeTime, Nullable: true},
		{Name: "updated_by_id", Type: field.TypeUUID, Nullable: true, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "updated_at", Type: field.TypeTime, Nullable: true},
		{Name: "deleted_by_id", Type: field.TypeUUID, Nullable: true, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "published_at", Type: field.TypeTime, Nullable: true},
		{Name: "archived_at", Type: field.TypeTime, Nullable: true},
		{Name: "name", Type: field.TypeString},
		{Name: "ext", Type: field.TypeString, Nullable: true},
		{Name: "url", Type: field.TypeString},
		{Name: "hash", Type: field.TypeString, Nullable: true},
		{Name: "mime", Type: field.TypeString, Nullable: true},
		{Name: "size", Type: field.TypeFloat64, Nullable: true},
		{Name: "size_in_bytes", Type: field.TypeInt64, Nullable: true},
		{Name: "width", Type: field.TypeInt, Nullable: true},
		{Name: "height", Type: field.TypeInt, Nullable: true},
		{Name: "provider_metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "path", Type: field.TypeString, Nullable: true},
		{Name: "is_url_signed", Type: field.TypeBool, Nullable: true},
		{Name: "media_id", Type: field.TypeUUID, Nullable: true, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "uuid", "sqlite3": "text"}},
	}
	// MediaFormatsTable holds the schema information for the "media_formats" table.
	MediaFormatsTable = &schema.Table{
		Name:       "media_formats",
		Columns:    MediaFormatsColumns,
		PrimaryKey: []*schema.Column{MediaFormatsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "media_formats_media_formats",
				Columns:    []*schema.Column{MediaFormatsColumns[22]},
				RefColumns: []*schema.Column{MediaColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "mediaformat_id",
				Unique:  false,
				Columns: []*schema.Column{MediaFormatsColumns[0]},
			},
			{
				Name:    "mediaformat_tenant_id",
				Unique:  false,
				Columns: []*schema.Column{MediaFormatsColumns[1]},
			},
			{
				Name:    "mediaformat_deleted_at",
				Unique:  false,
				Columns: []*schema.Column{MediaFormatsColumns[7]},
			},
			{
				Name:    "mediaformat_created_at",
				Unique:  false,
				Columns: []*schema.Column{MediaFormatsColumns[3]},
			},
			{
				Name:    "mediaformat_updated_at",
				Unique:  false,
				Columns: []*schema.Column{MediaFormatsColumns[5]},
			},
			{
				Name:    "mediaformat_published_at",
				Unique:  false,
				Columns: []*schema.Column{MediaFormatsColumns[8]},
			},
			{
				Name:    "mediaformat_media_id_hash",
				Unique:  true,
				Columns: []*schema.Column{MediaFormatsColumns[22], MediaFormatsColumns[13]},
			},
			{
				Name:    "mediaformat_name",
				Unique:  false,
				Columns: []*schema.Column{MediaFormatsColumns[10]},
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		CasbinPoliciesTable,
		MediaTable,
		MediaFormatsTable,
	}
)

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