migrate

package
v0.0.0-...-0fbf3a3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 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 (
	// ApplicationsColumns holds the columns for the "applications" table.
	ApplicationsColumns = []*schema.Column{
		{Name: "application_id", Type: field.TypeUUID},
		{Name: "basic_id", Type: field.TypeString, Unique: true, Size: 10},
		{Name: "premium_id", Type: field.TypeString, Unique: true, Size: 32},
		{Name: "bot_display_name", Type: field.TypeString, Size: 32},
		{Name: "bot_mid", Type: field.TypeString, Unique: true, Size: 64},
		{Name: "bot_active_status", Type: field.TypeEnum, Enums: []string{"active", "suspend", "delete"}},
		{Name: "bot_suspend_reason", Type: field.TypeEnum, Enums: []string{"user_resign", "force_resign", "penalty", "unpaid"}},
		{Name: "applicant_name", Type: field.TypeString, Size: 16},
		{Name: "applicant_biz_id", Type: field.TypeString, Size: 64},
		{Name: "applicant_mid", Type: field.TypeString, Size: 64},
		{Name: "applicant_email", Type: field.TypeString, Size: 64},
		{Name: "remark", Type: field.TypeString, Size: 64},
		{Name: "store_type", Type: field.TypeEnum, Enums: []string{"online_store", "physical_store"}},
		{Name: "website_url", Type: field.TypeString, Size: 2147483647},
		{Name: "application_status", Type: field.TypeEnum, Enums: []string{"wip", "reviewing", "verified", "rejected", "waiting", "replied", "revoked", "canceling"}},
		{Name: "review_comment", Type: field.TypeString, Size: 2147483647},
		{Name: "assigner", Type: field.TypeString, Size: 32},
		{Name: "assignee", Type: field.TypeString, Size: 32},
		{Name: "created_dtime", Type: field.TypeTime},
		{Name: "updated_dtime", Type: field.TypeTime},
	}
	// ApplicationsTable holds the schema information for the "applications" table.
	ApplicationsTable = &schema.Table{
		Name:       "applications",
		Columns:    ApplicationsColumns,
		PrimaryKey: []*schema.Column{ApplicationsColumns[0]},
	}
	// ApplicationAssignmentHistoriesColumns holds the columns for the "application_assignment_histories" table.
	ApplicationAssignmentHistoriesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "assigner", Type: field.TypeString, Size: 32},
		{Name: "assignee", Type: field.TypeString, Size: 32},
		{Name: "created_time", Type: field.TypeTime},
		{Name: "application_id", Type: field.TypeUUID, Nullable: true},
	}
	// ApplicationAssignmentHistoriesTable holds the schema information for the "application_assignment_histories" table.
	ApplicationAssignmentHistoriesTable = &schema.Table{
		Name:       "application_assignment_histories",
		Columns:    ApplicationAssignmentHistoriesColumns,
		PrimaryKey: []*schema.Column{ApplicationAssignmentHistoriesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "application_assignment_histories_applications_assignment_histories",
				Columns:    []*schema.Column{ApplicationAssignmentHistoriesColumns[4]},
				RefColumns: []*schema.Column{ApplicationsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ApplicationStatusHistoriesColumns holds the columns for the "application_status_histories" table.
	ApplicationStatusHistoriesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "status", Type: field.TypeEnum, Enums: []string{"wip", "reviewing", "verified", "rejected", "waiting", "replied", "revoked", "canceling"}},
		{Name: "created_time", Type: field.TypeTime},
		{Name: "application_id", Type: field.TypeUUID, Nullable: true},
	}
	// ApplicationStatusHistoriesTable holds the schema information for the "application_status_histories" table.
	ApplicationStatusHistoriesTable = &schema.Table{
		Name:       "application_status_histories",
		Columns:    ApplicationStatusHistoriesColumns,
		PrimaryKey: []*schema.Column{ApplicationStatusHistoriesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "application_status_histories_applications_status_histories",
				Columns:    []*schema.Column{ApplicationStatusHistoriesColumns[3]},
				RefColumns: []*schema.Column{ApplicationsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// AttachmentsColumns holds the columns for the "attachments" table.
	AttachmentsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "attachment_type", Type: field.TypeEnum, Enums: []string{"biz_cert", "store_appearance", "id_document", "other", "supplement", "reference"}},
		{Name: "obs_oid", Type: field.TypeString, Size: 32},
		{Name: "obs_hash", Type: field.TypeString, Size: 128},
		{Name: "created_dtime", Type: field.TypeTime},
		{Name: "application_id", Type: field.TypeUUID, Nullable: true},
		{Name: "ticket_id", Type: field.TypeInt, Nullable: true},
	}
	// AttachmentsTable holds the schema information for the "attachments" table.
	AttachmentsTable = &schema.Table{
		Name:       "attachments",
		Columns:    AttachmentsColumns,
		PrimaryKey: []*schema.Column{AttachmentsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "attachments_applications_attachments",
				Columns:    []*schema.Column{AttachmentsColumns[5]},
				RefColumns: []*schema.Column{ApplicationsColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "attachments_tickets_attachments",
				Columns:    []*schema.Column{AttachmentsColumns[6]},
				RefColumns: []*schema.Column{TicketsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ReviewersColumns holds the columns for the "reviewers" table.
	ReviewersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "reviewer_id", Type: field.TypeString, Unique: true, Size: 10},
		{Name: "reviewer_name", Type: field.TypeString, Size: 32},
		{Name: "iims_role", Type: field.TypeEnum, Enums: []string{"oav_admin", "oav_reviewer"}},
		{Name: "created_dtime", Type: field.TypeTime},
	}
	// ReviewersTable holds the schema information for the "reviewers" table.
	ReviewersTable = &schema.Table{
		Name:       "reviewers",
		Columns:    ReviewersColumns,
		PrimaryKey: []*schema.Column{ReviewersColumns[0]},
	}
	// TicketsColumns holds the columns for the "tickets" table.
	TicketsColumns = []*schema.Column{
		{Name: "ticket_id", Type: field.TypeInt, Increment: true},
		{Name: "status", Type: field.TypeEnum, Enums: []string{"created", "replied", "completed"}},
		{Name: "creator", Type: field.TypeString, Size: 32},
		{Name: "content", Type: field.TypeString, Size: 2147483647},
		{Name: "reply", Type: field.TypeString, Size: 2147483647},
		{Name: "replier", Type: field.TypeString, Size: 32},
		{Name: "reviewer", Type: field.TypeString, Size: 32},
		{Name: "review_remark", Type: field.TypeString, Size: 2147483647},
		{Name: "replied_dtime", Type: field.TypeTime},
		{Name: "reviewed_dtime", Type: field.TypeTime},
		{Name: "created_dtime", Type: field.TypeTime},
		{Name: "updated_dtime", Type: field.TypeTime},
		{Name: "application_id", Type: field.TypeUUID, Nullable: true},
	}
	// TicketsTable holds the schema information for the "tickets" table.
	TicketsTable = &schema.Table{
		Name:       "tickets",
		Columns:    TicketsColumns,
		PrimaryKey: []*schema.Column{TicketsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "tickets_applications_tickets",
				Columns:    []*schema.Column{TicketsColumns[12]},
				RefColumns: []*schema.Column{ApplicationsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		ApplicationsTable,
		ApplicationAssignmentHistoriesTable,
		ApplicationStatusHistoriesTable,
		AttachmentsTable,
		ReviewersTable,
		TicketsTable,
	}
)

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