migrate

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 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
	// 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 (
	// MailboxesColumns holds the columns for the "mailboxes" table.
	MailboxesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "mailbox_id", Type: field.TypeString},
		{Name: "name", Type: field.TypeString},
		{Name: "uid_next", Type: field.TypeInt, Default: 1},
		{Name: "uid_validity", Type: field.TypeInt, Default: 1},
		{Name: "subscribed", Type: field.TypeBool, Default: true},
	}
	// MailboxesTable holds the schema information for the "mailboxes" table.
	MailboxesTable = &schema.Table{
		Name:       "mailboxes",
		Columns:    MailboxesColumns,
		PrimaryKey: []*schema.Column{MailboxesColumns[0]},
	}
	// MailboxAttrsColumns holds the columns for the "mailbox_attrs" table.
	MailboxAttrsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "value", Type: field.TypeString},
		{Name: "mailbox_attributes", Type: field.TypeInt, Nullable: true},
	}
	// MailboxAttrsTable holds the schema information for the "mailbox_attrs" table.
	MailboxAttrsTable = &schema.Table{
		Name:       "mailbox_attrs",
		Columns:    MailboxAttrsColumns,
		PrimaryKey: []*schema.Column{MailboxAttrsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "mailbox_attrs_mailboxes_attributes",
				Columns:    []*schema.Column{MailboxAttrsColumns[2]},
				RefColumns: []*schema.Column{MailboxesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// MailboxFlagsColumns holds the columns for the "mailbox_flags" table.
	MailboxFlagsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "value", Type: field.TypeString},
		{Name: "mailbox_flags", Type: field.TypeInt, Nullable: true},
	}
	// MailboxFlagsTable holds the schema information for the "mailbox_flags" table.
	MailboxFlagsTable = &schema.Table{
		Name:       "mailbox_flags",
		Columns:    MailboxFlagsColumns,
		PrimaryKey: []*schema.Column{MailboxFlagsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "mailbox_flags_mailboxes_flags",
				Columns:    []*schema.Column{MailboxFlagsColumns[2]},
				RefColumns: []*schema.Column{MailboxesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// MailboxPermFlagsColumns holds the columns for the "mailbox_perm_flags" table.
	MailboxPermFlagsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "value", Type: field.TypeString},
		{Name: "mailbox_permanent_flags", Type: field.TypeInt, Nullable: true},
	}
	// MailboxPermFlagsTable holds the schema information for the "mailbox_perm_flags" table.
	MailboxPermFlagsTable = &schema.Table{
		Name:       "mailbox_perm_flags",
		Columns:    MailboxPermFlagsColumns,
		PrimaryKey: []*schema.Column{MailboxPermFlagsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "mailbox_perm_flags_mailboxes_permanent_flags",
				Columns:    []*schema.Column{MailboxPermFlagsColumns[2]},
				RefColumns: []*schema.Column{MailboxesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// MessagesColumns holds the columns for the "messages" table.
	MessagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "message_id", Type: field.TypeString, Unique: true},
		{Name: "internal_id", Type: field.TypeString, Unique: true},
		{Name: "date", Type: field.TypeTime},
		{Name: "size", Type: field.TypeInt},
		{Name: "body", Type: field.TypeString},
		{Name: "body_structure", Type: field.TypeString},
		{Name: "envelope", Type: field.TypeString},
	}
	// MessagesTable holds the schema information for the "messages" table.
	MessagesTable = &schema.Table{
		Name:       "messages",
		Columns:    MessagesColumns,
		PrimaryKey: []*schema.Column{MessagesColumns[0]},
	}
	// MessageFlagsColumns holds the columns for the "message_flags" table.
	MessageFlagsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "value", Type: field.TypeString},
		{Name: "message_flags", Type: field.TypeInt, Nullable: true},
	}
	// MessageFlagsTable holds the schema information for the "message_flags" table.
	MessageFlagsTable = &schema.Table{
		Name:       "message_flags",
		Columns:    MessageFlagsColumns,
		PrimaryKey: []*schema.Column{MessageFlagsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "message_flags_messages_flags",
				Columns:    []*schema.Column{MessageFlagsColumns[2]},
				RefColumns: []*schema.Column{MessagesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// UIDsColumns holds the columns for the "ui_ds" table.
	UIDsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "uid", Type: field.TypeInt},
		{Name: "deleted", Type: field.TypeBool, Default: false},
		{Name: "recent", Type: field.TypeBool, Default: true},
		{Name: "in_deletion_pool", Type: field.TypeBool, Default: false},
		{Name: "mailbox_ui_ds", Type: field.TypeInt, Nullable: true},
		{Name: "uid_message", Type: field.TypeInt, Nullable: true},
	}
	// UIDsTable holds the schema information for the "ui_ds" table.
	UIDsTable = &schema.Table{
		Name:       "ui_ds",
		Columns:    UIDsColumns,
		PrimaryKey: []*schema.Column{UIDsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "ui_ds_mailboxes_UIDs",
				Columns:    []*schema.Column{UIDsColumns[5]},
				RefColumns: []*schema.Column{MailboxesColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "ui_ds_messages_message",
				Columns:    []*schema.Column{UIDsColumns[6]},
				RefColumns: []*schema.Column{MessagesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		MailboxesTable,
		MailboxAttrsTable,
		MailboxFlagsTable,
		MailboxPermFlagsTable,
		MessagesTable,
		MessageFlagsTable,
		UIDsTable,
	}
)

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