migrate

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 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
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// AllMethodsServicesColumns holds the columns for the "all_methods_services" table.
	AllMethodsServicesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// AllMethodsServicesTable holds the schema information for the "all_methods_services" table.
	AllMethodsServicesTable = &schema.Table{
		Name:       "all_methods_services",
		Columns:    AllMethodsServicesColumns,
		PrimaryKey: []*schema.Column{AllMethodsServicesColumns[0]},
	}
	// BlogPostsColumns holds the columns for the "blog_posts" table.
	BlogPostsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "title", Type: field.TypeString},
		{Name: "body", Type: field.TypeString},
		{Name: "external_id", Type: field.TypeInt, Unique: true},
		{Name: "blog_post_author", Type: field.TypeInt, Nullable: true},
	}
	// BlogPostsTable holds the schema information for the "blog_posts" table.
	BlogPostsTable = &schema.Table{
		Name:       "blog_posts",
		Columns:    BlogPostsColumns,
		PrimaryKey: []*schema.Column{BlogPostsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "blog_posts_users_author",
				Columns:    []*schema.Column{BlogPostsColumns[4]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// CategoriesColumns holds the columns for the "categories" table.
	CategoriesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString},
	}
	// CategoriesTable holds the schema information for the "categories" table.
	CategoriesTable = &schema.Table{
		Name:       "categories",
		Columns:    CategoriesColumns,
		PrimaryKey: []*schema.Column{CategoriesColumns[0]},
	}
	// DependsOnSkippedsColumns holds the columns for the "depends_on_skippeds" table.
	DependsOnSkippedsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "name", Type: field.TypeString},
	}
	// DependsOnSkippedsTable holds the schema information for the "depends_on_skippeds" table.
	DependsOnSkippedsTable = &schema.Table{
		Name:       "depends_on_skippeds",
		Columns:    DependsOnSkippedsColumns,
		PrimaryKey: []*schema.Column{DependsOnSkippedsColumns[0]},
	}
	// DuplicateNumberMessagesColumns holds the columns for the "duplicate_number_messages" table.
	DuplicateNumberMessagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "hello", Type: field.TypeString},
		{Name: "world", Type: field.TypeString},
	}
	// DuplicateNumberMessagesTable holds the schema information for the "duplicate_number_messages" table.
	DuplicateNumberMessagesTable = &schema.Table{
		Name:       "duplicate_number_messages",
		Columns:    DuplicateNumberMessagesColumns,
		PrimaryKey: []*schema.Column{DuplicateNumberMessagesColumns[0]},
	}
	// ExplicitSkippedMessagesColumns holds the columns for the "explicit_skipped_messages" table.
	ExplicitSkippedMessagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// ExplicitSkippedMessagesTable holds the schema information for the "explicit_skipped_messages" table.
	ExplicitSkippedMessagesTable = &schema.Table{
		Name:       "explicit_skipped_messages",
		Columns:    ExplicitSkippedMessagesColumns,
		PrimaryKey: []*schema.Column{ExplicitSkippedMessagesColumns[0]},
	}
	// ImagesColumns holds the columns for the "images" table.
	ImagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "url_path", Type: field.TypeString},
	}
	// ImagesTable holds the schema information for the "images" table.
	ImagesTable = &schema.Table{
		Name:       "images",
		Columns:    ImagesColumns,
		PrimaryKey: []*schema.Column{ImagesColumns[0]},
	}
	// ImplicitSkippedMessagesColumns holds the columns for the "implicit_skipped_messages" table.
	ImplicitSkippedMessagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "depends_on_skipped_skipped", Type: field.TypeInt, Nullable: true},
	}
	// ImplicitSkippedMessagesTable holds the schema information for the "implicit_skipped_messages" table.
	ImplicitSkippedMessagesTable = &schema.Table{
		Name:       "implicit_skipped_messages",
		Columns:    ImplicitSkippedMessagesColumns,
		PrimaryKey: []*schema.Column{ImplicitSkippedMessagesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "implicit_skipped_messages_depends_on_skippeds_skipped",
				Columns:    []*schema.Column{ImplicitSkippedMessagesColumns[1]},
				RefColumns: []*schema.Column{DependsOnSkippedsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// InvalidFieldMessagesColumns holds the columns for the "invalid_field_messages" table.
	InvalidFieldMessagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "json", Type: field.TypeJSON},
	}
	// InvalidFieldMessagesTable holds the schema information for the "invalid_field_messages" table.
	InvalidFieldMessagesTable = &schema.Table{
		Name:       "invalid_field_messages",
		Columns:    InvalidFieldMessagesColumns,
		PrimaryKey: []*schema.Column{InvalidFieldMessagesColumns[0]},
	}
	// MessageWithEnumsColumns holds the columns for the "message_with_enums" table.
	MessageWithEnumsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "enum_type", Type: field.TypeEnum, Enums: []string{"pending", "active", "suspended", "deleted"}, Default: "pending"},
		{Name: "enum_without_default", Type: field.TypeEnum, Enums: []string{"first", "second"}},
	}
	// MessageWithEnumsTable holds the schema information for the "message_with_enums" table.
	MessageWithEnumsTable = &schema.Table{
		Name:       "message_with_enums",
		Columns:    MessageWithEnumsColumns,
		PrimaryKey: []*schema.Column{MessageWithEnumsColumns[0]},
	}
	// MessageWithFieldOnesColumns holds the columns for the "message_with_field_ones" table.
	MessageWithFieldOnesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "field_one", Type: field.TypeInt32},
	}
	// MessageWithFieldOnesTable holds the schema information for the "message_with_field_ones" table.
	MessageWithFieldOnesTable = &schema.Table{
		Name:       "message_with_field_ones",
		Columns:    MessageWithFieldOnesColumns,
		PrimaryKey: []*schema.Column{MessageWithFieldOnesColumns[0]},
	}
	// MessageWithIdsColumns holds the columns for the "message_with_ids" table.
	MessageWithIdsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt32, Increment: true},
	}
	// MessageWithIdsTable holds the schema information for the "message_with_ids" table.
	MessageWithIdsTable = &schema.Table{
		Name:       "message_with_ids",
		Columns:    MessageWithIdsColumns,
		PrimaryKey: []*schema.Column{MessageWithIdsColumns[0]},
	}
	// MessageWithOptionalsColumns holds the columns for the "message_with_optionals" table.
	MessageWithOptionalsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "str_optional", Type: field.TypeString, Nullable: true},
		{Name: "int_optional", Type: field.TypeInt8, Nullable: true},
		{Name: "uint_optional", Type: field.TypeUint8, Nullable: true},
		{Name: "float_optional", Type: field.TypeFloat32, Nullable: true},
		{Name: "bool_optional", Type: field.TypeBool, Nullable: true},
		{Name: "bytes_optional", Type: field.TypeBytes, Nullable: true},
		{Name: "uuid_optional", Type: field.TypeUUID, Nullable: true},
		{Name: "time_optional", Type: field.TypeTime, Nullable: true},
	}
	// MessageWithOptionalsTable holds the schema information for the "message_with_optionals" table.
	MessageWithOptionalsTable = &schema.Table{
		Name:       "message_with_optionals",
		Columns:    MessageWithOptionalsColumns,
		PrimaryKey: []*schema.Column{MessageWithOptionalsColumns[0]},
	}
	// MessageWithPackageNamesColumns holds the columns for the "message_with_package_names" table.
	MessageWithPackageNamesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "name", Type: field.TypeString},
	}
	// MessageWithPackageNamesTable holds the schema information for the "message_with_package_names" table.
	MessageWithPackageNamesTable = &schema.Table{
		Name:       "message_with_package_names",
		Columns:    MessageWithPackageNamesColumns,
		PrimaryKey: []*schema.Column{MessageWithPackageNamesColumns[0]},
	}
	// OneMethodServicesColumns holds the columns for the "one_method_services" table.
	OneMethodServicesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// OneMethodServicesTable holds the schema information for the "one_method_services" table.
	OneMethodServicesTable = &schema.Table{
		Name:       "one_method_services",
		Columns:    OneMethodServicesColumns,
		PrimaryKey: []*schema.Column{OneMethodServicesColumns[0]},
	}
	// PortalsColumns holds the columns for the "portals" table.
	PortalsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString},
		{Name: "portal_category", Type: field.TypeInt, Nullable: true},
	}
	// PortalsTable holds the schema information for the "portals" table.
	PortalsTable = &schema.Table{
		Name:       "portals",
		Columns:    PortalsColumns,
		PrimaryKey: []*schema.Column{PortalsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "portals_categories_category",
				Columns:    []*schema.Column{PortalsColumns[3]},
				RefColumns: []*schema.Column{CategoriesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// SkipEdgeExamplesColumns holds the columns for the "skip_edge_examples" table.
	SkipEdgeExamplesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "user_skip_edge", Type: field.TypeInt, Unique: true, Nullable: true},
	}
	// SkipEdgeExamplesTable holds the schema information for the "skip_edge_examples" table.
	SkipEdgeExamplesTable = &schema.Table{
		Name:       "skip_edge_examples",
		Columns:    SkipEdgeExamplesColumns,
		PrimaryKey: []*schema.Column{SkipEdgeExamplesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "skip_edge_examples_users_skip_edge",
				Columns:    []*schema.Column{SkipEdgeExamplesColumns[1]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// TwoMethodServicesColumns holds the columns for the "two_method_services" table.
	TwoMethodServicesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// TwoMethodServicesTable holds the schema information for the "two_method_services" table.
	TwoMethodServicesTable = &schema.Table{
		Name:       "two_method_services",
		Columns:    TwoMethodServicesColumns,
		PrimaryKey: []*schema.Column{TwoMethodServicesColumns[0]},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "user_name", Type: field.TypeString},
		{Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "active"}},
		{Name: "unnecessary", Type: field.TypeString, Nullable: true},
		{Name: "user_profile_pic", Type: field.TypeUUID, 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_images_profile_pic",
				Columns:    []*schema.Column{UsersColumns[4]},
				RefColumns: []*schema.Column{ImagesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ValidMessagesColumns holds the columns for the "valid_messages" table.
	ValidMessagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "name", Type: field.TypeString},
		{Name: "ts", Type: field.TypeTime},
		{Name: "uuid", Type: field.TypeUUID},
		{Name: "u8", Type: field.TypeUint8},
		{Name: "opti8", Type: field.TypeInt8, Nullable: true},
	}
	// ValidMessagesTable holds the schema information for the "valid_messages" table.
	ValidMessagesTable = &schema.Table{
		Name:       "valid_messages",
		Columns:    ValidMessagesColumns,
		PrimaryKey: []*schema.Column{ValidMessagesColumns[0]},
	}
	// CategoryBlogPostsColumns holds the columns for the "category_blog_posts" table.
	CategoryBlogPostsColumns = []*schema.Column{
		{Name: "category_id", Type: field.TypeInt},
		{Name: "blog_post_id", Type: field.TypeInt},
	}
	// CategoryBlogPostsTable holds the schema information for the "category_blog_posts" table.
	CategoryBlogPostsTable = &schema.Table{
		Name:       "category_blog_posts",
		Columns:    CategoryBlogPostsColumns,
		PrimaryKey: []*schema.Column{CategoryBlogPostsColumns[0], CategoryBlogPostsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "category_blog_posts_category_id",
				Columns:    []*schema.Column{CategoryBlogPostsColumns[0]},
				RefColumns: []*schema.Column{CategoriesColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "category_blog_posts_blog_post_id",
				Columns:    []*schema.Column{CategoryBlogPostsColumns[1]},
				RefColumns: []*schema.Column{BlogPostsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AllMethodsServicesTable,
		BlogPostsTable,
		CategoriesTable,
		DependsOnSkippedsTable,
		DuplicateNumberMessagesTable,
		ExplicitSkippedMessagesTable,
		ImagesTable,
		ImplicitSkippedMessagesTable,
		InvalidFieldMessagesTable,
		MessageWithEnumsTable,
		MessageWithFieldOnesTable,
		MessageWithIdsTable,
		MessageWithOptionalsTable,
		MessageWithPackageNamesTable,
		OneMethodServicesTable,
		PortalsTable,
		SkipEdgeExamplesTable,
		TwoMethodServicesTable,
		UsersTable,
		ValidMessagesTable,
		CategoryBlogPostsTable,
	}
)

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