migrate

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 7 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 (
	// ArticleArticleColumns holds the columns for the "article_article" table.
	ArticleArticleColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "title", Type: field.TypeString, Nullable: true},
		{Name: "images", Type: field.TypeJSON, Nullable: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "author_id", Type: field.TypeString, Nullable: true},
	}
	// ArticleArticleTable holds the schema information for the "article_article" table.
	ArticleArticleTable = &schema.Table{
		Name:       "article_article",
		Columns:    ArticleArticleColumns,
		PrimaryKey: []*schema.Column{ArticleArticleColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "article_article_user_khumuuser_articles",
				Columns:    []*schema.Column{ArticleArticleColumns[4]},
				RefColumns: []*schema.Column{UserKhumuuserColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// BoardsColumns holds the columns for the "boards" table.
	BoardsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// BoardsTable holds the schema information for the "boards" table.
	BoardsTable = &schema.Table{
		Name:        "boards",
		Columns:     BoardsColumns,
		PrimaryKey:  []*schema.Column{BoardsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// CommentCommentColumns holds the columns for the "comment_comment" table.
	CommentCommentColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "state", Type: field.TypeString, Default: "exists"},
		{Name: "content", Type: field.TypeString},
		{Name: "kind", Type: field.TypeString, Default: "anonymous"},
		{Name: "is_written_by_article_author", Type: field.TypeBool, Default: false},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "article_id", Type: field.TypeInt, Nullable: true},
		{Name: "parent_id", Type: field.TypeInt, Nullable: true},
		{Name: "author_id", Type: field.TypeString, Nullable: true},
		{Name: "study_article_id", Type: field.TypeInt, Nullable: true},
	}
	// CommentCommentTable holds the schema information for the "comment_comment" table.
	CommentCommentTable = &schema.Table{
		Name:       "comment_comment",
		Columns:    CommentCommentColumns,
		PrimaryKey: []*schema.Column{CommentCommentColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "comment_comment_article_article_comments",
				Columns:    []*schema.Column{CommentCommentColumns[6]},
				RefColumns: []*schema.Column{ArticleArticleColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "comment_comment_comment_comment_children",
				Columns:    []*schema.Column{CommentCommentColumns[7]},
				RefColumns: []*schema.Column{CommentCommentColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "comment_comment_user_khumuuser_comments",
				Columns:    []*schema.Column{CommentCommentColumns[8]},
				RefColumns: []*schema.Column{UserKhumuuserColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "comment_comment_article_studyarticle_comments",
				Columns:    []*schema.Column{CommentCommentColumns[9]},
				RefColumns: []*schema.Column{ArticleStudyarticleColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// UserKhumuuserColumns holds the columns for the "user_khumuuser" table.
	UserKhumuuserColumns = []*schema.Column{
		{Name: "username", Type: field.TypeString},
		{Name: "nickname", Type: field.TypeString},
		{Name: "password", Type: field.TypeString},
		{Name: "student_number", Type: field.TypeString, Nullable: true},
		{Name: "state", Type: field.TypeString, Default: "active"},
	}
	// UserKhumuuserTable holds the schema information for the "user_khumuuser" table.
	UserKhumuuserTable = &schema.Table{
		Name:        "user_khumuuser",
		Columns:     UserKhumuuserColumns,
		PrimaryKey:  []*schema.Column{UserKhumuuserColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// CommentLikecommentColumns holds the columns for the "comment_likecomment" table.
	CommentLikecommentColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "comment_id", Type: field.TypeInt, Nullable: true},
		{Name: "user_id", Type: field.TypeString, Nullable: true},
	}
	// CommentLikecommentTable holds the schema information for the "comment_likecomment" table.
	CommentLikecommentTable = &schema.Table{
		Name:       "comment_likecomment",
		Columns:    CommentLikecommentColumns,
		PrimaryKey: []*schema.Column{CommentLikecommentColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "comment_likecomment_comment_comment_like",
				Columns:    []*schema.Column{CommentLikecommentColumns[1]},
				RefColumns: []*schema.Column{CommentCommentColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "comment_likecomment_user_khumuuser_like",
				Columns:    []*schema.Column{CommentLikecommentColumns[2]},
				RefColumns: []*schema.Column{UserKhumuuserColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ArticleStudyarticleColumns holds the columns for the "article_studyarticle" table.
	ArticleStudyarticleColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "author_id", Type: field.TypeString, Nullable: true},
	}
	// ArticleStudyarticleTable holds the schema information for the "article_studyarticle" table.
	ArticleStudyarticleTable = &schema.Table{
		Name:       "article_studyarticle",
		Columns:    ArticleStudyarticleColumns,
		PrimaryKey: []*schema.Column{ArticleStudyarticleColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "article_studyarticle_user_khumuuser_studyArticles",
				Columns:    []*schema.Column{ArticleStudyarticleColumns[1]},
				RefColumns: []*schema.Column{UserKhumuuserColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		ArticleArticleTable,
		BoardsTable,
		CommentCommentTable,
		UserKhumuuserTable,
		CommentLikecommentTable,
		ArticleStudyarticleTable,
	}
)

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