migrate

package
v0.0.0-...-52a3571 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 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 (
	// AnnouncementsColumns holds the columns for the "announcements" table.
	AnnouncementsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "title", Type: field.TypeString},
		{Name: "content", Type: field.TypeString},
		{Name: "created_time", Type: field.TypeTime},
		{Name: "modified_time", Type: field.TypeTime},
		{Name: "announcement_team", Type: field.TypeInt64, Nullable: true},
	}
	// AnnouncementsTable holds the schema information for the "announcements" table.
	AnnouncementsTable = &schema.Table{
		Name:       "announcements",
		Columns:    AnnouncementsColumns,
		PrimaryKey: []*schema.Column{AnnouncementsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "announcements_teams_team",
				Columns:    []*schema.Column{AnnouncementsColumns[5]},
				RefColumns: []*schema.Column{TeamsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// JudgeRecordsColumns holds the columns for the "judge_records" table.
	JudgeRecordsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "judge_time", Type: field.TypeTime},
		{Name: "finished_time", Type: field.TypeTime},
		{Name: "time_cost", Type: field.TypeInt64},
		{Name: "memory_cost", Type: field.TypeInt64},
		{Name: "status", Type: field.TypeInt64, Default: 0},
	}
	// JudgeRecordsTable holds the schema information for the "judge_records" table.
	JudgeRecordsTable = &schema.Table{
		Name:       "judge_records",
		Columns:    JudgeRecordsColumns,
		PrimaryKey: []*schema.Column{JudgeRecordsColumns[0]},
	}
	// ProblemsColumns holds the columns for the "problems" table.
	ProblemsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "title", Type: field.TypeString},
		{Name: "content", Type: field.TypeString},
		{Name: "created_time", Type: field.TypeTime},
		{Name: "user_created_problems", Type: field.TypeInt64, Nullable: true},
	}
	// ProblemsTable holds the schema information for the "problems" table.
	ProblemsTable = &schema.Table{
		Name:       "problems",
		Columns:    ProblemsColumns,
		PrimaryKey: []*schema.Column{ProblemsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "problems_users_created_problems",
				Columns:    []*schema.Column{ProblemsColumns[4]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// TagsColumns holds the columns for the "tags" table.
	TagsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "created_time", Type: field.TypeTime},
	}
	// TagsTable holds the schema information for the "tags" table.
	TagsTable = &schema.Table{
		Name:       "tags",
		Columns:    TagsColumns,
		PrimaryKey: []*schema.Column{TagsColumns[0]},
	}
	// TeamsColumns holds the columns for the "teams" table.
	TeamsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "description", Type: field.TypeString},
		{Name: "created_time", Type: field.TypeTime},
		{Name: "private", Type: field.TypeBool, Default: false},
		{Name: "team_creator", Type: field.TypeInt64, Nullable: true},
	}
	// TeamsTable holds the schema information for the "teams" table.
	TeamsTable = &schema.Table{
		Name:       "teams",
		Columns:    TeamsColumns,
		PrimaryKey: []*schema.Column{TeamsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "teams_users_creator",
				Columns:    []*schema.Column{TeamsColumns[5]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// TodosColumns holds the columns for the "todos" table.
	TodosColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "text", Type: field.TypeString},
		{Name: "done", Type: field.TypeBool, Default: false},
	}
	// TodosTable holds the schema information for the "todos" table.
	TodosTable = &schema.Table{
		Name:       "todos",
		Columns:    TodosColumns,
		PrimaryKey: []*schema.Column{TodosColumns[0]},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "nickname", Type: field.TypeString},
		{Name: "email", Type: field.TypeString},
		{Name: "password", Type: field.TypeString},
		{Name: "avatar", Type: field.TypeString, Default: "test"},
		{Name: "created_time", Type: field.TypeTime},
		{Name: "announcement_author", Type: field.TypeInt64, Unique: true, Nullable: true},
		{Name: "judge_record_user", Type: field.TypeInt64, Nullable: true},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "users_announcements_author",
				Columns:    []*schema.Column{UsersColumns[6]},
				RefColumns: []*schema.Column{AnnouncementsColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "users_judge_records_user",
				Columns:    []*schema.Column{UsersColumns[7]},
				RefColumns: []*schema.Column{JudgeRecordsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ProblemTagsColumns holds the columns for the "problem_tags" table.
	ProblemTagsColumns = []*schema.Column{
		{Name: "problem_id", Type: field.TypeInt64},
		{Name: "tag_id", Type: field.TypeInt64},
	}
	// ProblemTagsTable holds the schema information for the "problem_tags" table.
	ProblemTagsTable = &schema.Table{
		Name:       "problem_tags",
		Columns:    ProblemTagsColumns,
		PrimaryKey: []*schema.Column{ProblemTagsColumns[0], ProblemTagsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "problem_tags_problem_id",
				Columns:    []*schema.Column{ProblemTagsColumns[0]},
				RefColumns: []*schema.Column{ProblemsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "problem_tags_tag_id",
				Columns:    []*schema.Column{ProblemTagsColumns[1]},
				RefColumns: []*schema.Column{TagsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// TeamMembersColumns holds the columns for the "team_members" table.
	TeamMembersColumns = []*schema.Column{
		{Name: "team_id", Type: field.TypeInt64},
		{Name: "user_id", Type: field.TypeInt64},
	}
	// TeamMembersTable holds the schema information for the "team_members" table.
	TeamMembersTable = &schema.Table{
		Name:       "team_members",
		Columns:    TeamMembersColumns,
		PrimaryKey: []*schema.Column{TeamMembersColumns[0], TeamMembersColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "team_members_team_id",
				Columns:    []*schema.Column{TeamMembersColumns[0]},
				RefColumns: []*schema.Column{TeamsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "team_members_user_id",
				Columns:    []*schema.Column{TeamMembersColumns[1]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// TeamAdminsColumns holds the columns for the "team_admins" table.
	TeamAdminsColumns = []*schema.Column{
		{Name: "team_id", Type: field.TypeInt64},
		{Name: "user_id", Type: field.TypeInt64},
	}
	// TeamAdminsTable holds the schema information for the "team_admins" table.
	TeamAdminsTable = &schema.Table{
		Name:       "team_admins",
		Columns:    TeamAdminsColumns,
		PrimaryKey: []*schema.Column{TeamAdminsColumns[0], TeamAdminsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "team_admins_team_id",
				Columns:    []*schema.Column{TeamAdminsColumns[0]},
				RefColumns: []*schema.Column{TeamsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "team_admins_user_id",
				Columns:    []*schema.Column{TeamAdminsColumns[1]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// UserSolvedProblemsColumns holds the columns for the "user_solved_problems" table.
	UserSolvedProblemsColumns = []*schema.Column{
		{Name: "user_id", Type: field.TypeInt64},
		{Name: "problem_id", Type: field.TypeInt64},
	}
	// UserSolvedProblemsTable holds the schema information for the "user_solved_problems" table.
	UserSolvedProblemsTable = &schema.Table{
		Name:       "user_solved_problems",
		Columns:    UserSolvedProblemsColumns,
		PrimaryKey: []*schema.Column{UserSolvedProblemsColumns[0], UserSolvedProblemsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "user_solved_problems_user_id",
				Columns:    []*schema.Column{UserSolvedProblemsColumns[0]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "user_solved_problems_problem_id",
				Columns:    []*schema.Column{UserSolvedProblemsColumns[1]},
				RefColumns: []*schema.Column{ProblemsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AnnouncementsTable,
		JudgeRecordsTable,
		ProblemsTable,
		TagsTable,
		TeamsTable,
		TodosTable,
		UsersTable,
		ProblemTagsTable,
		TeamMembersTable,
		TeamAdminsTable,
		UserSolvedProblemsTable,
	}
)

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