migrate

package
v0.0.0-...-2fd3d37 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 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
)
View Source
var (
	// AdminColumns holds the columns for the "admin" table.
	AdminColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "username", Type: field.TypeString, Unique: true, Size: 30},
		{Name: "nickname", Type: field.TypeString, Unique: true, Nullable: true, Size: 30},
		{Name: "password", Type: field.TypeString, Size: 100},
		{Name: "gender", Type: field.TypeInt, Nullable: true},
		{Name: "signature", Type: field.TypeString, Size: 50},
	}
	// AdminTable holds the schema information for the "admin" table.
	AdminTable = &schema.Table{
		Name:        "admin",
		Columns:     AdminColumns,
		PrimaryKey:  []*schema.Column{AdminColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// AdminLoginLogColumns holds the columns for the "admin_login_log" table.
	AdminLoginLogColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "admin_id", Type: field.TypeInt},
		{Name: "ip", Type: field.TypeString, Nullable: true, Size: 128},
		{Name: "user_agent", Type: field.TypeString, Nullable: true, Size: 2147483647},
		{Name: "admin_login_logs", Type: field.TypeInt, Nullable: true},
	}
	// AdminLoginLogTable holds the schema information for the "admin_login_log" table.
	AdminLoginLogTable = &schema.Table{
		Name:       "admin_login_log",
		Columns:    AdminLoginLogColumns,
		PrimaryKey: []*schema.Column{AdminLoginLogColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "admin_login_log_admin_loginLogs",
				Columns: []*schema.Column{AdminLoginLogColumns[5]},

				RefColumns: []*schema.Column{AdminColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// CasbinRuleColumns holds the columns for the "casbin_rule" table.
	CasbinRuleColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "p_type", Type: field.TypeString, Size: 50},
		{Name: "v0", Type: field.TypeString, Size: 50},
		{Name: "v1", Type: field.TypeString, Size: 50},
		{Name: "v2", Type: field.TypeString, Size: 50},
		{Name: "v3", Type: field.TypeString, Size: 50},
		{Name: "v4", Type: field.TypeString, Size: 50},
		{Name: "v5", Type: field.TypeString, Size: 50},
	}
	// CasbinRuleTable holds the schema information for the "casbin_rule" table.
	CasbinRuleTable = &schema.Table{
		Name:        "casbin_rule",
		Columns:     CasbinRuleColumns,
		PrimaryKey:  []*schema.Column{CasbinRuleColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// MemberColumns holds the columns for the "member" table.
	MemberColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "gid", Type: field.TypeUUID, Unique: true},
		{Name: "email", Type: field.TypeString, Unique: true, Size: 40},
		{Name: "nickname", Type: field.TypeString, Unique: true, Size: 30},
		{Name: "password", Type: field.TypeString, Size: 100},
		{Name: "gender", Type: field.TypeInt, Nullable: true},
		{Name: "signature", Type: field.TypeString, Size: 50},
	}
	// MemberTable holds the schema information for the "member" table.
	MemberTable = &schema.Table{
		Name:        "member",
		Columns:     MemberColumns,
		PrimaryKey:  []*schema.Column{MemberColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// MemberLoginLogColumns holds the columns for the "member_login_log" table.
	MemberLoginLogColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "member_gid", Type: field.TypeUUID},
		{Name: "ip", Type: field.TypeString, Nullable: true, Size: 128},
		{Name: "user_agent", Type: field.TypeString, Nullable: true, Size: 2147483647},
		{Name: "member_login_logs", Type: field.TypeInt, Nullable: true},
	}
	// MemberLoginLogTable holds the schema information for the "member_login_log" table.
	MemberLoginLogTable = &schema.Table{
		Name:       "member_login_log",
		Columns:    MemberLoginLogColumns,
		PrimaryKey: []*schema.Column{MemberLoginLogColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "member_login_log_member_loginLogs",
				Columns: []*schema.Column{MemberLoginLogColumns[5]},

				RefColumns: []*schema.Column{MemberColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// NoteArticlesColumns holds the columns for the "note_articles" table.
	NoteArticlesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "gid", Type: field.TypeUUID, Unique: true},
		{Name: "member_gid", Type: field.TypeUUID},
		{Name: "mime", Type: field.TypeEnum, Enums: []string{"text/html", "text/markdown"}},
		{Name: "content", Type: field.TypeString, Size: 2147483647},
		{Name: "member_note_articles", Type: field.TypeInt, Nullable: true},
	}
	// NoteArticlesTable holds the schema information for the "note_articles" table.
	NoteArticlesTable = &schema.Table{
		Name:       "note_articles",
		Columns:    NoteArticlesColumns,
		PrimaryKey: []*schema.Column{NoteArticlesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "note_articles_member_noteArticles",
				Columns: []*schema.Column{NoteArticlesColumns[7]},

				RefColumns: []*schema.Column{MemberColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// NoteFilesystemColumns holds the columns for the "note_filesystem" table.
	NoteFilesystemColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "member_gid", Type: field.TypeUUID},
		{Name: "parent_id", Type: field.TypeInt},
		{Name: "name", Type: field.TypeString, Size: 30},
		{Name: "is_dir", Type: field.TypeBool},
		{Name: "deleted", Type: field.TypeBool},
		{Name: "member_note_filesystem", Type: field.TypeInt, Nullable: true},
	}
	// NoteFilesystemTable holds the schema information for the "note_filesystem" table.
	NoteFilesystemTable = &schema.Table{
		Name:       "note_filesystem",
		Columns:    NoteFilesystemColumns,
		PrimaryKey: []*schema.Column{NoteFilesystemColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "note_filesystem_member_noteFilesystem",
				Columns: []*schema.Column{NoteFilesystemColumns[8]},

				RefColumns: []*schema.Column{MemberColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// OptionsColumns holds the columns for the "options" table.
	OptionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "key", Type: field.TypeString, Unique: true, Size: 30},
		{Name: "value", Type: field.TypeString, Size: 500},
	}
	// OptionsTable holds the schema information for the "options" table.
	OptionsTable = &schema.Table{
		Name:        "options",
		Columns:     OptionsColumns,
		PrimaryKey:  []*schema.Column{OptionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AdminTable,
		AdminLoginLogTable,
		CasbinRuleTable,
		MemberTable,
		MemberLoginLogTable,
		NoteArticlesTable,
		NoteFilesystemTable,
		OptionsTable,
	}
)

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